Skip to content

Commit

Permalink
#63. Negative Lookahead Error
Browse files Browse the repository at this point in the history
Fixing some tests.
  • Loading branch information
curious-odd-man committed Aug 29, 2021
1 parent 1370091 commit db30529
Show file tree
Hide file tree
Showing 2 changed files with 37 additions and 8 deletions.
Original file line number Diff line number Diff line change
Expand Up @@ -31,13 +31,11 @@ public static Collection<Object[]> data() {

@Test
public void generateTest() {
GenerationVisitor generationVisitor = GenerationVisitor.builder()
.withRandom(TestingUtilities.newRandom(aSeed))
.get();
aTestPattern.getResultNode()
.visit(generationVisitor);
boolean result = isValidGenerated(generationVisitor.getString());
assertTrue("Text: '" + generationVisitor.getString() + "'does not match pattern " + aTestPattern.getPattern(), result);
RgxGen rgxGen = aTestPattern.getRgxGen();
String text = rgxGen.generate(TestingUtilities.newRandom(aSeed));

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

@Test
Expand Down
Original file line number Diff line number Diff line change
@@ -1,7 +1,11 @@
package com.github.curiousoddman.rgxgen.data;

import com.github.curiousoddman.rgxgen.RgxGen;
import com.github.curiousoddman.rgxgen.nodes.*;
import com.github.curiousoddman.rgxgen.parsing.NodeTreeBuilder;
import com.github.curiousoddman.rgxgen.testutil.TestingUtilities;
import com.github.curiousoddman.rgxgen.validation.FullPatternValidator;
import com.github.curiousoddman.rgxgen.validation.Validator;

import java.math.BigInteger;
import java.util.*;
Expand Down Expand Up @@ -227,7 +231,7 @@ public enum TestPattern implements DataInterface {
POSITIVE_LOOKAHEAD_BEFORE_NOT_INFINITE("(?=bar).*car",
new Sequence("(?=bar).*car",
new FinalSymbol("bar"),
new Repeat(".*", new SymbolSet(), 0),
Repeat.minimum(".*", new SymbolSet(), 0),
new FinalSymbol("car"))) {{
setUseFindForMatching();
}},
Expand All @@ -243,6 +247,7 @@ public enum TestPattern implements DataInterface {
NEGATIVE_LOOKAHEAD_BEFORE("(?!B)[AB]",
new SymbolSet("[AB]", new Character[]{'A', 'B'}, SymbolSet.TYPE.POSITIVE)) {{
setUseFindForMatching();
setValidated();
}},
//-----------------------------------------------------------------------------------------------------------------------------------------
NEGATIVE_LOOKAHEAD_BEFORE_SPANS_TWO_NODES("(?!BB)[AB][AB]",
Expand All @@ -253,6 +258,7 @@ public enum TestPattern implements DataInterface {
)
) {{
setUseFindForMatching();
setValidated();
}},
//-----------------------------------------------------------------------------------------------------------------------------------------
POSITIVE_LOOKBEHIND_AFTER("fo[od](?<=foo)",
Expand Down Expand Up @@ -442,6 +448,7 @@ public enum TestPattern implements DataInterface {
List<String> aAllUniqueValues;
boolean aIsUsableWithJavaPattern;
boolean aUseFindForMatching;
Validator aValidator;

TestPattern(String pattern, Node resultNode) {
aPattern = pattern;
Expand Down Expand Up @@ -504,6 +511,30 @@ protected final void setUseFindForMatching() {
aUseFindForMatching = true;
}

protected final void setValidated() {
setValidator(new FullPatternValidator(aPattern));
}

protected final void setValidator(Validator validator) {
aValidator = validator;
}

public RgxGen getRgxGen() {
return new RgxGen(
new NodeTreeBuilder() {
@Override
public Node get() {
return aResultNode;
}

@Override
public Optional<Validator> getValidator() {
return Optional.ofNullable(aValidator);
}
}
);
}

@Override
public String toString() {
return aPattern;
Expand Down

0 comments on commit db30529

Please sign in to comment.