コード例 #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
        private void testFindAllIndexCommon(
            String testName, TestTest test, List <int[]> result, bool resultIndicesAreUTF8)
        {
            if (test.matches.Length == 0 && result == null)
            {
                // 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 (test.matches.Length != result.Count)
                {
                    Assert.Fail(
                        String.Format(
                            "{0}: expected {1} matches; got {2}: {3}",
                            testName,
                            test.matches.Length,
                            result.Count,
                            test));
                }

                for (int k = 0; k < test.matches.Length; k++)
                {
                    int[] e   = test.matches[k];
                    int[] res = result[k];
                    if (!resultIndicesAreUTF8)
                    {
                        res = GoTestUtils.utf16IndicesToUtf8(res, test.text);
                    }

                    if (e[0] != res[0] || e[1] != res[1])
                    {
                        Assert.Fail(
                            String.Format(
                                "{0}: match {2}: expected {2}; got {3}: {4}",
                                testName,
                                k,
                                e.ToString(), // (only 1st two elements matter here)
                                res.ToString(),
                                test));
                    }
                }
            }
        }
コード例 #3
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));
                    }
                }
            }
        }
コード例 #4
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));
                }
            }
        }
コード例 #5
0
ファイル: UnitTest1.cs プロジェクト: kaby76/re2cs
 // The n and x parameters construct a [][]int by extracting n
 // sequences from x.  This represents n matches with len(x)/n
 // submatches each.
 public TestTest(String pat, String text, int n, params int[] x)
 {
     this.pat      = pat;
     this.text     = text;
     this.textUTF8 = GoTestUtils.utf8(text);
     this.matches  = new int[n][];
     if (n > 0)
     {
         int runLength = x.Length / n;
         for (int j = 0, i = 0; i < n; i++)
         {
             matches[i] = new int[runLength];
             System.Array.Copy(x, j, matches[i], 0, runLength);
             j += runLength;
             if (j > x.Length)
             {
                 Assert.Fail("invalid build entry");
             }
         }
     }
 }
コード例 #6
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));
                }
            }
        }
コード例 #7
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));
                }
            }
        }
コード例 #8
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));
                }
            }
        }
コード例 #9
0
ファイル: UnitTest1.cs プロジェクト: kaby76/re2cs
 public String submatchString(int i, int j)
 {
     return(GoTestUtils.fromUTF8(submatchBytes(i, j))); // yikes
 }