// (Go: TestFindAllStringSubmatch) public void testFindAllSubmatch() { List <String[]> result = RE2.compile(test.pat).findAllSubmatch(test.text, -1); if (test.matches.Length == 0 && result == null) { // ok } else if (test.matches.Length == 0 && result != null) { Assert.Fail(String.Format("expected no match; got one: {0}", test)); } else if (test.matches.Length > 0 && result == null) { Assert.Fail(String.Format("expected match; got none: {0}", test)); } else if (test.matches.Length != result.Count) { Assert.Fail( String.Format( "expected {0} matches; got {1}: {2}", test.matches.Length, result.Count, test)); } else { for (int k = 0; k < test.matches.Length; ++k) { testSubmatch("testFindAllStringSubmatch", test, k, result[k]); } } }
public void testFind() { String result = RE2.compile(test.pat).find(test.text); if (test.matches.Length == 0 && result.Length == 0) { // ok } else if (test.matches.Length == 0 && result.Length != 0) { Assert.Fail(String.Format("find: expected no match; got one: {0}", test)); } else if (test.matches.Length > 0 && result.Length == 0) { // Tricky because an empty result has two meanings: // no match or empty match. int[] match = test.matches[0]; if (match[0] != match[1]) { Assert.Fail(String.Format("find: expected match; got none: %s", test)); } } else { String expect = test.submatchString(0, 0); if (!expect.Equals(result)) { Assert.Fail(String.Format("find: expected {0} got {1}: {2}", expect, result, test)); } } }
// (Go: TestFindAllStringSubmatchIndex) public void testFindAllSubmatchIndex() { testFindAllSubmatchIndexCommon( "testFindAllSubmatchIndex", test, RE2.compile(test.pat).findAllSubmatchIndex(test.text, -1), false); }
// (Go: TestFindAllSubmatchIndex) public void testFindAllUTF8SubmatchIndex() { testFindAllSubmatchIndexCommon( "testFindAllUTF8SubmatchIndex", test, RE2.compile(test.pat).findAllUTF8SubmatchIndex(test.textUTF8, -1), true); }
// (Go: TestFindStringSubmatchIndex) public void testFindSubmatchIndex() { testFindSubmatchIndexCommon( "testFindStringSubmatchIndex", test, RE2.compile(test.pat).findSubmatchIndex(test.text), false); }
static void Main(string[] args) { // Cox's simple example. string text = "abbb"; string pat = "abab|abbb"; var compiled = RE2.compile(pat); var result = compiled.match(text); System.Console.WriteLine("Result of pat '" + pat + "' in text '" + text + "'" + result); }
// Now come the simple All cases. public void testFindAllUTF8() { List <byte[]> result = RE2.compile(test.pat).findAllUTF8(test.textUTF8, -1); if (test.matches.Length == 0 && result == null) { // ok } else if (test.matches.Length == 0 && result != null) { Assert.Fail(String.Format("findAllUTF8: expected no match; got one: {0}", test)); } else if (test.matches.Length > 0 && result == null) { throw new Exception("findAllUTF8: expected match; got none: " + test); } else { if (test.matches.Length != result.Count) { Assert.Fail( String.Format( "findAllUTF8: expected {0} matches; got {1}: {2}", test.matches.Length, result.Count), test); } for (int i = 0; i < test.matches.Length; i++) { byte[] expect = test.submatchBytes(i, 0); if (!expect.SequenceEqual(result[i])) { Assert.Fail( String.Format( "findAllUTF8: match {0}: expected {1}; got {2}: {3}", i / 2, GoTestUtils.fromUTF8(expect), GoTestUtils.fromUTF8(result[i]), test)); } } } }
// (Go: TestFindStringSubmatch) public void testFindSubmatch() { String[] result = RE2.compile(test.pat).findSubmatch(test.text); if (test.matches.Length == 0 && result == null) { // ok } else if (test.matches.Length == 0 && result != null) { Assert.Fail(String.Format("expected no match; got one: {0}", test)); } else if (test.matches.Length > 0 && result == null) { Assert.Fail(String.Format("expected match; got none: {0}", test)); } else { testSubmatch("testFindSubmatch", test, 0, result); } }
public void testFindAll() { List <String> result = RE2.compile(test.pat).findAll(test.text, -1); if (test.matches.Length == 0 && result == null) { // ok } else if (test.matches.Length == 0 && result != null) { Assert.Fail(String.Format("findAll: expected no match; got one: {0}", test)); } else if (test.matches.Length > 0 && result == null) { Assert.Fail(String.Format("findAll: expected match; got none: {0}", test)); } else { if (test.matches.Length != result.Count) { Assert.Fail( String.Format( "findAll: expected {0} matches; got {1}: {2}", test.matches.Length, result.Count, test)); } for (int i = 0; i < test.matches.Length; i++) { String expect = test.submatchString(i, 0); if (!expect.Equals(result[i])) { Assert.Fail(String.Format("findAll: expected {0}; got {1}: {2}", expect, result, test)); } } } }
// First the simple cases. public void testFindUTF8() { RE2 re = RE2.compile(test.pat); if (!re.ToString().Equals(test.pat)) { Assert.Fail(String.Format("RE2.toString() = \"{0}\"; should be \"{1}\"", re.ToString(), test.pat)); } byte[] result = re.findUTF8(test.textUTF8); if (test.matches.Length == 0 && GoTestUtils.len(result) == 0) { // ok } else if (test.matches.Length == 0 && result != null) { Assert.Fail(String.Format("findUTF8: expected no match; got one: {0}", test)); } else if (test.matches.Length > 0 && result == null) { Assert.Fail(String.Format("findUTF8: expected match; got none: {0}", test)); } else { byte[] expect = test.submatchBytes(0, 0); if (!expect.SequenceEqual(result)) { Assert.Fail( String.Format( "findUTF8: expected {0}; got {1}: {2}", GoTestUtils.fromUTF8(expect), GoTestUtils.fromUTF8(result), test)); } } }
public void testFindIndex() { int[] result = RE2.compile(test.pat).findIndex(test.text); testFindIndexCommon("testFindIndex", test, result, false); }
public void testFindUTF8Index() { testFindIndexCommon( "testFindUTF8Index", test, RE2.compile(test.pat).findUTF8Index(test.textUTF8), true); }