Exemple #1
0
        // 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));
                }
            }
        }