@Test public void testSerialization() throws Exception { // Default engine is the Java engine RegexStringComparator a = new RegexStringComparator("a|b"); RegexStringComparator b = RegexStringComparator.parseFrom(a.toByteArray()); assertTrue(a.areSerializedFieldsEqual(b)); assertTrue(b.getEngine() instanceof RegexStringComparator.JavaRegexEngine); // joni engine a = new RegexStringComparator("a|b", EngineType.JONI); b = RegexStringComparator.parseFrom(a.toByteArray()); assertTrue(a.areSerializedFieldsEqual(b)); assertTrue(b.getEngine() instanceof RegexStringComparator.JoniRegexEngine); }
@Test public void testJavaEngine() throws Exception { for (TestCase t: TEST_CASES) { boolean result = new RegexStringComparator(t.regex, t.flags, EngineType.JAVA) .compareTo(Bytes.toBytes(t.haystack)) == 0; assertEquals("Regex '" + t.regex + "' failed test '" + t.haystack + "'", result, t.expected); } }
@Test public void testJoniEngine() throws Exception { for (TestCase t: TEST_CASES) { boolean result = new RegexStringComparator(t.regex, t.flags, EngineType.JONI) .compareTo(Bytes.toBytes(t.haystack)) == 0; assertEquals("Regex '" + t.regex + "' failed test '" + t.haystack + "'", result, t.expected); } }