59 lines
2.0 KiB
C#
59 lines
2.0 KiB
C#
using System.Text.RegularExpressions;
|
|
using Microsoft.VisualStudio.TestTools.UnitTesting;
|
|
|
|
namespace Sacs.UnitTests.Net.Standard.Base.Generic
|
|
{
|
|
[TestClass]
|
|
public class Regex_Tester
|
|
{
|
|
//-------------------------------------------------------------------
|
|
// Data members.
|
|
|
|
//-------------------------------------------------------------------
|
|
[TestMethod]
|
|
public void Regex_FolderPaths()
|
|
{
|
|
Assert.AreEqual(true, Regex.IsMatch("abcabcabc\\.metadata\\.plugins\\abcabcabc", ".*?\\\\\\.metadata\\\\\\.plugins\\\\.*?"));
|
|
|
|
// Path ends in.
|
|
Assert.AreEqual(true, Regex.IsMatch("D:\\Home\\Data\\Logs\\App", "[\\\\/]app$", RegexOptions.IgnoreCase));
|
|
Assert.AreEqual(true, Regex.IsMatch("/home/data/logs/app", "[\\\\/]app$", RegexOptions.IgnoreCase));
|
|
|
|
// Path doesn't end in.
|
|
Assert.AreEqual(false, Regex.IsMatch("D:\\Home\\Data\\Logs", "[\\\\/]app$", RegexOptions.IgnoreCase));
|
|
Assert.AreEqual(false, Regex.IsMatch("/home/data/logs", "[\\\\/]app$", RegexOptions.IgnoreCase));
|
|
}
|
|
|
|
//-------------------------------------------------------------------
|
|
[TestMethod]
|
|
public void Regex_IsMatch()
|
|
{
|
|
string input = "abcdefghi";
|
|
|
|
Assert.AreEqual(true, Regex.IsMatch(input, "a"));
|
|
Assert.AreEqual(true, Regex.IsMatch(input, "^a"));
|
|
Assert.AreEqual(true, Regex.IsMatch(input, "d"));
|
|
Assert.AreEqual(true, Regex.IsMatch(input, "i$"));
|
|
|
|
// Combination characters.
|
|
Assert.AreEqual(true, Regex.IsMatch(input, "[adg]"));
|
|
Assert.AreEqual(true, Regex.IsMatch(input, "[cba]"));
|
|
|
|
// Blank matches input.
|
|
Assert.AreEqual(true, Regex.IsMatch(input, ""));
|
|
|
|
// Characters at incorrect position.
|
|
Assert.AreEqual(false, Regex.IsMatch(input, "a$"));
|
|
Assert.AreEqual(false, Regex.IsMatch(input, "^d"));
|
|
Assert.AreEqual(false, Regex.IsMatch(input, "d$"));
|
|
Assert.AreEqual(false, Regex.IsMatch(input, "^i"));
|
|
|
|
// Incorrect characters.
|
|
Assert.AreEqual(false, Regex.IsMatch(input, "j"));
|
|
Assert.AreEqual(false, Regex.IsMatch(input, " "));
|
|
}
|
|
|
|
//-------------------------------------------------------------------
|
|
}
|
|
}
|