56 lines
1.9 KiB
C#
56 lines
1.9 KiB
C#
using System.Text.RegularExpressions;
|
|
using NUnit.Framework;
|
|
|
|
namespace Sacs.UnitTests.Net.Standard.Base.Generic
|
|
{
|
|
[TestFixture]
|
|
public class Regex_Tester
|
|
{
|
|
// --- Tests ---
|
|
|
|
[Test]
|
|
public void Regex_FolderPaths()
|
|
{
|
|
Assert.That(Regex.IsMatch("abcabcabc\\.metadata\\.plugins\\abcabcabc", ".*?\\\\\\.metadata\\\\\\.plugins\\\\.*?"), Is.EqualTo(true));
|
|
|
|
// Path ends in.
|
|
Assert.That(Regex.IsMatch("D:\\Home\\Data\\Logs\\App", "[\\\\/]app$", RegexOptions.IgnoreCase), Is.EqualTo(true));
|
|
Assert.That(Regex.IsMatch("/home/data/logs/app", "[\\\\/]app$", RegexOptions.IgnoreCase), Is.EqualTo(true));
|
|
|
|
// Path doesn't end in.
|
|
Assert.That(Regex.IsMatch("D:\\Home\\Data\\Logs", "[\\\\/]app$", RegexOptions.IgnoreCase), Is.EqualTo(false));
|
|
Assert.That(Regex.IsMatch("/home/data/logs", "[\\\\/]app$", RegexOptions.IgnoreCase), Is.EqualTo(false));
|
|
}
|
|
|
|
[Test]
|
|
public void Regex_IsMatch()
|
|
{
|
|
string input = "abcdefghi";
|
|
|
|
Assert.That(Regex.IsMatch(input, "a"), Is.EqualTo(true));
|
|
Assert.That(Regex.IsMatch(input, "^a"), Is.EqualTo(true));
|
|
Assert.That(Regex.IsMatch(input, "d"), Is.EqualTo(true));
|
|
Assert.That(Regex.IsMatch(input, "i$"), Is.EqualTo(true));
|
|
|
|
// Combination characters.
|
|
Assert.That(Regex.IsMatch(input, "[adg]"), Is.EqualTo(true));
|
|
Assert.That(Regex.IsMatch(input, "[cba]"), Is.EqualTo(true));
|
|
|
|
// Blank matches input.
|
|
Assert.That(Regex.IsMatch(input, ""), Is.EqualTo(true));
|
|
|
|
// Characters at incorrect position.
|
|
Assert.That(Regex.IsMatch(input, "a$"), Is.EqualTo(false));
|
|
Assert.That(Regex.IsMatch(input, "^d"), Is.EqualTo(false));
|
|
Assert.That(Regex.IsMatch(input, "d$"), Is.EqualTo(false));
|
|
Assert.That(Regex.IsMatch(input, "^i"), Is.EqualTo(false));
|
|
|
|
// Incorrect characters.
|
|
Assert.That(Regex.IsMatch(input, "j"), Is.EqualTo(false));
|
|
Assert.That(Regex.IsMatch(input, " "), Is.EqualTo(false));
|
|
}
|
|
|
|
// --- The End ---
|
|
}
|
|
}
|