Пример #1
0
 // (Go: testFindSubmatchIndex)
 private void testFindAllSubmatchIndexCommon(
     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));
     }
     else
     {
         for (int k = 0; k < test.matches.Length; ++k)
         {
             testSubmatchIndices(testName, test, k, result[k], resultIndicesAreUTF8);
         }
     }
 }
Пример #2
0
        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));
                }
            }
        }
Пример #3
0
        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));
                    }
                }
            }
        }
Пример #4
0
 private void testFindSubmatchIndexCommon(
     String testName, TestTest test, 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
     {
         testSubmatchIndices(testName, test, 0, result, resultIndicesAreUTF8);
     }
 }
Пример #5
0
 public void DoFrigginTests()
 {
     foreach (var p in FIND_TESTS)
     {
         test = p;
         testFindUTF8();
         testFind();
         testFindUTF8Index();
         testFindIndex();
         testFindAllUTF8();
         testFindAll();
         testFindAllUTF8Index();
         testFindUTF8Submatch();
         testFindSubmatch();
         testFindUTF8SubmatchIndex();
         testFindSubmatchIndex();
         testFindAllUTF8Submatch();
         testFindAllSubmatch();
         testFindAllUTF8SubmatchIndex();
         testFindAllSubmatchIndex();
     }
 }
Пример #6
0
        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
        // (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
 public override int GetHashCode() => TestTest.GetHashCode();