void Test2() { var map = new List <(string Key, string Value)>(); map.Add(("V", "VA")); map.Add(("V", "VO")); var matcher = new ConfusableMatcher(map, null); var res = matcher.IndexOf("VV", "VAVOVAVO", CMOptions.Default); AssertNoMatch(res); res = matcher.IndexOf("VAVOVAVO", "VV", CMOptions.Default); AssertMatchMulti(res, new[] { 0, 0 }, new[] { 3, 4 }); CMOptions opts = CMOptions.Default; opts.StartIndex = 4; res = matcher.IndexOf("VAVOVAVO", "VV", opts); AssertMatchMulti(res, new[] { 4, 4 }, new[] { 3, 4 }); opts.StartIndex = 2; res = matcher.IndexOf("VAVOVAVO", "VV", opts); AssertMatchMulti(res, new[] { 2, 2 }, new[] { 3, 4 }); opts.StartIndex = 3; res = matcher.IndexOf("VAVOVAVO", "VV", opts); AssertMatchMulti(res, new[] { 4, 4 }, new[] { 3, 4 }); }
void Test10() { var opts = CMOptions.Default; opts.MatchRepeating = true; var map = new List <(string Key, string Value)>(); var matcher = new ConfusableMatcher(map, null); var res = matcher.IndexOf(":)", "", opts); AssertMatch(res, 0, 0); res = matcher.IndexOf("", ":)", opts); AssertNoMatch(res); }
void LidlNormalizerTests(string In, string Contains, int ExpectedIndex, int ExpectedLength) { var map = GetDefaultMap(); // Additional test data var keys = new[] { "A", "A", "A", "A", "B", "U", "U", "O", "O", "A", "A", "A", "C", "D", "E", "F", "G", "H", "I", "J", "K", "L", "M", "N", "O", "P", "Q", "R", "S", "T", "U", "V", "W", "X", "Y", "Z", "A", "B", "C", "D", "E", "F", "G", "H", "I", "J", "K", "L", "M", "N", "O", "P", "Q", "R", "S", "T", "U", "V", "W", "X", "Y", "Z", "0", "A", "B", "C", "D", "E", "F", "G", "H", "I", "J", "K", "L", "M", "N", "O", "P", "Q", "R", "S", "T", "U", "V", "W", "X", "Y", "Z", "A", "B", "C", "D", "E", "F", "G", "H", "I", "J", "K", "L", "M", "N", "O", "P", "Q", "R", "S", "T", "U", "V", "W", "X", "Y", "Z", "A", "B", "C", "D", "E", "F", "G", "H", "I", "J", "K", "L", "M", "N", "O", "P", "Q", "R", "S", "T", "U", "V", "W", "X", "Y", "Z", "A", "B", "C", "D", "E", "F", "G", "H", "I", "J", "K", "L", "M", "N", "O", "P", "Q", "R", "S", "T", "U", "V", "W", "X", "Y", "Z", "A", "B", "C", "D", "E", "F", "G", "H", "I", "J", "K", "L", "M", "N", "O", "P", "Q", "R", "S", "T", "U", "V", "W", "X", "Y", "Z", "U", "A", " ", "S", "M", "O", "L", "N", "A", "T", "I", "O", "N", "N", "I", "G", "N", "I", "FREE", "AE" }; var vals = new[] { "\U00000105", "\U0000ab31", "\U00001d43", "\U000000e5", "\U0000249d", "\U000000fc", "\U000000dc", "\U000000f6", "\U000000d6", "\U000000e4", "\U000000c4", "\U0000249c", "\U0000249e", "\U0000249f", "\U000024a0", "\U000024a1", "\U000024a2", "\U000024a3", "\U000024a4", "\U000024a5", "\U000024a6", "\U000024a7", "\U000024a8", "\U000024a9", "\U000024aa", "\U000024ab", "\U000024ac", "\U000024ad", "\U000024ae", "\U000024af", "\U000024b0", "\U000024b1", "\U000024b2", "\U000024b3", "\U000024b4", "\U000024cf", "\U000024d0", "\U000024d1", "\U000024d2", "\U000024d3", "\U000024d4", "\U000024d5", "\U000024d6", "\U000024d7", "\U000024d8", "\U000024d9", "\U000024da", "\U000024db", "\U000024dc", "\U000024dd", "\U000024de", "\U000024df", "\U000024e0", "\U000024e1", "\U000024e2", "\U000024e3", "\U000024e4", "\U000024e5", "\U000024e6", "\U000024e7", "\U000024e8", "\U000024e9", "\U000024ea", "\U0001d552", "\U0001d553", "\U0001d554", "\U0001d555", "\U0001d556", "\U0001d557", "\U0001d558", "\U0001d559", "\U0001d55a", "\U0001d55b", "\U0001d55c", "\U0001d55d", "\U0001d55e", "\U0001d55f", "\U0001d560", "\U0001d561", "\U0001d562", "\U0001d563", "\U0001d564", "\U0001d565", "\U0001d566", "\U0001d567", "\U0001d568", "\U0001d569", "\U0001d56a", "\U0001d56b", "\U0001f130", "\U0001f131", "\U0001f132", "\U0001f133", "\U0001f134", "\U0001f135", "\U0001f136", "\U0001f137", "\U0001f138", "\U0001f139", "\U0001f13a", "\U0001f13b", "\U0001f13c", "\U0001f13d", "\U0001f13e", "\U0001f13f", "\U0001f140", "\U0001f141", "\U0001f142", "\U0001f143", "\U0001f144", "\U0001f145", "\U0001f146", "\U0001f147", "\U0001f148", "\U0001f149", "\U000020b3", "\U00000e3f", "\U000020b5", "\U00000110", "\U00000246", "\U000020a3", "\U000020b2", "\U00002c67", "\U00000142", "\U0000004a", "\U000020ad", "\U00002c60", "\U000020a5", "\U000020a6", "\U000000d8", "\U000020b1", "\U00000051", "\U00002c64", "\U000020b4", "\U000020ae", "\U00000244", "\U00000056", "\U000020a9", "\U000004fe", "\U0000024e", "\U00002c6b", "\U0001d586", "\U0001d587", "\U0001d588", "\U0001d589", "\U0001d58a", "\U0001d58b", "\U0001d58c", "\U0001d58d", "\U0001d58e", "\U0001d58f", "\U0001d590", "\U0001d591", "\U0001d592", "\U0001d593", "\U0001d594", "\U0001d595", "\U0001d596", "\U0001d597", "\U0001d598", "\U0001d599", "\U0001d59a", "\U0001d59b", "\U0001d59c", "\U0001d59d", "\U0001d59e", "\U0001d59f", "\U0001f170", "\U0001f171", "\U0001f172", "\U0001f173", "\U0001f174", "\U0001f175", "\U0001f176", "\U0001f177", "\U0001f178", "\U0001f179", "\U0001f17a", "\U0001f17b", "\U0001f17c", "\U0001f17d", "\U0001f17e", "\U0001f17f", "\U0001f180", "\U0001f181", "\U0001f182", "\U0001f183", "\U0001f184", "\U0001f185", "\U0001f186", "\U0001f187", "\U0001f188", "\U0001f189", "\U0001f1fa", "\U0001f1e6", " ", "\U000002e2", "\U00001d50", "\U00001d52", "\U000002e1", "\U0000207f", "\U00001d43", "\U00001d57", "\U00001da6", "\U00001d52", "\U0000207f", "\U0000041d", "\U00000438", "\U00000433", "\U0001F1F3", "\U0001F1EE", "\U0001f193", "\U00001d2d" }; for (var x = 0; x < keys.Length; x++) { map.Add((keys[x], vals[x])); } var opts = CMOptions.Default; opts.MatchRepeating = true; var matcher = new ConfusableMatcher(map, null); var res = matcher.IndexOf(In, Contains, opts); AssertMatch(res, ExpectedIndex, ExpectedLength); }
void Test32() { var map = new List <(string Key, string Value)>(); var opts = CMOptions.Default; opts.MatchOnWordBoundary = true; opts.MatchRepeating = true; var matcher = new ConfusableMatcher(map, null); var res = matcher.IndexOf("QQQ", "Q", opts); AssertMatch(res, 0, 3); res = matcher.IndexOf("aQQQ", "Q", opts); Assert.True(res.Status == CM_RETURN_STATUS.WORD_BOUNDARY_FAIL_START || res.Status == CM_RETURN_STATUS.WORD_BOUNDARY_FAIL_END); AssertMatchMulti(res, new[] { 1, 1, 1, 2, 2, 3 }, new[] { 1, 2, 3, 1, 2, 1 }, res.Status); res = matcher.IndexOf("QQQa", "Q", opts); Assert.True(res.Status == CM_RETURN_STATUS.WORD_BOUNDARY_FAIL_START || res.Status == CM_RETURN_STATUS.WORD_BOUNDARY_FAIL_END); AssertMatchMulti(res, new[] { 0, 0, 0, 1, 1, 2 }, new[] { 1, 2, 3, 1, 2, 1 }, res.Status); res = matcher.IndexOf("a QQQ", "Q", opts); AssertMatch(res, 2, 3); res = matcher.IndexOf("QQQ a", "Q", opts); AssertMatch(res, 0, 3); res = matcher.IndexOf("QQQ;duper", "Q", opts); AssertMatch(res, 0, 3); res = matcher.IndexOf("yes\u202FQQQ", "Q", opts); AssertMatch(res, 4, 3); }
void Test34() { var map = new List <(string Key, string Value)>(); var opts = CMOptions.Default; opts.MatchOnWordBoundary = true; opts.MatchRepeating = true; var matcher = new ConfusableMatcher(map, null); var res = matcher.IndexOf("SUPER", "SUPER", opts); AssertMatch(res, 0, 5); res = matcher.IndexOf("aSUPER", "SUPER", opts); AssertMatch(res, 1, 5, CM_RETURN_STATUS.WORD_BOUNDARY_FAIL_START); res = matcher.IndexOf("SUPERa", "SUPER", opts); AssertMatch(res, 0, 5, CM_RETURN_STATUS.WORD_BOUNDARY_FAIL_END); res = matcher.IndexOf("a SUPER", "SUPER", opts); AssertMatch(res, 2, 5); res = matcher.IndexOf("SUPER a", "SUPER", opts); AssertMatch(res, 0, 5); res = matcher.IndexOf("SUPER;duper", "SUPER", opts); AssertMatch(res, 0, 5); res = matcher.IndexOf("yes\u202FSUPER", "SUPER", opts); AssertMatch(res, 4, 5); }
void Test31() { var map = new List <(string Key, string Value)>(); var opts = CMOptions.Default; opts.MatchOnWordBoundary = true; var matcher = new ConfusableMatcher(map, null); var res = matcher.IndexOf("X", "X", opts); AssertMatch(res, 0, 1); res = matcher.IndexOf("aX", "X", opts); AssertMatch(res, 1, 1, CM_RETURN_STATUS.WORD_BOUNDARY_FAIL_START); res = matcher.IndexOf("Xa", "X", opts); AssertMatch(res, 0, 1, CM_RETURN_STATUS.WORD_BOUNDARY_FAIL_END); res = matcher.IndexOf("a X", "X", opts); AssertMatch(res, 2, 1); res = matcher.IndexOf("X a", "X", opts); AssertMatch(res, 0, 1); res = matcher.IndexOf("X;duper", "X", opts); AssertMatch(res, 0, 1); res = matcher.IndexOf("yes\uFEFFX", "X", opts); AssertMatch(res, 4, 1); }
void Test12() { var map = new List <(string Key, string Value)>(); var matcher = new ConfusableMatcher(map, new[] { "B", " ", "C" }); var res = matcher.IndexOf("AB CD", "ABCD", CMOptions.Default); AssertMatch(res, 0, 5); }
void Test6() { var map = new List <(string Key, string Value)>(); map.Add(("N", "/\\/")); map.Add(("V", "\\/")); map.Add(("I", "/")); var opts = CMOptions.Default; opts.MatchRepeating = true; var matcher = new ConfusableMatcher(map, null); var res = matcher.IndexOf("I/\\/AM", "INAN", opts); AssertNoMatch(res); res = matcher.IndexOf("I/\\/AM", "INAM", opts); AssertMatch(res, 0, 6); res = matcher.IndexOf("I/\\/AM", "IIVAM", opts); AssertMatch(res, 0, 6); }
void Test18() { var map = GetDefaultMap(); var opts = CMOptions.Default; opts.TimeoutNs = 1; opts.MatchRepeating = true; var matcher = new ConfusableMatcher(map, null); var In = "ASASASASASASASASASASASASASASASASASASASASASASASASASASASASASASASASASASASASASASASASASASASASASASASB"; var res = matcher.IndexOf(In, "ASB", opts); Assert.Equal(CM_RETURN_STATUS.TIMEOUT, res.Status); opts.StartFromEnd = true; opts.StartIndex = (nuint)In.Length - 1; res = matcher.IndexOf(In, "ASB", opts); AssertMatch(res, 92, 3); }
void Test8() { var map = new List <(string Key, string Value)>(); var matcher = new ConfusableMatcher(map, new[] { "\U00000332", "\U00000305", "[", "]" }); var res = matcher.IndexOf( "[̲̅a̲̅][̲̅b̲̅][̲̅c̲̅][̲̅d̲̅][̲̅e̲̅][̲̅f̲̅][̲̅g̲̅][̲̅h̲̅][̲̅i̲̅][̲̅j̲̅][̲̅k̲̅][̲̅l̲̅][̲̅m̲̅][̲̅n̲̅][̲̅o̲̅][̲̅p̲̅][̲̅q̲̅][̲̅r̲̅][̲̅s̲̅][̲̅t̲̅][̲̅u̲̅][̲̅v̲̅][̲̅w̲̅][̲̅x̲̅][̲̅y̲̅][̲̅z̲̅][̲̅0̲̅][̲̅1̲̅][̲̅2̲̅][̲̅3̲̅][̲̅4̲̅][̲̅5̲̅][̲̅6̲̅][̲̅7̲̅][̲̅8̲̅][̲̅9̲̅][̲̅0̲̅]", "ABCDEFGHIJKLMNOPQRSTUVWXYZ01234567890", CMOptions.Default); AssertMatch(res, 3, 253); }
void Test3() { var map = new List <(string Key, string Value)>(); map.Add(("A", "\x02\x03")); map.Add(("B", "\xFA\xFF")); var matcher = new ConfusableMatcher(map, null); var res = matcher.IndexOf("\x02\x03\xFA\xFF", "AB", CMOptions.Default); AssertMatch(res, 0, 4); }
void Test5() { var map = new List <(string Key, string Value)>(); map.Add(("N", "/\\/")); map.Add(("N", "/\\")); map.Add(("I", "/")); var matcher = new ConfusableMatcher(map, null); var res = matcher.IndexOf("/\\/CE", "NICE", CMOptions.Default); AssertMatch(res, 0, 5); }
public void Test1() { var map = new List <(string Key, string Value)>(); map.Add(("N", "T")); map.Add(("I", "E")); map.Add(("C", "S")); map.Add(("E", "T")); var matcher = new ConfusableMatcher(map, null); var res = matcher.IndexOf("TEST", "NICE", CMOptions.Default); AssertMatch(res, 0, 4); }
void Test11() { var map = new List <(string Key, string Value)>(); var matcher = new ConfusableMatcher(map, null); var res = matcher.IndexOf("A", "A", CMOptions.Default); AssertMatch(res, 0, 1); var matcher2 = new ConfusableMatcher(map, null, false); res = matcher2.IndexOf("A", "A", CMOptions.Default); AssertNoMatch(res); }
void Test7() { var map = GetDefaultMap(); var @in = "AAAAAAAAASSAFSAFNFNFNISFNSIFSIFJSDFUDSHF ASUF/|/__/|/___%/|/%I%%/|//|/%%%%%NNNN/|/NN__/|/N__𝘪G___%____$__G__𝓰𝘦Ѓ"; var opts = CMOptions.Default; opts.MatchRepeating = true; var matcher = new ConfusableMatcher(map, new[] { "_", "%", "$" }); var res = matcher.IndexOf(@in, "NIGGER", opts); AssertMatchMulti(res, new[] { 64, 89 }, new[] { 50, 25 }); }
void Test13() { var opts = CMOptions.Default; opts.MatchRepeating = true; var map = new List <(string Key, string Value)>() { ("N", "/\\/") }; var ignoreList = new List <string>(); var matcher = new ConfusableMatcher(map, null); bool running = true; var @lock = new object(); var t1 = new Thread(() => { while (running) { lock (@lock) { matcher.IndexOf("/\\/", "N", opts); } } }); var t2 = new Thread(() => { while (running) { lock (@lock) { if (matcher != null) { matcher.Dispose(); } matcher = new ConfusableMatcher(map, null, true); } Thread.Sleep(500); } }); t1.Start(); t2.Start(); Thread.Sleep(10000); running = false; t1.Join(); t2.Join(); }
void Test4() { var map = new List <(string Key, string Value)>(); map.Add(("S", "$")); map.Add(("D", "[)")); var matcher = new ConfusableMatcher(map, new[] { "_", " " }); var opts = CMOptions.Default; opts.MatchRepeating = true; var res = matcher.IndexOf("A__ _ $$$[)D", "ASD", opts); AssertMatch(res, 0, 11); }
void Test19() { var map = GetDefaultMap(); var opts = CMOptions.Default; opts.MatchRepeating = true; opts.TimeoutNs = 5000000; var matcher = new ConfusableMatcher(map, new[] { "̇", "̸" }); var In = "Ṅ̸iggęr"; var res = matcher.IndexOf(In, "NIGGER", opts); AssertMatch(res, 0, 8); }
void Test14() { var opts = CMOptions.Default; opts.StartIndex = 2; var map = new List <(string Key, string Value)>() { ("⿌", "⿌"), ("⎀", "⎀") }; var matcher = new ConfusableMatcher(map, null); var res = matcher.IndexOf("碐랩⿌⎀ꅉᚲ콅讷鷪", "⿌⎀", opts); AssertMatch(res, 2, 2); }
void Test33() { var map = new List <(string Key, string Value)>(); var @in = "a QBQQ"; var opts = CMOptions.Default; opts.MatchOnWordBoundary = true; opts.MatchRepeating = true; opts.StartFromEnd = true; opts.StartIndex = (nuint)@in.Length - 1; var matcher = new ConfusableMatcher(map, new[] { "B" }); var res = matcher.IndexOf(@in, "Q", opts); AssertMatch(res, 2, 4); }
void Test9() { var map = new List <(string Key, string Value)>(); map.Add(("B", "A")); map.Add(("B", "AB")); map.Add(("B", "ABC")); map.Add(("B", "ABCD")); map.Add(("B", "ABCDE")); map.Add(("B", "ABCDEF")); map.Add(("B", "ABCDEFG")); map.Add(("B", "ABCDEFGH")); map.Add(("B", "ABCDEFGHI")); map.Add(("B", "ABCDEFGHIJ")); map.Add(("B", "ABCDEFGHIJK")); map.Add(("B", "ABCDEFGHIJKL")); map.Add(("B", "ABCDEFGHIJKLM")); map.Add(("B", "ABCDEFGHIJKLMN")); map.Add(("B", "ABCDEFGHIJKLMNO")); map.Add(("B", "ABCDEFGHIJKLMNOP")); map.Add(("B", "ABCDEFGHIJKLMNOPQ")); map.Add(("B", "ABCDEFGHIJKLMNOPQR")); map.Add(("B", "ABCDEFGHIJKLMNOPQRS")); var matcher = new ConfusableMatcher(map, null); var res = matcher.IndexOf( "ABCDEFGHIJKLMNOPQRS", "B", CMOptions.Default); AssertMatchMulti(res, new[] { 0, 0 }, new[] { 1, 1 }); map.Remove(("B", "ABCDEFGHIJKLMNOP")); map.Add(("B", "P")); map.Add(("B", "PQ")); map.Add(("B", "PQR")); map.Add(("B", "PQRS")); map.Add(("B", "PQRST")); map.Add(("B", "PQRSTU")); map.Add(("B", "PQRSTUV")); map.Add(("B", "PQRSTUVW")); map.Add(("B", "PQRSTUVWX")); map.Add(("B", "PQRSTUVWXY")); map.Add(("B", "PQRSTUVWXYZ")); map.Add(("B", "PQRSTUVWXYZ0")); map.Add(("B", "PQRSTUVWXYZ01")); map.Add(("B", "PQRSTUVWXYZ012")); map.Add(("B", "PQRSTUVWXYZ0123")); map.Add(("B", "PQRSTUVWXYZ01234")); map.Add(("B", "PQRSTUVWXYZ012345")); map.Add(("B", "PQRSTUVWXYZ0123456")); map.Add(("B", "PQRSTUVWXYZ01234567")); map.Add(("B", "PQRSTUVWXYZ012345678")); map.Add(("B", "PQRSTUVWXYZ0123456789")); matcher = new ConfusableMatcher(map, null); res = matcher.IndexOf( "ABCDEFGHIJKLMNOPQRSTUVWXYZ0123456789", "BB", CMOptions.Default); AssertMatch(res, 0, 2); var opts = CMOptions.Default; opts.MatchRepeating = true; opts.TimeoutNs = 5000000; res = matcher.IndexOf( "PQRSTUVWXYZ0123456789PQRSTUVWXYZ0123456789PQRSTUVWXYZ0123456789PQRSTUVWXYZ0123456789PQRSTUVWXYZ0123456789PQRSTUVWXYZ0123456789PQRSTUVWXYZ0123456789PQRSTUVWXYZ0123456789PQRSTUVWXYZ0123456789PQRSTUVWXYZ0123456789PQRSTUVWXYZ0123456789PQRSTUVWXYZ0123456789PQRSTUVWXYZ0123456789PQRSTUVWXYZ0123456789PQRSTUVWXYZ0123456789PQRSTUVWXYZ0123456789PQRSTUVWXYZ0123456789PQRSTUVWXYZ0123456789PQRSTUVWXYZ0123456789PQRSTUVWXYZ0123456789PQRSTUVWXYZ0123456789PQRSTUVWXYZ0123456789PQRSTUVWXYZ0123456789PQRSTUVWXYZ0123456789PQRSTUVWXYZ0123456789PQRSTUVWXYZ0123456789PQRSTUVWXYZ0123456789", "BBBBBBBBBBBBBBBBBBBBBBBBBBB", opts); AssertMatch(res, 0, 547); }