Пример #1
0
 @Test
 public void testIndexOfNamedGroupContainingSpecialConstruct() {
   Pattern p =
       Pattern.compile(
           "\\d{2}/\\d{2}/\\d{4}: EXCEPTION - (?<exception>(?s)(.+(?:Exception|Error)[^\\n]+(?:\\s++at [^\\n]+)++)(?:\\s*\\.{3}[^\\n]++)?\\s*)\\n");
   assertEquals(0, p.indexOf("exception"));
 }
Пример #2
0
 @Test
 public void testIndexOfWithInvalidPositiveInstanceIndex() {
   Pattern p = Pattern.compile("(a)(?<named>x)(b)(?:c)(?<named>y)");
   thrown.expect(IndexOutOfBoundsException.class);
   thrown.expectMessage("Index: 10000000, Size: 2");
   assertEquals(-1, p.indexOf("named", 10000000));
 }
Пример #3
0
 @Test
 public void testIndexOfNamedGroupAfterNonEscapedParenAfterEscapedOpenBracket() {
   // since the open-bracket is escaped, it doesn't create a character class,
   // so the parentheses inside the "foo" group is a capturing group (that
   // currently captures nothing but still valid regex and thus counted)
   Pattern p = Pattern.compile("(a)(?<foo>\\[()])(?:c)(?<named>x)");
   assertEquals(3, p.indexOf("named"));
 }
Пример #4
0
 @Test
 public void testIndexOfWithInvalidNegativeInstanceIndex() {
   Pattern p = Pattern.compile("(a)(?<named>x)(b)(?:c)(?<named>y)");
   // Negative index causes ArrayIndexOutOfBoundsException (which
   // is a subclass of IndexOutOfBoundsException)
   thrown.expect(ArrayIndexOutOfBoundsException.class);
   thrown.expectMessage("-100");
   assertEquals(-1, p.indexOf("named", -100));
 }
Пример #5
0
 @Test
 public void testIndexOfWithMultipleGroupsWithSameName() {
   Pattern p = Pattern.compile("(a)(?<named>x)(b)(?:c)(?<named>y)");
   assertEquals(3, p.indexOf("named", 1));
 }
Пример #6
0
 @Test
 public void testIndexOfNamedGroupAtMiddle() {
   Pattern p = Pattern.compile("(a)(?<named>x)(b)(?:c)");
   assertEquals(1, p.indexOf("named"));
 }
Пример #7
0
 @Test
 public void testIndexOfNamedGroupAfterEscapedParen() {
   Pattern p = Pattern.compile("\\(a\\)\\((b)\\)(?:c)(?<named>x)");
   assertEquals(1, p.indexOf("named"));
 }
Пример #8
0
 @Test
 public void testIndexOfNamedGroupAfterUnnamedAndNoncaptureGroups() {
   Pattern p = Pattern.compile("(a)(b)(?:c)(?<named>x)");
   assertEquals(2, p.indexOf("named"));
 }
Пример #9
0
 @Test
 public void testIndexOfNameWithUnicodeChars() {
   Pattern p = Pattern.compile("(?<gefräßig>x)");
   assertEquals(0, p.indexOf("gefräßig"));
 }
Пример #10
0
 @Test
 public void testIndexOfAcceptsNameWithClosingAngleBracket() {
   Pattern p = Pattern.compile("(?<foo bar > should not grab this bracket> x)");
   assertEquals(0, p.indexOf("foo bar "));
 }
Пример #11
0
 @Test
 public void testIndexOfAcceptsClassName() {
   Pattern p = Pattern.compile("(?<com.example.foo>x)");
   assertEquals(0, p.indexOf("com.example.foo"));
 }
Пример #12
0
 @Test
 public void testIndexOfNamedGroupAfterNonEscapedParenInCharClassWithEscapedCloseBracket() {
   Pattern p = Pattern.compile("(a)(?<foo>[\\]()])(?:c)(?<named>x)");
   assertEquals(2, p.indexOf("named"));
 }
Пример #13
0
 @Test
 public void testIndexOfNamedGroupAfterSlashedCloseParenInCharacterClass() {
   // double-slashes in a character class are literal slashes, not escapes
   Pattern p = Pattern.compile("(a)(?<foo>[(\\\\)])(?:c)(?<named>x)");
   assertEquals(2, p.indexOf("named"));
 }
Пример #14
0
 @Test
 public void testIndexOfNamedGroupAfterEscapedCloseParenInCharacterClass() {
   Pattern p = Pattern.compile("(a)(?<foo>[(\\)])(?:c)(?<named>x)");
   assertEquals(2, p.indexOf("named"));
 }
Пример #15
0
 @Test
 public void testIndexOfNamedGroupBeforeSpecialConstruct1() {
   Pattern p = Pattern.compile("(?<named>x)(?idsumx-idsumx)(?=b)(?!x)");
   assertEquals(0, p.indexOf("named"));
 }
Пример #16
0
 @Test
 public void testIndexOfNotFound() {
   Pattern p = Pattern.compile("(a)(b)(?:c)(?<named>x)");
   assertEquals(-1, p.indexOf("dummy"));
 }
Пример #17
0
 @Test
 public void testIndexOfWithPositiveLookbehindAtBeginning() {
   Pattern p = Pattern.compile("(?<=a)(b)(c)(?<named>x)");
   assertEquals(2, p.indexOf("named"));
 }
Пример #18
0
 @Test
 public void testIndexOfAcceptsNameWithSpacesAndPunctuation() {
   Pattern p = Pattern.compile("(?<  Lorem ipsum dolor sit amet, consectetur adipisicing elit>x)");
   assertEquals(0, p.indexOf("  Lorem ipsum dolor sit amet, consectetur adipisicing elit"));
 }
Пример #19
0
 @Test
 public void testIndexOfWithNegativeLookahead() {
   Pattern p = Pattern.compile("(a)(b)(?!c)(?<named>x)");
   assertEquals(2, p.indexOf("named"));
 }
Пример #20
0
 @Test
 public void testIndexOfAcceptsNameWithNewLines() {
   Pattern p = Pattern.compile("(?<Lorem ipsum dolor sit amet,\n consectetur adipisicing elit>x)");
   assertEquals(0, p.indexOf("Lorem ipsum dolor sit amet,\n consectetur adipisicing elit"));
 }
Пример #21
0
 @Test
 public void testIndexOfWithFlagsAndExtraNoCapture() {
   Pattern p = Pattern.compile("(a)(b)(?idsumx:Z)(?<named>x)");
   assertEquals(2, p.indexOf("named"));
 }
Пример #22
0
 @Test
 public void testIndexOfNamedGroup() {
   Pattern p = Pattern.compile("(?<named>x)");
   assertEquals(0, p.indexOf("named"));
 }
Пример #23
0
 @Test
 public void testIndexOfNamedGroupAtBeginning() {
   Pattern p = Pattern.compile("(?<named>x)(a)(b)(?:c)");
   assertEquals(0, p.indexOf("named"));
 }
Пример #24
0
 @Test
 public void testIndexOfNamedGroupAfterAnotherNamedGroup() {
   Pattern p = Pattern.compile("(a)(?<foo>)(?:c)(?<named>x)");
   assertEquals(2, p.indexOf("named"));
 }
Пример #25
0
 @Test
 public void testIndexOfNestedNamedGroup() {
   Pattern p = Pattern.compile("(a)(?<foo>b)(?:c)(?<bar>d(?<named>x))");
   assertEquals(3, p.indexOf("named"));
 }