public void Newlines() { string input = "AB\nCD\r\nEF\n\rGH\rIJ\n\nKL\r\rMN\n\r\nOP\r\n\rQR\n"; string[] patterns = new[] { @"\n", @"\r\n", @"\n\r", @"\r", @"\n\n", @"\r\r", @"\n\r\n", @"\r\n\r", @"\n\n\n", @"\r\r\r", // real newlines "\n", "\r", @" ", @" " }; RegexAssert.AreMatchesSameAsMsoft(input, patterns, AlgorithmType); }
public void CharCodesInClass() { string input = "It cost € 3,200.\nExpensive."; string[] patterns = new[] { @"[\x20]", @"[\x30]", @"[\x0AE]", @"[\x0AF]", @"[\40]", @"[\040]", @"[\60]", @"[\060]", @"[\0600]", // @"\060" + "0" @"[\12]", @"[\012]", @"[€]", @"[\u20ac]", @"[\u0030]" }; RegexAssert.AreMatchesSameAsMsoft(input, patterns, AlgorithmType); }
public void CharCodes() { string input = "It cost € 3,200.\nExpensive."; string[] patterns = new[] { @"\x20", @"\x30", @"\x0AE", @"\x0AF", @"\40", @"\040", @"\60", @"\060", @"\0600", // @"\060" + "0" @"\12", @"\012", @"€", @"\u20ac", @"\u0030" }; RegexAssert.AreMatchesSameAsMsoft(input, patterns, AlgorithmType); }
// TODO: enable this test when captures work properly //[Test] public void PrimeNumbers() { int[] numbers = new[] { 0, 1, 2, 3, 4, 5, 6, 7, 8, 9, 10, 11, 12, 13, 14, 15, 16, 17, 18, 19, 20, 23, 24, 25, 26, 29, 31, 37, 41, 43, 47, 53, 59, 60, 61, 64, 67, 71, 72, 73, }; string pattern = @"^1?$|^(11+?)\1+$"; foreach (int n in numbers) { string input = new string('1', n); Console.WriteLine("Number: {0}", n); Console.WriteLine("Prime: {0}", Msoft.Regex.Matches(input, pattern).Count == 0); RegexAssert.AreMatchesSameAsMsoft(input, pattern, AlgorithmType); //RegexAssert.DisplayMsoftMatches(input, pattern); } }
public void EmptyPattern() { RegexAssert.AreMatchesSameAsMsoft("", "", AlgorithmType); RegexAssert.AreMatchesSameAsMsoft("x", "", AlgorithmType); RegexAssert.AreMatchesSameAsMsoft("xx", "", AlgorithmType); RegexAssert.AreMatchesSameAsMsoft("xyz", "", AlgorithmType); }
public void WordBoundary() { string input = "One thing or another\nAnd then some"; string[] patterns = new[] { @"\b\w+", @"\w+\b", @"\b\w+\b", @"\b.+", @".+\b", @"\b.+\b", @"\b.+?\b", @"\b.*?\b", @"\b[a-z]+", @"[a-z]+\b", @"\b[a-z]+\b", @"\bt\w*", @"\b[Aa]\w*", @"\w*e\b", @"\b[A-Z]\w*", @"\B\w+", @"\w+\B", @"\B\w+\B", @"(\B.)+", }; RegexAssert.AreMatchesSameAsMsoft(input, patterns, AlgorithmType); }
public void QuantifierWithAnchorChild() { string input = "One thing or another"; string[] patterns = new[] { @"^+", @"(^\d*)+", @"(^\w*)+", @"(^\w*?)+", @"^+?", @"(^\d*)+?", @"(^\w*?)+?", @"([A-Z]*)+", @"([A-Z]*)+?", @"(^[A-Z]*)+", @"(^[A-Zm-z]*)+", @"(^[A-Zm-z]?)+", }; RegexAssert.AreMatchesSameAsMsoft(input, patterns, AlgorithmType); }
public void EscapedChars() { string input = @"abc^d ef gh i$ jk \A \z\Z \b\B \G \g \a\n"; string[] patterns = new[] { @"\^", @"\$", @"\\A", @"\\a", @"\\Z", @"\\z", @"\\B", @"\\b", @"\\G", @"\\g", @"\\N", @"\\n", @"\n", @"\\", @"\\\w", @"\\.", @"\\[a-z]", @"\\[A-Z]", }; RegexAssert.AreMatchesSameAsMsoft(input, patterns, AlgorithmType); }
public void StartAndEndOfStringOrLine() { string input = "One thing or another\nAnd then some"; string[] patterns = new[] { @"^\w+", @"\w+$", @"^\w+|\w+$", @"\w+$|^\w+", @"\w*^\w*", @"\w*$\w*", @"\w+$\w*", @"\A\w+", @"\w+\Z", @"\w+\z", @"\A\w+|\w+\Z", }; RegexAssert.AreMatchesSameAsMsoft(input, patterns, AlgorithmType); RegexAssert.AreMatchesSameAsMsoft(input, patterns, AlgorithmType, RegexOptions.Multiline); }
public void NonEscapedSpecialCharsInClass() { string input = @".$^{[(|)*+?\"; string[] patterns = new[] { @"[.]", @"[$]", @"[{]", @"[[]", @"[(]", @"[|]", @"[)]", @"[*]", @"[+]", @"[?]", @"[x^]", @"[\^]", @"[^^]", @"[\\]", @"[$^{[(|)*+?]", @"[.$^{[(|)*+?\\]", }; RegexAssert.AreMatchesSameAsMsoft(input, patterns, AlgorithmType); }
public void FromNToM_ZeroWidth() { string input = "abbcccddddeeeee 122333444455555666666"; string[] patterns = new[] { @"c{0,1000000}", @"1{0,0}", @"1{0,1}", @"1{0}", @"1{0,}", @"d{0,}", @"\d{0,}", @"\w{0,10}", @"\w{0,15}", @"\w{0,16}", @"\w{0,}", @"[0-9a-z ]{0,}", @"[0-9a-z]{0,}" }; RegexAssert.AreMatchesSameAsMsoft(input, patterns, AlgorithmType); }
public void NoParens() { RegexAssert.AreMatchesSameAsMsoft("abc", @"abc|def", AlgorithmType); RegexAssert.AreMatchesSameAsMsoft("def", @"abc|def", AlgorithmType); RegexAssert.AreMatchesSameAsMsoft("abcdef", @"abc|def", AlgorithmType); RegexAssert.AreMatchesSameAsMsoft("abc def", @"abc|def", AlgorithmType); RegexAssert.AreMatchesSameAsMsoft("abcadef", @"abc|def", AlgorithmType); }
public void Nested() { // TODO: create similar tests that need backtracking RegexAssert.AreMatchesSameAsMsoft("abab", @"(aba?)+", AlgorithmType); RegexAssert.AreMatchesSameAsMsoft("abbab", @"(aba?)+", AlgorithmType); RegexAssert.AreMatchesSameAsMsoft("abbab", @"(abb?)+", AlgorithmType); RegexAssert.AreMatchesSameAsMsoft("abbab", @"abb?", AlgorithmType); }
public void RepeatedChar() { RegexAssert.AreMatchesSameAsMsoft("Something or other", "o", AlgorithmType); RegexAssert.AreMatchesSameAsMsoft("Matter", "t", AlgorithmType); RegexAssert.AreMatchesSameAsMsoft("Mississippi", "s", AlgorithmType); RegexAssert.AreMatchesSameAsMsoft("CCCP", "CC", AlgorithmType); RegexAssert.AreMatchesSameAsMsoft("CCCCP", "CC", AlgorithmType); }
public void FalseNestedGroups() { RegexAssert.AreMatchesSameAsMsoft("abcdlas \b 01234 [] xyz", @"[[\s]\d]", AlgorithmType); RegexAssert.AreMatchesSameAsMsoft("abcdlas \b 01234 [7] xyz", @"[[\s]\d]", AlgorithmType); RegexAssert.AreMatchesSameAsMsoft("abcdlas \b 01234 [] xyz", @"[\d[\s]]", AlgorithmType); RegexAssert.AreMatchesSameAsMsoft("abcdlas \b 01234 [7] xyz", @"[\d[\s]]", AlgorithmType); }
public void ContiguousMatch_4() { string input = " One thing or another."; string[] patterns = new[] { @"\G\w+\s*", }; RegexAssert.AreMatchesSameAsMsoft(input, patterns, AlgorithmType); }
public void ContiguousMatch_3() { string input = "This is the first sentence. And this is the second one."; string[] patterns = new[] { @"\G\w+\s*", }; RegexAssert.AreMatchesSameAsMsoft(input, patterns, AlgorithmType); }
public void FromNToM() { string input = "abbcccddddeeeee 122333444455555666666"; string[] patterns = new[] { @"c{1,2}", @"c{1,3}", @"c{2,5}", @"c{3,7}", @"c{4,5}", @"c{3,3}", @"c{1,1000000}", @"e{4,5}", @"e{5,6}", @"e{4,6}", @"e{5,5}", @"1{1,1}", @"1{1,}", @"1{2,}", @"1{1}", @"1{2}", @"d{4}", @"d{3}", @"d{5}", @"d{4,}", @"d{3,}", @"d{1,}", @"e{5}", @"\d{1,}", @"\d{3,}", @"\d{21,}", @"\d{22,}", @"\w{1,10}", @"\w{1,15}", @"\w{1,16}", @"\w{1,}", @"\w{10,}", @"\w{15,}", @"\w{16,}", @"\w{20,}", @"[0-9a-z ]{1,}", @"[0-9a-z ]{22,}", @"[0-9a-z]{1,}" }; RegexAssert.AreMatchesSameAsMsoft(input, patterns, AlgorithmType); }
public void ExponentialTime() { // TODO: run this with ExplicitDFAMatcher (when fully working) const int n = 7; string input = new string('a', n); string pattern = Enumerable.Repeat("a?", n).JoinStrings() + input; RegexAssert.AreMatchesSameAsMsoft(input, pattern, AlgorithmType); }
public void CharSetsAndRanges() { string input = "A thing or another thing"; string[] patterns = new[] { "[aeiou]", "[a-fdmzA-D]" }; RegexAssert.AreMatchesSameAsMsoft(input, patterns, AlgorithmType); }
public void ContiguousMatch_5() { string input = "abc"; string[] patterns = new[] { @"\G\w?", @"\G\w*", }; RegexAssert.AreMatchesSameAsMsoft(input, patterns, AlgorithmType); }
public void FalseStart() { string input = "Something or other"; string[] patterns = new[] { "thingy", "Somme", "Some" }; RegexAssert.AreMatchesSameAsMsoft(input, patterns, AlgorithmType); }
public void CompareToMsoft() { RegexAssert.AreMatchesSameAsMsoft("Something or other", "xyz", AlgorithmType); RegexAssert.AreMatchesSameAsMsoft("Something or other", "thing", AlgorithmType); RegexAssert.AreMatchesSameAsMsoft("A thing or another thing", "thing", AlgorithmType); RegexAssert.AreMatchesSameAsMsoft("Some thinthing or another", "thing", AlgorithmType); RegexAssert.AreMatchesSameAsMsoft("This is alfalfa", "alfa", AlgorithmType); RegexAssert.AreMatchesSameAsMsoft("This is alfalfalfa", "alfa", AlgorithmType); RegexAssert.AreMatchesSameAsMsoft("This is alfalfalf", "alfa", AlgorithmType); }
public void Ranges() { string input = "A thing or another thing"; string[] patterns = new[] { "[a-m]", "[a-ae-ei-io-ou-u]", "[A-Z] [a-z]" }; RegexAssert.AreMatchesSameAsMsoft(input, patterns, AlgorithmType); }
public void DashesInsideClass() { string input = "abc-def mnpqrstu []."; string[] patterns = new[] { @"[A-Za\-z]", @"[a-d-n]", @"[a-d-n-s]", @"[a-d-.]", }; RegexAssert.AreMatchesSameAsMsoft(input, patterns, AlgorithmType); }
public void WithSpaces() { string input = "Something or other"; string[] patterns = new[] { " or ", "g o", "g or o", "thing or other" }; RegexAssert.AreMatchesSameAsMsoft(input, patterns, AlgorithmType); }
public void NegativeRanges() { string input = "A thing or another thing"; string[] patterns = new[] { @"[^A-Z ]", @"[^ a-z]", @"\W", @"\S" }; RegexAssert.AreMatchesSameAsMsoft(input, patterns, AlgorithmType); }
public void Singleline_Newlines() { string input = "AB\nCD\r\nEF\n\rGH\rIJ\n\nKL\r\rMN\n\r\nOP\r\n\rQR\n"; string[] patterns = new[] { @".", @".+", }; RegexAssert.AreMatchesSameAsMsoft(input, patterns, AlgorithmType); RegexAssert.AreMatchesSameAsMsoft(input, patterns, AlgorithmType, RegexOptions.Singleline); }
public void ContiguousMatch_1() { string input = "capybara,squirrel,chipmunk,porcupine,gopher," + "beaver,groundhog,hamster,guinea pig,gerbil," + "chinchilla,prairie dog,mouse,rat"; string[] patterns = new[] { @"\G(\w+\s?\w*),?", @"(\w+\s?\w*),?", }; RegexAssert.AreMatchesSameAsMsoft(input, patterns, AlgorithmType); }
public void Simple() { string input = "A thing or another thing "; string[] patterns = new[] { @"\w+", @"\s+", @"\w\w*", @"\s\w*" }; RegexAssert.AreMatchesSameAsMsoft(input, patterns, AlgorithmType); }