public void TestSpecialCase3() { RegExp re = new RegExp("(\\鯺)*(.)*\\Ӕ"); string input = "\u5cfd\ufffd\ub2f7\u0033\ue304\u51d7\u3692\udb50\udfb3\u0576\udae2\udc62\u0053\u0449\u04d4"; Automaton automaton = re.ToAutomaton(); CharacterRunAutomaton cra = new CharacterRunAutomaton(automaton); ByteRunAutomaton bra = new ByteRunAutomaton(automaton); Assert.IsTrue(cra.Run(input)); sbyte[] bytes = input.GetBytes(Encoding.UTF8); Assert.IsTrue(bra.Run(bytes, 0, bytes.Length)); }
public void TestSpecialCase2() { RegExp re = new RegExp(".+\u0775"); string input = "\ufadc\ufffd\ub80b\uda5a\udc68\uf234\u0056\uda5b\udcc1\ufffd\ufffd\u0775"; Automaton automaton = re.ToAutomaton(); CharacterRunAutomaton cra = new CharacterRunAutomaton(automaton); ByteRunAutomaton bra = new ByteRunAutomaton(automaton); Assert.IsTrue(cra.Run(input)); sbyte[] bytes = input.GetBytes(Encoding.UTF8); Assert.IsTrue(bra.Run(bytes, 0, bytes.Length)); // this one fails! }
public void TestSpecialCase() { RegExp re = new RegExp(".?"); Automaton automaton = re.ToAutomaton(); CharacterRunAutomaton cra = new CharacterRunAutomaton(automaton); ByteRunAutomaton bra = new ByteRunAutomaton(automaton); // make sure character dfa accepts empty string Assert.IsTrue(cra.IsAccept(cra.InitialState)); Assert.IsTrue(cra.Run("")); Assert.IsTrue(cra.Run(new char[0], 0, 0)); // make sure byte dfa accepts empty string Assert.IsTrue(bra.IsAccept(bra.InitialState)); Assert.IsTrue(bra.Run(new byte[0], 0, 0)); }
public void AssertLexicon(List<Automaton> a, List<string> terms) { var automata = CollectionsHelper.Shuffle(a); var lex = BasicOperations.Union(automata); lex.Determinize(); Assert.IsTrue(SpecialOperations.IsFinite(lex)); foreach (string s in terms) { Assert.IsTrue(BasicOperations.Run(lex, s)); } var lexByte = new ByteRunAutomaton(lex); foreach (string s in terms) { var bytes = s.GetBytes(Encoding.UTF8); Assert.IsTrue(lexByte.Run(bytes, 0, bytes.Length)); } }
public void AssertLexicon(List<Automaton> a, List<string> terms) { var automata = CollectionsHelper.Shuffle(a); var lex = BasicOperations.Union(automata); lex.Determinize(); Assert.IsTrue(SpecialOperations.IsFinite(lex)); foreach (string s in terms) { Assert.IsTrue(BasicOperations.Run(lex, s)); } var lexByte = new ByteRunAutomaton(lex); foreach (string s in terms) { sbyte[] bytes = s.GetBytes(Encoding.UTF8); Assert.IsTrue(lexByte.Run(bytes, 0, bytes.Length)); } }
public void AssertLexicon() { Collections.Shuffle(automata, Random()); var lex = BasicOperations.Union(automata); lex.Determinize(); Assert.IsTrue(SpecialOperations.IsFinite(lex)); foreach (string s in terms) { assertTrue(BasicOperations.Run(lex, s)); } var lexByte = new ByteRunAutomaton(lex); foreach (string s in terms) { var bytes = s.GetBytes(Encoding.UTF8); assertTrue(lexByte.Run(bytes, 0, bytes.Length)); } }
private static void AssertAutomaton(Automaton automaton) { var cra = new CharacterRunAutomaton(automaton); var bra = new ByteRunAutomaton(automaton); var ras = new AutomatonTestUtil.RandomAcceptedStrings(automaton); int num = AtLeast(1000); for (int i = 0; i < num; i++) { string s; if (Random().NextBoolean()) { // likely not accepted s = TestUtil.RandomUnicodeString(Random()); } else { // will be accepted int[] codepoints = ras.GetRandomAcceptedString(Random()); try { s = UnicodeUtil.NewString(codepoints, 0, codepoints.Length); } catch (Exception e) { Console.WriteLine(codepoints.Length + " codepoints:"); for (int j = 0; j < codepoints.Length; j++) { Console.WriteLine(" " + codepoints[j].ToString("x")); } throw e; } } var bytes = s.GetBytes(Encoding.UTF8); Assert.AreEqual(cra.Run(s), bra.Run(bytes, 0, bytes.Length)); } }
private static void AssertAutomaton(Automaton automaton) { var cra = new CharacterRunAutomaton(automaton); var bra = new ByteRunAutomaton(automaton); var ras = new RandomAcceptedStrings(automaton); int num = AtLeast(1000); for (int i = 0; i < num; i++) { string s; if (Random.NextBoolean()) { // likely not accepted s = TestUtil.RandomUnicodeString(Random); } else { // will be accepted int[] codepoints = ras.GetRandomAcceptedString(Random); try { s = UnicodeUtil.NewString(codepoints, 0, codepoints.Length); } catch (Exception /*e*/) { Console.WriteLine(codepoints.Length + " codepoints:"); for (int j = 0; j < codepoints.Length; j++) { Console.WriteLine(" " + codepoints[j].ToString("x")); } throw; // LUCENENET: CA2200: Rethrow to preserve stack details (https://docs.microsoft.com/en-us/visualstudio/code-quality/ca2200-rethrow-to-preserve-stack-details) } } var bytes = s.GetBytes(Encoding.UTF8); Assert.AreEqual(cra.Run(s), bra.Run(bytes, 0, bytes.Length)); } }
private bool Matches(ByteRunAutomaton a, int code) { char[] chars = Character.ToChars(code); UnicodeUtil.UTF16toUTF8(chars, 0, chars.Length, b); return(a.Run(b.Bytes, 0, b.Length)); }
public void TestSpecialCase() { RegExp re = new RegExp(".?"); Automaton automaton = re.ToAutomaton(); CharacterRunAutomaton cra = new CharacterRunAutomaton(automaton); ByteRunAutomaton bra = new ByteRunAutomaton(automaton); // make sure character dfa accepts empty string Assert.IsTrue(cra.IsAccept(cra.InitialState)); Assert.IsTrue(cra.Run("")); Assert.IsTrue(cra.Run(new char[0], 0, 0)); // make sure byte dfa accepts empty string Assert.IsTrue(bra.IsAccept(bra.InitialState)); Assert.IsTrue(bra.Run(new byte[0], 0, 0)); }
private bool Matches(ByteRunAutomaton a, int code) { char[] chars = Character.ToChars(code); UnicodeUtil.UTF16toUTF8(chars, 0, chars.Length, b); return a.Run(b.Bytes, 0, b.Length); }
private static void AssertAutomaton(Automaton automaton) { var cra = new CharacterRunAutomaton(automaton); var bra = new ByteRunAutomaton(automaton); var ras = new AutomatonTestUtil.RandomAcceptedStrings(automaton); int num = AtLeast(1000); for (int i = 0; i < num; i++) { string s; if (Random().NextBoolean()) { // likely not accepted s = TestUtil.RandomUnicodeString(Random()); } else { // will be accepted int[] codepoints = ras.GetRandomAcceptedString(Random()); try { s = UnicodeUtil.NewString(codepoints, 0, codepoints.Length); } catch (Exception e) { Console.WriteLine(codepoints.Length + " codepoints:"); for (int j = 0; j < codepoints.Length; j++) { Console.WriteLine(" " + codepoints[j].ToString("x")); } throw e; } } var bytes = s.GetBytes(Encoding.UTF8); Assert.AreEqual(cra.Run(s), bra.Run(bytes, 0, bytes.Length)); } }
public void TestSpecialCase3() { RegExp re = new RegExp("(\\鯺)*(.)*\\Ӕ"); string input = "\u5cfd\ufffd\ub2f7\u0033\ue304\u51d7\u3692\udb50\udfb3\u0576\udae2\udc62\u0053\u0449\u04d4"; Automaton automaton = re.ToAutomaton(); CharacterRunAutomaton cra = new CharacterRunAutomaton(automaton); ByteRunAutomaton bra = new ByteRunAutomaton(automaton); Assert.IsTrue(cra.Run(input)); var bytes = input.GetBytes(Encoding.UTF8); Assert.IsTrue(bra.Run(bytes, 0, bytes.Length)); }
public void TestSpecialCase2() { RegExp re = new RegExp(".+\u0775"); string input = "\ufadc\ufffd\ub80b\uda5a\udc68\uf234\u0056\uda5b\udcc1\ufffd\ufffd\u0775"; Automaton automaton = re.ToAutomaton(); CharacterRunAutomaton cra = new CharacterRunAutomaton(automaton); ByteRunAutomaton bra = new ByteRunAutomaton(automaton); Assert.IsTrue(cra.Run(input)); var bytes = input.GetBytes(Encoding.UTF8); Assert.IsTrue(bra.Run(bytes, 0, bytes.Length)); // this one fails! }