Skip to content

Commit

Permalink
Added some runtime-parsing regex tests
Browse files Browse the repository at this point in the history
  • Loading branch information
Knetic committed Jul 3, 2016
1 parent 4332817 commit b3f8214
Showing 1 changed file with 77 additions and 3 deletions.
80 changes: 77 additions & 3 deletions evaluationFailure_test.go
Original file line number Diff line number Diff line change
Expand Up @@ -19,6 +19,7 @@ type DebugStruct struct {
type EvaluationFailureTest struct {
Name string
Input string
Parameters map[string]interface{}
Expected string
}

Expand All @@ -28,6 +29,7 @@ const (
INVALID_LOGICALOP_TYPES = "cannot be used with the logical operator"
INVALID_TERNARY_TYPES = "cannot be used with the ternary operator"
ABSENT_PARAMETER = "No parameter"
INVALID_REGEX = "Unable to compile regexp pattern"
)

// preset parameter map of types that can be used in an evaluation failure test to check typing.
Expand Down Expand Up @@ -272,8 +274,50 @@ func TestComparatorTyping(test *testing.T) {
},
EvaluationFailureTest{

Name: "LTE number to string",
Input: "number <= string",
Name: "REQ number to string",
Input: "number =~ string",
Expected: INVALID_COMPARATOR_TYPES,
},
EvaluationFailureTest{

Name: "REQ number to bool",
Input: "number =~ bool",
Expected: INVALID_COMPARATOR_TYPES,
},
EvaluationFailureTest{

Name: "REQ bool to number",
Input: "bool =~ number",
Expected: INVALID_COMPARATOR_TYPES,
},
EvaluationFailureTest{

Name: "REQ bool to string",
Input: "bool =~ string",
Expected: INVALID_COMPARATOR_TYPES,
},
EvaluationFailureTest{

Name: "NREQ number to string",
Input: "number !~ string",
Expected: INVALID_COMPARATOR_TYPES,
},
EvaluationFailureTest{

Name: "NREQ number to bool",
Input: "number !~ bool",
Expected: INVALID_COMPARATOR_TYPES,
},
EvaluationFailureTest{

Name: "NREQ bool to number",
Input: "bool !~ number",
Expected: INVALID_COMPARATOR_TYPES,
},
EvaluationFailureTest{

Name: "NREQ bool to string",
Input: "bool !~ string",
Expected: INVALID_COMPARATOR_TYPES,
},
}
Expand Down Expand Up @@ -301,6 +345,32 @@ func TestTernaryTyping(test *testing.T) {
runEvaluationFailureTests(evaluationTests, test)
}

func TestRegexParameterCompilation(test *testing.T) {

evaluationTests := []EvaluationFailureTest{
EvaluationFailureTest{

Name: "Regex equality runtime parsing",
Input: "'foo' =~ foo",
Parameters: map[string]interface{} {
"foo": "[foo",
},
Expected: INVALID_REGEX,
},
EvaluationFailureTest{

Name: "Regex inequality runtime parsing",
Input: "'foo' =~ foo",
Parameters: map[string]interface{} {
"foo": "[foo",
},
Expected: INVALID_REGEX,
},
}

runEvaluationFailureTests(evaluationTests, test)
}

func runEvaluationFailureTests(evaluationTests []EvaluationFailureTest, test *testing.T) {

var expression *EvaluableExpression
Expand All @@ -320,7 +390,11 @@ func runEvaluationFailureTests(evaluationTests []EvaluationFailureTest, test *te
continue
}

_, err = expression.Evaluate(EVALUATION_FAILURE_PARAMETERS)
if(testCase.Parameters == nil) {
testCase.Parameters = EVALUATION_FAILURE_PARAMETERS
}

_, err = expression.Evaluate(testCase.Parameters)

if err == nil {

Expand Down

0 comments on commit b3f8214

Please sign in to comment.