Skip to content

Commit

Permalink
#63. Negative Lookahead Error
Browse files Browse the repository at this point in the history
Tests improvement
  • Loading branch information
curious-odd-man committed Aug 29, 2021
1 parent 6d9c924 commit c9e2917
Show file tree
Hide file tree
Showing 4 changed files with 35 additions and 18 deletions.
Original file line number Diff line number Diff line change
Expand Up @@ -35,7 +35,7 @@ public void generateTest() {
String text = rgxGen.generate(TestingUtilities.newRandom(aSeed));

boolean result = isValidGenerated(text);
assertTrue("Text: '" + text + "'does not match pattern " + aTestPattern.getPattern(), result);
assertTrue(aTestPattern.getLocation() + "\nText: '" + text + "'does not match pattern " + aTestPattern.getPattern(), result);
}

@Test
Expand Down
24 changes: 13 additions & 11 deletions src/test/java/com/github/curiousoddman/rgxgen/CombinedTests.java
Original file line number Diff line number Diff line change
Expand Up @@ -35,8 +35,10 @@ public static Collection<Object> data() {
public void parseTest() {
NodeTreeBuilder defaultTreeBuilder = new DefaultTreeBuilder(aTestPattern.getPattern());
Node node = defaultTreeBuilder.get();
assertEquals(aTestPattern.getResultNode()
.toString(), node.toString());
assertEquals(
aTestPattern.getLocation(),
aTestPattern.getResultNode()
.toString(), node.toString());
NodePatternVerifyingVisitor visitor = new NodePatternVerifyingVisitor(aTestPattern.getResultNode());
node.visit(visitor);
assertTrue(visitor.getErrors()
Expand All @@ -47,21 +49,21 @@ public void parseTest() {

@Test
public void countUniqueUsingVisitorTest() {
assumeTrue(aTestPattern.hasEstimatedCount());
assumeTrue(aTestPattern.getLocation(), aTestPattern.hasEstimatedCount());
UniqueValuesCountingVisitor v = new UniqueValuesCountingVisitor(new RgxGenProperties());
aTestPattern.getResultNode()
.visit(v);
assertEquals(aTestPattern.getEstimatedCount(), v.getEstimation()
.orElse(null));
assertEquals(aTestPattern.getLocation(), aTestPattern.getEstimatedCount(), v.getEstimation()
.orElse(null));
}


@Test
public void countUniqueTest() {
assumeTrue(aTestPattern.hasEstimatedCount());
assumeTrue(aTestPattern.getLocation(), aTestPattern.hasEstimatedCount());
RgxGen rgxGen = new RgxGen(aTestPattern.getPattern());
assertEquals(aTestPattern.getEstimatedCount(), rgxGen.getUniqueEstimation()
.orElse(null));
assertEquals(aTestPattern.getLocation(), aTestPattern.getEstimatedCount(), rgxGen.getUniqueEstimation()
.orElse(null));
}

@Test
Expand All @@ -78,8 +80,8 @@ public void generateUniqueTest() {
public void classRgxGenTest() {
RgxGen rgxGen = new RgxGen(aTestPattern.getPattern());
if (aTestPattern.hasEstimatedCount()) {
assertEquals(aTestPattern.getEstimatedCount(), rgxGen.getUniqueEstimation()
.orElse(null));
assertEquals(aTestPattern.getLocation(), aTestPattern.getEstimatedCount(), rgxGen.getUniqueEstimation()
.orElse(null));
}
for (int i = 0; i < 100; i++) {
Random rand = TestingUtilities.newRandom(i);
Expand All @@ -105,7 +107,7 @@ public void classRgxGenCaseInsensitiveTest() {
for (int j = 0; j < 10; j++) {
String generated = rgxGen.generate(random);
boolean result = isValidGenerated(generated);
assertTrue(createMessage(generated, aTestPattern, i, j), result);
assertTrue(aTestPattern.getLocation() + createMessage(generated, aTestPattern, i, j), result);
}
}
}
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -296,11 +296,11 @@ public enum TestPattern implements DataInterface {
}},
//-----------------------------------------------------------------------------------------------------------------------------------------
POSITIVE_LOOKBEHIND_AFTER_1(".*(?<=foo)",
new Sequence(
".*(?<=foo)",
Repeat.minimum(".*", new SymbolSet(), 0),
new FinalSymbol("foo")
)
new Sequence(
".*(?<=foo)",
Repeat.minimum(".*", new SymbolSet(), 0),
new FinalSymbol("foo")
)
) {{
setUseFindForMatching();
}},
Expand Down Expand Up @@ -466,15 +466,26 @@ public enum TestPattern implements DataInterface {
boolean aIsUsableWithJavaPattern;
boolean aUseFindForMatching;
Validator aValidator;
String aEnumLocationInFile;

TestPattern(String pattern, Node resultNode) {
aPattern = pattern;
aResultNode = resultNode;
aEstimatedCount = TestingUtilities.BIG_INTEGER_MINUS_ONE;
aIsUsableWithJavaPattern = true;
aUseFindForMatching = false;
aEnumLocationInFile = name() + " at ." + formatLocation();
}

private final String formatLocation() {
StackTraceElement stackTraceElement = Thread.currentThread()
.getStackTrace()[4];

return '(' + stackTraceElement.getFileName() + ':' + stackTraceElement.getLineNumber() + ')';

}


public String getPattern() {
return aPattern;
}
Expand Down Expand Up @@ -556,4 +567,8 @@ public Optional<Validator> getValidator() {
public String toString() {
return aPattern;
}

public String getLocation() {
return aEnumLocationInFile;
}
}
Original file line number Diff line number Diff line change
Expand Up @@ -69,7 +69,7 @@ public void aLotOfValuesAvailableTest() {

for (int i = 0; i < ITERATIONS; i++) {
String next = stringIterator.next();
assertTrue(stringIterator.hasNext());
assertTrue(aRegex, stringIterator.hasNext());
if (aUseFind) {
assertTrue(next, p.matcher(next)
.find());
Expand Down

0 comments on commit c9e2917

Please sign in to comment.