Skip to content

Commit

Permalink
#63. Negative Lookahead Error
Browse files Browse the repository at this point in the history
More tests
  • Loading branch information
curious-odd-man committed Feb 13, 2021
1 parent 6117542 commit 621ee53
Showing 1 changed file with 51 additions and 19 deletions.
70 changes: 51 additions & 19 deletions src/test/java/com/github/curiousoddman/rgxgen/data/TestPattern.java
Original file line number Diff line number Diff line change
Expand Up @@ -6,7 +6,6 @@
import java.math.BigInteger;
import java.util.*;
import java.util.stream.Collectors;
import java.util.stream.IntStream;
import java.util.stream.Stream;

import static com.github.curiousoddman.rgxgen.testutil.TestingUtilities.getAllDigits;
Expand Down Expand Up @@ -214,26 +213,56 @@ public enum TestPattern implements DataInterface {
setInfinite();
}},
//-----------------------------------------------------------------------------------------------------------------------------------------
POSITIVE_LOOKAHEAD("foo(?=bar)",
new Sequence("foo(?=bar)",
new FinalSymbol("foo"), new FinalSymbol("bar"))
),
POSITIVE_LOOKAHEAD_AFTER("foo(?=bar)",
new Sequence("foo(?=bar)",
new FinalSymbol("foo"), new FinalSymbol("bar"))
) {{
setUseFindForMatching();
}},
//-----------------------------------------------------------------------------------------------------------------------------------------
// FIXME: Same as "bar.*"
POSITIVE_LOOKAHEAD_BEFORE("(?=bar).*", new FinalSymbol("NOT IMPLEMENTED")) {{
setUseFindForMatching();
}},
//-----------------------------------------------------------------------------------------------------------------------------------------
NEGATIVE_LOOKAHEAD("foo(?!bar)",
new Sequence("foo(?!bar)",
new FinalSymbol("foo"), new NotSymbol("bar", new FinalSymbol("bar")))) {{
NEGATIVE_LOOKAHEAD_AFTER("foo(?!bar)",
new Sequence("foo(?!bar)",
new FinalSymbol("foo"), new NotSymbol("bar", new FinalSymbol("bar")))) {{
setInfinite();
setUseFindForMatching();
}},
//-----------------------------------------------------------------------------------------------------------------------------------------
POSITIVE_LOOKBEHIND("(?<=foo)bar",
new Sequence("(?<=foo)bar",
new FinalSymbol("foo"), new FinalSymbol("bar"))
),
// FIXME: Same as "A".
NEGATIVE_LOOKAHEAD_BEFORE("(?!B)[AB]",
new FinalSymbol("NOT IMPLEMENTED")) {{
setUseFindForMatching();
}},
//-----------------------------------------------------------------------------------------------------------------------------------------
// FIXME: Same as "foo"
POSITIVE_LOOKBEHIND_AFTER("fo[od](?<=foo)",
new FinalSymbol("NOT IMPLEMENTED")) {{
setUseFindForMatching();
}},
//-----------------------------------------------------------------------------------------------------------------------------------------
NEGATIVE_LOOKBEHIND("(?<!not)foo",
new Sequence("(?<!not)foo",
new NotSymbol("not", new FinalSymbol("not")), new FinalSymbol("foo"))) {{
POSITIVE_LOOKBEHIND_BEFORE("(?<!not)foo",
new Sequence("(?<!not)foo",
new NotSymbol("not", new FinalSymbol("not")), new FinalSymbol("foo"))) {{
setInfinite();
setUseFindForMatching();
}},
//-----------------------------------------------------------------------------------------------------------------------------------------
// FIXME: Same as .*foo
NEGATIVE_LOOKBEHIND_AFTER(".*(?<=foo)",
new FinalSymbol("NOT IMPLEMENTED")
) {{
setUseFindForMatching();
}},
//-----------------------------------------------------------------------------------------------------------------------------------------
NEGATIVE_LOOKBEHIND_BEFORE("(?<!not)foo",
new Sequence("(?<!not)foo",
new NotSymbol("not", new FinalSymbol("not")), new FinalSymbol("foo"))) {{
setInfinite();
setUseFindForMatching();
}},
//-----------------------------------------------------------------------------------------------------------------------------------------
CHOICE_CAPTURED("(a|b)\\1",
Expand Down Expand Up @@ -387,12 +416,14 @@ public enum TestPattern implements DataInterface {
BigInteger aEstimatedCount;
List<String> aAllUniqueValues;
boolean aIsUsableWithJavaPattern;
boolean aUseFindForMatching;

TestPattern(String pattern, Node resultNode) {
aPattern = pattern;
aResultNode = resultNode;
aEstimatedCount = TestingUtilities.BIG_INTEGER_MINUS_ONE;
aIsUsableWithJavaPattern = true;
aUseFindForMatching = false;
}

public String getPattern() {
Expand Down Expand Up @@ -437,16 +468,17 @@ public boolean hasAllUniqueValues() {
}

public boolean useFindForMatching() {
return this == POSITIVE_LOOKAHEAD
|| this == NEGATIVE_LOOKAHEAD
|| this == POSITIVE_LOOKBEHIND
|| this == NEGATIVE_LOOKBEHIND;
return aUseFindForMatching;
}

public boolean isUsableWithJavaPattern() {
return aIsUsableWithJavaPattern;
}

protected final void setUseFindForMatching() {
aUseFindForMatching = true;
}

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

0 comments on commit 621ee53

Please sign in to comment.