Пример #1
0
        public void testSplit()
        {
            ApiTestUtils.testSplit("/", "abcde", new String[] { "abcde" });
            ApiTestUtils.testSplit("/", "a/b/cc//d/e//", new String[] { "a", "b", "cc", "", "d", "e" });
            ApiTestUtils.testSplit("/", "a/b/cc//d/e//", 3, new String[] { "a", "b", "cc//d/e//" });
            ApiTestUtils.testSplit("/", "a/b/cc//d/e//", 4, new String[] { "a", "b", "cc", "/d/e//" });
            ApiTestUtils.testSplit("/", "a/b/cc//d/e//", 5, new String[] { "a", "b", "cc", "", "d/e//" });
            ApiTestUtils.testSplit("/", "a/b/cc//d/e//", 6, new String[] { "a", "b", "cc", "", "d", "e//" });
            ApiTestUtils.testSplit(
                "/", "a/b/cc//d/e//", 7, new String[] { "a", "b", "cc", "", "d", "e", "/" });
            ApiTestUtils.testSplit(
                "/", "a/b/cc//d/e//", 8, new String[] { "a", "b", "cc", "", "d", "e", "", "" });
            ApiTestUtils.testSplit(
                "/", "a/b/cc//d/e//", 9, new String[] { "a", "b", "cc", "", "d", "e", "", "" });

            // The tests below are listed at
            // http://docs.oracle.com/javase/1.5.0/docs/api/java/util/regex/Pattern.html#split(java.lang.CharSequence, int)

            String s       = "boo:and:foo";
            String regexp1 = ":";
            String regexp2 = "o";

            ApiTestUtils.testSplit(regexp1, s, 2, new String[] { "boo", "and:foo" });
            ApiTestUtils.testSplit(regexp1, s, 5, new String[] { "boo", "and", "foo" });
            ApiTestUtils.testSplit(regexp1, s, -2, new String[] { "boo", "and", "foo" });
            ApiTestUtils.testSplit(regexp2, s, 5, new String[] { "b", "", ":and:f", "", "" });
            ApiTestUtils.testSplit(regexp2, s, -2, new String[] { "b", "", ":and:f", "", "" });
            ApiTestUtils.testSplit(regexp2, s, 0, new String[] { "b", "", ":and:f" });
            ApiTestUtils.testSplit(regexp2, s, new String[] { "b", "", ":and:f" });
        }
Пример #2
0
 public void testGroupCount()
 {
     // It is a simple delegation, but still test it.
     ApiTestUtils.testGroupCount("(.*)ab(.*)a", 2);
     ApiTestUtils.testGroupCount("(.*)(ab)(.*)a", 3);
     ApiTestUtils.testGroupCount("(.*)((a)b)(.*)a", 4);
     ApiTestUtils.testGroupCount("(.*)(\\(ab)(.*)a", 3);
     ApiTestUtils.testGroupCount("(.*)(\\(a\\)b)(.*)a", 3);
 }
Пример #3
0
        public void testMatchesWithFlags()
        {
            ApiTestUtils.testMatchesRE2("ab+c", 0, "abbbc", "cbba");
            ApiTestUtils.testMatchesRE2("ab+c", Pattern.CASE_INSENSITIVE, "abBBc", "cbbba");
            ApiTestUtils.testMatchesRE2("ab.*c", 0, "abxyzc", "ab\nxyzc");
            ApiTestUtils.testMatchesRE2("ab.*c", Pattern.DOTALL, "ab\nxyzc", "aB\nxyzC");
            ApiTestUtils.testMatchesRE2(
                "ab.*c", Pattern.DOTALL | Pattern.CASE_INSENSITIVE, "aB\nxyzC", "z");
            ApiTestUtils.testMatchesRE2("^ab.*c$", 0, "abc", "xyz\nabc\ndef");

            ApiTestUtils.testMatchesRE2("^ab.*c$", Pattern.MULTILINE, "abc", "xyz\nabc\ndef");
            ApiTestUtils.testMatchesRE2("^ab.*c$", Pattern.MULTILINE, "abc", "");
            ApiTestUtils.testMatchesRE2("^ab.*c$", Pattern.DOTALL | Pattern.MULTILINE, "ab\nc", "AB\nc");
            ApiTestUtils.testMatchesRE2(
                "^ab.*c$", Pattern.DOTALL | Pattern.MULTILINE | Pattern.CASE_INSENSITIVE, "AB\nc", "z");
        }
Пример #4
0
 public void testMatchesNoFlags()
 {
     ApiTestUtils.testMatches("ab+c", "abbbc", "cbbba");
     ApiTestUtils.testMatches("ab.*c", "abxyzc", "ab\nxyzc");
     ApiTestUtils.testMatches("^ab.*c$", "abc", "xyz\nabc\ndef");
 }
Пример #5
0
 public void testQuote()
 {
     ApiTestUtils.testMatchesRE2(Pattern.quote("ab+c"), 0, "ab+c", "abc");
 }