Exemplo n.º 1
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));
                }
            }
        }
Exemplo n.º 2
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));
                    }
                }
            }
        }
Exemplo n.º 3
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));
                }
            }
        }