2008-07-28 19:58:15 +00:00
|
|
|
|
#region CPL License
|
|
|
|
|
/*
|
|
|
|
|
Nuclex Framework
|
2012-02-29 16:27:43 +00:00
|
|
|
|
Copyright (C) 2002-2012 Nuclex Development Labs
|
2008-07-28 19:58:15 +00:00
|
|
|
|
|
|
|
|
|
This library is free software; you can redistribute it and/or
|
|
|
|
|
modify it under the terms of the IBM Common Public License as
|
|
|
|
|
published by the IBM Corporation; either version 1.0 of the
|
|
|
|
|
License, or (at your option) any later version.
|
|
|
|
|
|
|
|
|
|
This library is distributed in the hope that it will be useful,
|
|
|
|
|
but WITHOUT ANY WARRANTY; without even the implied warranty of
|
|
|
|
|
MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
|
|
|
|
|
IBM Common Public License for more details.
|
|
|
|
|
|
|
|
|
|
You should have received a copy of the IBM Common Public
|
|
|
|
|
License along with this library
|
|
|
|
|
*/
|
|
|
|
|
#endregion
|
|
|
|
|
|
|
|
|
|
using System;
|
|
|
|
|
using System.IO;
|
|
|
|
|
|
|
|
|
|
#if UNITTEST
|
|
|
|
|
|
|
|
|
|
using NUnit.Framework;
|
|
|
|
|
|
|
|
|
|
namespace Nuclex.Support {
|
|
|
|
|
|
|
|
|
|
/// <summary>Unit Test for the string helper class</summary>
|
|
|
|
|
[TestFixture]
|
2012-02-29 16:27:43 +00:00
|
|
|
|
internal class StringHelperTest {
|
2008-07-28 19:58:15 +00:00
|
|
|
|
|
2008-07-30 18:32:35 +00:00
|
|
|
|
/// <summary>
|
|
|
|
|
/// Verifies that the IndexNotOfAny() method works identical to the framework's
|
|
|
|
|
/// implementation of the IndexOfAny() method, only inverted.
|
|
|
|
|
/// </summary>
|
|
|
|
|
[Test]
|
|
|
|
|
public void TestIndexNotOfAny() {
|
|
|
|
|
string positive = "xxxxxOOOOO";
|
|
|
|
|
string negative = "OOOOOxxxxx";
|
|
|
|
|
|
|
|
|
|
Assert.AreEqual(
|
|
|
|
|
positive.IndexOfAny(new char[] { 'O' }),
|
|
|
|
|
StringHelper.IndexNotOfAny(negative, new char[] { 'O' })
|
|
|
|
|
);
|
|
|
|
|
}
|
|
|
|
|
|
2008-11-26 19:15:36 +00:00
|
|
|
|
/// <summary>
|
|
|
|
|
/// Verifies that the IndexNotOfAny() method works identical to the framework's
|
|
|
|
|
/// implementation of the IndexOfAny() method, only inverted, using a start index.
|
|
|
|
|
/// </summary>
|
|
|
|
|
[Test]
|
|
|
|
|
public void TestIndexNotOfAnyWithStartIndex() {
|
|
|
|
|
string positive = "OOOOOxxxxxOOOOO";
|
|
|
|
|
string negative = "xxxxxOOOOOxxxxx";
|
|
|
|
|
|
|
|
|
|
Assert.AreEqual(
|
|
|
|
|
positive.IndexOfAny(new char[] { 'O' }, 5),
|
|
|
|
|
StringHelper.IndexNotOfAny(negative, new char[] { 'O' }, 5)
|
|
|
|
|
);
|
|
|
|
|
}
|
|
|
|
|
|
2008-07-30 18:32:35 +00:00
|
|
|
|
/// <summary>
|
|
|
|
|
/// Verifies that the LastIndexNotOfAny() method works identical to the framework's
|
|
|
|
|
/// implementation of the LastIndexOfAny() method, only inverted.
|
|
|
|
|
/// </summary>
|
|
|
|
|
[Test]
|
|
|
|
|
public void TestLastIndexNotOfAny() {
|
|
|
|
|
string positive = "xxxxxOOOOO";
|
|
|
|
|
string negative = "OOOOOxxxxx";
|
|
|
|
|
|
|
|
|
|
Assert.AreEqual(
|
|
|
|
|
positive.LastIndexOfAny(new char[] { 'x' }),
|
|
|
|
|
StringHelper.LastIndexNotOfAny(negative, new char[] { 'x' })
|
|
|
|
|
);
|
|
|
|
|
}
|
|
|
|
|
|
2008-11-26 19:15:36 +00:00
|
|
|
|
/// <summary>
|
|
|
|
|
/// Verifies that the LastIndexNotOfAny() method works identical to the framework's
|
|
|
|
|
/// implementation of the LastIndexOfAny() method, only inverted, using a start index.
|
|
|
|
|
/// </summary>
|
|
|
|
|
[Test]
|
|
|
|
|
public void TestLastIndexNotOfAnyWithStartIndex() {
|
|
|
|
|
string positive = "OOOOOxxxxxOOOOO";
|
|
|
|
|
string negative = "xxxxxOOOOOxxxxx";
|
|
|
|
|
|
|
|
|
|
Assert.AreEqual(
|
|
|
|
|
positive.LastIndexOfAny(new char[] { 'x' }, 5),
|
|
|
|
|
StringHelper.LastIndexNotOfAny(negative, new char[] { 'x' }, 5)
|
|
|
|
|
);
|
|
|
|
|
}
|
|
|
|
|
|
2008-07-30 18:32:35 +00:00
|
|
|
|
/// <summary>
|
|
|
|
|
/// Verifies that the IndexNotOfAny() method works with multiple characters
|
|
|
|
|
/// </summary>
|
|
|
|
|
[Test]
|
|
|
|
|
public void TestMultipleCharIndexNotOfAny() {
|
2008-11-26 19:15:36 +00:00
|
|
|
|
string positive = "abcde12345";
|
|
|
|
|
string negative = "12345abcde";
|
2008-07-30 18:32:35 +00:00
|
|
|
|
|
|
|
|
|
Assert.AreEqual(
|
2008-11-26 19:15:36 +00:00
|
|
|
|
positive.IndexOfAny(new char[] { '1', '2', '3', '4', '5' }),
|
|
|
|
|
StringHelper.IndexNotOfAny(negative, new char[] { '1', '2', '3', '4', '5' })
|
2008-07-30 18:32:35 +00:00
|
|
|
|
);
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
/// <summary>
|
2008-11-26 19:15:36 +00:00
|
|
|
|
/// Verifies that the IndexNotOfAny() method works with multiple characters,
|
|
|
|
|
/// using a start index
|
|
|
|
|
/// </summary>
|
|
|
|
|
[Test]
|
|
|
|
|
public void TestMultipleCharIndexNotOfAnyWithStartIndex() {
|
|
|
|
|
string positive = "12345abcde12345";
|
|
|
|
|
string negative = "abcde12345abcde";
|
|
|
|
|
|
|
|
|
|
Assert.AreEqual(
|
|
|
|
|
positive.IndexOfAny(new char[] { '1', '2', '3', '4', '5' }, 5),
|
|
|
|
|
StringHelper.IndexNotOfAny(negative, new char[] { '1', '2', '3', '4', '5' }, 5)
|
|
|
|
|
);
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
/// <summary>
|
|
|
|
|
/// Verifies that the LastIndexNotOfAny() method works with multiple characters
|
2008-07-30 18:32:35 +00:00
|
|
|
|
/// </summary>
|
|
|
|
|
[Test]
|
|
|
|
|
public void TestMultipleCharLastIndexNotOfAny() {
|
2008-11-26 19:15:36 +00:00
|
|
|
|
string positive = "abcde12345";
|
|
|
|
|
string negative = "12345abcde";
|
|
|
|
|
|
|
|
|
|
Assert.AreEqual(
|
|
|
|
|
positive.LastIndexOfAny(new char[] { 'a', 'b', 'c', 'd', 'e' }),
|
|
|
|
|
StringHelper.LastIndexNotOfAny(negative, new char[] { 'a', 'b', 'c', 'd', 'e' })
|
|
|
|
|
);
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
/// <summary>
|
|
|
|
|
/// Verifies that the LastIndexNotOfAny() method works with multiple characters,
|
|
|
|
|
/// using a start index
|
|
|
|
|
/// </summary>
|
|
|
|
|
[Test]
|
|
|
|
|
public void TestMultipleCharLastIndexNotOfAnyWithStartIndex() {
|
|
|
|
|
string positive = "12345abcde12345";
|
|
|
|
|
string negative = "abcde12345abcde";
|
|
|
|
|
|
|
|
|
|
Assert.AreEqual(
|
|
|
|
|
positive.LastIndexOfAny(new char[] { 'a', 'b', 'c', 'd', 'e' }, 5),
|
|
|
|
|
StringHelper.LastIndexNotOfAny(negative, new char[] { 'a', 'b', 'c', 'd', 'e' }, 5)
|
|
|
|
|
);
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
/// <summary>
|
|
|
|
|
/// Verifies that the IndexNotOfAny() method fails when only matches are found
|
|
|
|
|
/// </summary>
|
|
|
|
|
[Test]
|
|
|
|
|
public void TestIndexNotOfAnyMatchesOnly() {
|
|
|
|
|
string positive = "1234512345";
|
|
|
|
|
string negative = "abcdeabcde";
|
|
|
|
|
|
|
|
|
|
Assert.AreEqual(
|
|
|
|
|
positive.IndexOfAny(new char[] { 'a', 'b', 'c', 'd', 'e' }),
|
|
|
|
|
StringHelper.IndexNotOfAny(negative, new char[] { 'a', 'b', 'c', 'd', 'e' })
|
|
|
|
|
);
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
/// <summary>
|
|
|
|
|
/// Verifies that the IndexNotOfAny() method fails when only matches are found,
|
|
|
|
|
/// using a start index
|
|
|
|
|
/// </summary>
|
|
|
|
|
[Test]
|
|
|
|
|
public void TestIndexNotOfAnyMatchesOnlyWithStartIndex() {
|
|
|
|
|
string positive = "abcde1234512345";
|
|
|
|
|
string negative = "12345abcdeabcde";
|
2008-07-30 18:32:35 +00:00
|
|
|
|
|
|
|
|
|
Assert.AreEqual(
|
2008-11-26 19:15:36 +00:00
|
|
|
|
positive.IndexOfAny(new char[] { 'a', 'b', 'c', 'd', 'e' }, 5),
|
|
|
|
|
StringHelper.IndexNotOfAny(negative, new char[] { 'a', 'b', 'c', 'd', 'e' }, 5)
|
2008-07-30 18:32:35 +00:00
|
|
|
|
);
|
|
|
|
|
}
|
2008-07-28 19:58:15 +00:00
|
|
|
|
|
2008-11-26 19:15:36 +00:00
|
|
|
|
/// <summary>
|
|
|
|
|
/// Verifies that the LastIndexNotOfAny() method fails when only matches are found
|
|
|
|
|
/// </summary>
|
|
|
|
|
[Test]
|
|
|
|
|
public void TestLastIndexNotOfAnyMatchesOnly() {
|
|
|
|
|
string positive = "1234512345";
|
|
|
|
|
string negative = "abcdeabcde";
|
|
|
|
|
|
|
|
|
|
Assert.AreEqual(
|
|
|
|
|
positive.LastIndexOfAny(new char[] { 'a', 'b', 'c', 'd', 'e' }),
|
|
|
|
|
StringHelper.LastIndexNotOfAny(negative, new char[] { 'a', 'b', 'c', 'd', 'e' })
|
|
|
|
|
);
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
/// <summary>
|
|
|
|
|
/// Verifies that the LastIndexNotOfAny() method fails when only matches are found,
|
|
|
|
|
/// using a start index
|
|
|
|
|
/// </summary>
|
|
|
|
|
[Test]
|
|
|
|
|
public void TestLastIndexNotOfAnyMatchesOnlyWithStartIndex() {
|
|
|
|
|
string positive = "abcde1234512345";
|
|
|
|
|
string negative = "12345abcdeabcde";
|
|
|
|
|
|
|
|
|
|
Assert.AreEqual(
|
|
|
|
|
positive.LastIndexOfAny(new char[] { 'a', 'b', 'c', 'd', 'e' }, 5),
|
|
|
|
|
StringHelper.LastIndexNotOfAny(negative, new char[] { 'a', 'b', 'c', 'd', 'e' }, 5)
|
|
|
|
|
);
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
// TODO: Also need unit tests for the 'length' argument
|
|
|
|
|
// to guarantee the methods stop searching at the exact character
|
|
|
|
|
|
2008-07-28 19:58:15 +00:00
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
} // namespace Nuclex.Support
|
|
|
|
|
|
|
|
|
|
#endif // UNITTEST
|