Skip to content

Commit

Permalink
match("foo") throws an ugly exception
Browse files Browse the repository at this point in the history
  • Loading branch information
gombasg committed Mar 10, 2020
1 parent 2724470 commit cecaa99
Show file tree
Hide file tree
Showing 3 changed files with 17 additions and 3 deletions.
6 changes: 3 additions & 3 deletions panc/src/main/java/org/quattor/pan/dml/functions/Match.java
Original file line number Diff line number Diff line change
Expand Up @@ -53,9 +53,9 @@ public static Operation getInstance(SourceRange sourceRange,

// Optimize the operation if compile time constants are given for the
// regular expression and match flags.
if (operations.length > 0
&& operations[1] instanceof StringProperty
&& (operations.length < 3 || operations[2] instanceof StringProperty)) {
if (operations.length == 2
&& operations[0] instanceof StringProperty
&& operations[1] instanceof StringProperty) {
return StaticMatch.getInstance(sourceRange, operations);
} else {
return new Match(sourceRange, operations);
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -100,6 +100,11 @@ public void invalidCallWithNoArguments() throws SyntaxException {
Match.getInstance(null);
}

@Test(expected = SyntaxException.class)
public void invalidCallWithOneArgument() throws SyntaxException {
Match.getInstance(null, StringProperty.getInstance("a"));
}

@Test(expected = SyntaxException.class)
public void invalidCallWithTooManyArguments() throws SyntaxException {
Match.getInstance(null, StringProperty.getInstance("a"), StringProperty
Expand Down
9 changes: 9 additions & 0 deletions panc/src/test/pan/Functionality/regexp/regexp4.pan
Original file line number Diff line number Diff line change
@@ -0,0 +1,9 @@
#
# too few args should give a nice error message
#
# @expect=org.quattor.pan.exceptions.SyntaxException
#

object template regexp4;

"/bug" = match("12323");

0 comments on commit cecaa99

Please sign in to comment.