-
Notifications
You must be signed in to change notification settings - Fork 12
/
LookaroundTests.java
59 lines (51 loc) · 2.09 KB
/
LookaroundTests.java
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
package com.github.curiousoddman.rgxgen;
import com.github.curiousoddman.rgxgen.iterators.StringIterator;
import org.junit.Test;
import org.junit.runner.RunWith;
import org.junit.runners.Parameterized;
import java.util.Arrays;
import java.util.Collection;
import java.util.regex.Pattern;
import static org.junit.Assert.assertTrue;
/**
* These tests are the tests which require find() instead of matches() to verify the generated patter.
* Apparently lookahead and lookbehind does not match
*/
@RunWith(Parameterized.class)
public class LookaroundTests {
@Parameterized.Parameters(name = "{0}")
public static Collection<Object[]> data() {
return Arrays.asList(new Object[][]{
{"Positive lookahead", "foo(?=b)"},
{"Negative lookahead", "foo(?!bab)"},
{"Positive lookbehind", "(?<=foo)bar"},
{"Negative lookbehind", "(?<!not)fof"}
});
}
@Parameterized.Parameter
public String aName;
@Parameterized.Parameter(1)
public String aRegex;
@Test
public void generateTest() {
RgxGen rgxGen = new RgxGen(aRegex);
for (int i = 0; i < 100; i++) {
String s = rgxGen.generate();
assertTrue("Text: '" + s + "'does not match pattern " + aRegex, Pattern.compile(aRegex)
.matcher(s)
.find());
}
}
@Test
public void generateInfiniteTest() {
RgxGen rgxGen = new RgxGen(aRegex);
StringIterator stringIterator = rgxGen.iterateUnique();
for (int i = 0; i < 100 && stringIterator.hasNext(); i++) {
String s = stringIterator.next();
System.out.println(".");
assertTrue("Text: '" + s + "'does not match pattern " + aRegex, Pattern.compile(aRegex)
.matcher(s)
.find());
}
}
}