コード例 #1
0
ファイル: UnitTest1.cs プロジェクト: kaby76/re2cs
        private void testFindIndexCommon(
            String testName, TestTest test, int[] result, bool resultIndicesAreUTF8)
        {
            if (test.matches.Length == 0 && GoTestUtils.len(result) == 0)
            {
                // ok
            }
            else if (test.matches.Length == 0 && result != null)
            {
                Assert.Fail(String.Format("{0}: expected no match; got one: {1}", testName, test));
            }
            else if (test.matches.Length > 0 && result == null)
            {
                Assert.Fail(String.Format("{0}: expected match; got none: {1}", testName, test));
            }
            else
            {
                if (!resultIndicesAreUTF8)
                {
                    result = GoTestUtils.utf16IndicesToUtf8(result, test.text);
                }

                int[] expect = test.matches[0]; // UTF-8 indices
                if (expect[0] != result[0] || expect[1] != result[1])
                {
                    Assert.Fail(
                        String.Format(
                            "{0}: expected {1} got {2}: {3}",
                            testName,
                            expect.ToString(),
                            result.ToString(),
                            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
        private void testSubmatchIndices(
            String testName, TestTest test, int n, int[] result, bool resultIndicesAreUTF8)
        {
            int[] expect = test.matches[n];
            if (expect.Length != GoTestUtils.len(result))
            {
                Assert.Fail(
                    String.Format(
                        "{0} {1}: expected {2} matches; got {3}: {4}",
                        testName,
                        n,
                        expect.Length / 2,
                        GoTestUtils.len(result) / 2,
                        test));
                return;
            }

            if (!resultIndicesAreUTF8)
            {
                result = GoTestUtils.utf16IndicesToUtf8(result, test.text);
            }

            for (int k = 0; k < expect.Length; ++k)
            {
                if (expect[k] != result[k])
                {
                    Assert.Fail(
                        String.Format(
                            "{0} {1}: submatch error: expected {2} got {3}: {4}",
                            testName,
                            n,
                            expect.ToString(),
                            result.ToString(),
                            test));
                }
            }
        }
コード例 #4
0
ファイル: UnitTest1.cs プロジェクト: kaby76/re2cs
        // (Go: testSubmatchString)
        private void testSubmatch(String testName, TestTest test, int n, String[] 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 < submatches.Length; k += 2)
            {
                if (submatches[k] == -1)
                {
                    if (result[k / 2] != null && result[k / 2].Length != 0)
                    {
                        Assert.Fail(
                            String.Format(
                                "{0} {1}: expected null got {2}: {3}", testName, n, result.ToString(), test));
                    }

                    continue;
                }

                System.Console.WriteLine(testName + "  " + test + " " + n + " " + k + " ");
                String expect = test.submatchString(n, k / 2);
                if (!expect.Equals(result[k / 2]))
                {
                    Assert.Fail(String.Format("{0} {1}: expected {2} got {3}: {4}", testName, n, expect, result, test));
                }
            }
        }
コード例 #5
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));
                }
            }
        }