예제 #1
0
파일: UnitTest1.cs 프로젝트: kaby76/re2cs
        // 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));
                    }
                }
            }
        }
예제 #2
0
파일: UnitTest1.cs 프로젝트: kaby76/re2cs
        // Now come the Submatch cases.

        private void testSubmatchBytes(String testName, FindTest.TestTest test, int n, byte[][] result)
        {
            int[] submatches = test.matches[n];
            if (submatches.Length != GoTestUtils.len(result) * 2)
            {
                Assert.Fail(
                    String.Format(
                        "{0} {1}: expected {2} submatches; got {3}: {4}",
                        testName,
                        n,
                        submatches.Length / 2,
                        GoTestUtils.len(result),
                        test));
            }

            for (int k = 0; k < GoTestUtils.len(result); k++)
            {
                if (submatches[k * 2] == -1)
                {
                    if (result[k] != null)
                    {
                        Assert.Fail(String.Format("{0} {1}: expected null got {2}: {3}", testName, n, result, test));
                    }

                    continue;
                }

                byte[] expect = test.submatchBytes(n, k);
                if (!expect.SequenceEqual(result[k]))
                {
                    Assert.Fail(
                        String.Format(
                            "{0} {1}: expected {2}; got {3}: {4}",
                            testName,
                            n,
                            GoTestUtils.fromUTF8(expect),
                            GoTestUtils.fromUTF8(result[k]),
                            test));
                }
            }
        }
예제 #3
0
파일: UnitTest1.cs 프로젝트: kaby76/re2cs
        // 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));
                }
            }
        }
예제 #4
0
파일: UnitTest1.cs 프로젝트: kaby76/re2cs
 public String submatchString(int i, int j)
 {
     return(GoTestUtils.fromUTF8(submatchBytes(i, j))); // yikes
 }