diff --git a/syntax/std_seq_contains_test.go b/syntax/std_seq_contains_test.go index 6a2a7807..1ce8b86d 100644 --- a/syntax/std_seq_contains_test.go +++ b/syntax/std_seq_contains_test.go @@ -16,7 +16,7 @@ func TestStrContains(t *testing.T) { AssertCodesEvalToSameValue(t, `false`, `//seq.contains("A", "")`) AssertCodesEvalToSameValue(t, `true`, `//seq.contains("", "")`) - assertExprPanics(t, `//seq.contains(1, "ABC")`) + AssertCodeErrors(t, `//seq.contains(1, "ABC")`, "") } func TestArrayContains(t *testing.T) { //nolint:dupl @@ -45,8 +45,8 @@ func TestArrayContains(t *testing.T) { //nolint:dupl AssertCodesEvalToSameValue(t, `true`, `//seq.contains([], [1])`) AssertCodesEvalToSameValue(t, `true`, `//seq.contains([], [])`) - assertExprPanics(t, `//seq.contains(1, [1,2,3,4,5])`) - assertExprPanics(t, `//seq.contains('A',['A','B','C','D','E'])`) + AssertCodeErrors(t, `//seq.contains(1, [1,2,3,4,5])`, "") + AssertCodeErrors(t, `//seq.contains('A',['A','B','C','D','E'])`, "") } func TestBytesContains(t *testing.T) { diff --git a/syntax/std_seq_join_test.go b/syntax/std_seq_join_test.go index aba7909a..51a8ac0c 100644 --- a/syntax/std_seq_join_test.go +++ b/syntax/std_seq_join_test.go @@ -19,7 +19,7 @@ func TestStrJoin(t *testing.T) { // It is not supported // AssertCodesEvalToSameValue(t, `""`, `//seq.join("",[])`) - assertExprPanics(t, `//seq.join("this", 2)`) + AssertCodeErrors(t, `//seq.join("this", 2)`, "") } func TestArrayJoin(t *testing.T) { @@ -51,12 +51,12 @@ func TestArrayJoin(t *testing.T) { AssertCodesEvalToSameValue(t, `[[1, 2], 3, 4]`, `//seq.join([], [[[1, 2]], [3, 4]])`) AssertCodesEvalToSameValue(t, `[[1, 2], [3, 4], 5]`, `//seq.join([], [[[1, 2]], [[3,4], 5]])`) - assertExprPanics(t, `//seq.join(1, [1,2,3,4,5])`) - assertExprPanics(t, `//seq.join('A', [1,2])`) - assertExprPanics(t, `//seq.join([],[1,2])`) - assertExprPanics(t, `//seq.join([1],[1,2])`) - assertExprPanics(t, `//seq.join([0], [1,2,3,4,5])`) - assertExprPanics(t, `//seq.join(['A'], ['AT','BB', 'CD'])`) + AssertCodeErrors(t, `//seq.join(1, [1,2,3,4,5])`, "") + AssertCodeErrors(t, `//seq.join('A', [1,2])`, "") + AssertCodeErrors(t, `//seq.join([],[1,2])`, "") + AssertCodeErrors(t, `//seq.join([1],[1,2])`, "") + AssertCodeErrors(t, `//seq.join([0], [1,2,3,4,5])`, "") + AssertCodeErrors(t, `//seq.join(['A'], ['AT','BB', 'CD'])`, "") } func TestBytesJoin(t *testing.T) { diff --git a/syntax/std_seq_prefix_test.go b/syntax/std_seq_prefix_test.go index 57caca0a..dd4395d5 100644 --- a/syntax/std_seq_prefix_test.go +++ b/syntax/std_seq_prefix_test.go @@ -17,7 +17,7 @@ func TestStrPrefix(t *testing.T) { AssertCodesEvalToSameValue(t, `false`, `//seq.has_prefix("A","")`) AssertCodesEvalToSameValue(t, `true`, `//seq.has_prefix("","A")`) - assertExprPanics(t, `//seq.has_prefix(1,"ABC")`) + AssertCodeErrors(t, `//seq.has_prefix(1,"ABC")`, "") } func TestArrayPrefix(t *testing.T) { @@ -41,8 +41,8 @@ func TestArrayPrefix(t *testing.T) { AssertCodesEvalToSameValue(t, `false`, `//seq.has_prefix(['A','B','C','D','E','F'],[])`) AssertCodesEvalToSameValue(t, `true`, `//seq.has_prefix([],['A','B','C','D','E'])`) - assertExprPanics(t, `//seq.has_prefix(1,[1,2,3])`) - assertExprPanics(t, `//seq.has_prefix('A',['A','B','C'])`) + AssertCodeErrors(t, `//seq.has_prefix(1,[1,2,3])`, "") + AssertCodeErrors(t, `//seq.has_prefix('A',['A','B','C'])`, "") } func TestBytesPrefix(t *testing.T) { diff --git a/syntax/std_seq_split_test.go b/syntax/std_seq_split_test.go index e22a144e..42b94684 100644 --- a/syntax/std_seq_split_test.go +++ b/syntax/std_seq_split_test.go @@ -11,7 +11,7 @@ func TestStrSplit(t *testing.T) { AssertCodesEvalToSameValue(t, `["this", "is", "a", "test"]`, `//seq.split(" ","this is a test") `) AssertCodesEvalToSameValue(t, `["this is a test"] `, `//seq.split(",","this is a test") `) AssertCodesEvalToSameValue(t, `["th", " ", " a test"] `, `//seq.split("is","this is a test")`) - assertExprPanics(t, `//seq.split(1, "this is a test")`) + AssertCodeErrors(t, `//seq.split(1, "this is a test")`, "") AssertCodesEvalToSameValue(t, `["t", "h", "i", "s", " ", "i", "s", " ", "a", " ", "t", "e", "s", "t"]`, @@ -24,7 +24,7 @@ func TestStrSplit(t *testing.T) { AssertCodesEvalToSameValue(t, `[""]`, `//seq.split(",","") `) - assertExprPanics(t, `//seq.split(1,"ABC")`) + AssertCodeErrors(t, `//seq.split(1,"ABC")`, "") } func TestArraySplit(t *testing.T) { //nolint:dupl @@ -63,8 +63,8 @@ func TestArraySplit(t *testing.T) { //nolint:dupl AssertCodesEvalToSameValue(t, `[]`, `//seq.split([],[])`) AssertCodesEvalToSameValue(t, `[[]]`, `//seq.split(['A'],[])`) - assertExprPanics(t, `//seq.split(1,[1,2,3])`) - assertExprPanics(t, `//seq.split('A',['A','B'])`) + AssertCodeErrors(t, `//seq.split(1,[1,2,3])`, "") + AssertCodeErrors(t, `//seq.split('A',['A','B'])`, "") } func TestBytesSplit(t *testing.T) { diff --git a/syntax/std_seq_sub_test.go b/syntax/std_seq_sub_test.go index 53df3344..9107d111 100644 --- a/syntax/std_seq_sub_test.go +++ b/syntax/std_seq_sub_test.go @@ -11,7 +11,7 @@ func TestStrSub(t *testing.T) { AssertCodesEvalToSameValue(t, `"t1his is not1 a t1est1"`, `//seq.sub("t", "t1","this is not a test")`) AssertCodesEvalToSameValue(t, `"this is still a test"`, `//seq.sub( "doesn't matter", "hello there","this is still a test")`) - assertExprPanics(t, `//seq.sub("hello there", "test", 1)`) + AssertCodeErrors(t, `//seq.sub("hello there", "test", 1)`, "") ///////////////// AssertCodesEvalToSameValue(t, `""`, `//seq.sub( "","", "")`) AssertCodesEvalToSameValue(t, `"A"`, `//seq.sub( "","A", "")`) @@ -20,7 +20,7 @@ func TestStrSub(t *testing.T) { AssertCodesEvalToSameValue(t, `"EAEBECE"`, `//seq.sub( "", "E","ABC")`) AssertCodesEvalToSameValue(t, `"BC"`, `//seq.sub( "A", "","ABC")`) - assertExprPanics(t, `//seq.sub(1,'B','BCD')`) + AssertCodeErrors(t, `//seq.sub(1,'B','BCD')`, "") } func TestArraySub(t *testing.T) { @@ -32,8 +32,8 @@ func TestArraySub(t *testing.T) { AssertCodesEvalToSameValue(t, `[2, 2, 3]`, `//seq.sub([1], [2], [1, 2, 3])`) AssertCodesEvalToSameValue(t, `[[1,1], [4,4], [3,3]]`, `//seq.sub([[2,2]], [[4,4]], [[1,1], [2,2], [3,3]])`) - assertExprPanics(t, `//seq.sub(1,'B',[1,2,3])`) - assertExprPanics(t, `//seq.sub(1,'B',['A','B','C'])`) + AssertCodeErrors(t, `//seq.sub(1,'B',[1,2,3])`, "") + AssertCodeErrors(t, `//seq.sub(1,'B',['A','B','C'])`, "") } func TestArraySubEdgeCases(t *testing.T) { diff --git a/syntax/std_seq_suffix_test.go b/syntax/std_seq_suffix_test.go index 6775ef31..dc1b4a44 100644 --- a/syntax/std_seq_suffix_test.go +++ b/syntax/std_seq_suffix_test.go @@ -15,7 +15,7 @@ func TestStrSuffix(t *testing.T) { AssertCodesEvalToSameValue(t, `true`, `//seq.has_suffix("","")`) AssertCodesEvalToSameValue(t, `true`, `//seq.has_suffix("","ABCDE")`) - assertExprPanics(t, `//seq.has_suffix(1,"ABC")`) + AssertCodeErrors(t, `//seq.has_suffix(1,"ABC")`, "") } func TestArraySuffix(t *testing.T) { @@ -39,8 +39,8 @@ func TestArraySuffix(t *testing.T) { AssertCodesEvalToSameValue(t, `true`, `//seq.has_suffix([], [])`) AssertCodesEvalToSameValue(t, `false`, `//seq.has_suffix(['D','E'],[])`) - assertExprPanics(t, `//seq.has_suffix(1,[1,2])`) - assertExprPanics(t, `//seq.has_suffix('A',['A','B'])`) + AssertCodeErrors(t, `//seq.has_suffix(1,[1,2])`, "") + AssertCodeErrors(t, `//seq.has_suffix('A',['A','B'])`, "") } func TestBytesSuffix(t *testing.T) { diff --git a/syntax/std_str_test.go b/syntax/std_str_test.go index 36cf5e20..eb39fcd7 100644 --- a/syntax/std_str_test.go +++ b/syntax/std_str_test.go @@ -2,8 +2,6 @@ package syntax import ( "testing" - - "github.com/stretchr/testify/assert" ) func TestStrLower(t *testing.T) { @@ -32,7 +30,3 @@ func TestStrTitle(t *testing.T) { AssertCodesEvalToSameValue(t, `"This Is A Test"`, `//str.title("this is a test")`) AssertCodeErrors(t, `//str.title(123)`, "") } - -func assertExprPanics(t *testing.T, code string) { - assert.Panics(t, func() { AssertCodesEvalToSameValue(t, `"doesn't matter"`, code) }) -} diff --git a/syntax/test_helpers.go b/syntax/test_helpers.go index ae051fc7..f44f9eb9 100644 --- a/syntax/test_helpers.go +++ b/syntax/test_helpers.go @@ -2,6 +2,7 @@ package syntax import ( "errors" + "fmt" "testing" "github.com/arr-ai/arrai/rel" @@ -84,6 +85,9 @@ func AssertCodeErrors(t *testing.T, code, errString string) bool { if assert.NoError(t, err, "parsing code: %s", code) { codeExpr := pc.CompileExpr(ast) _, err := codeExpr.Eval(rel.EmptyScope) + if err == nil { + panic(fmt.Sprintf("the code `%s` didn't generate any error", code)) + } assert.EqualError(t, errors.New(err.Error()[:len(errString)]), errString) } return false