Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

add tests #78

Merged
merged 4 commits into from
Mar 6, 2022
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
65 changes: 29 additions & 36 deletions evaluator/evaluator_test.go
Original file line number Diff line number Diff line change
Expand Up @@ -56,6 +56,9 @@ func TestEvalBooleanExpression(t *testing.T) {
{"3 <= 2", false},
{"2 >= 1", true},
{"2 >= 2", true},
{"2.0 >= 3.0", false},
{"3.0 >= 2.0", true},
{"3.0 <= 3.0", true},
{"2 >= 3", false},
{"1 == 1", true},
{"1 != 1", false},
Expand All @@ -81,6 +84,7 @@ func TestEvalBooleanExpression(t *testing.T) {
{"4 > 3 ? true : false", true},
{"3 > 4 ? false : true", true},
{"a = true ? (false ? 0 : true) : 0; a", true},
{"[1] + [1] == [1, 1]", true},
}

for _, tt := range tests {
Expand Down Expand Up @@ -191,6 +195,19 @@ func TestErrorHandling(t *testing.T) {
{"5 % 0", "division by zero not allowed"},
{"5 % 0 ? true : false", "division by zero not allowed"},
{"(4 > 5 ? true).nope()", "undefined method `.nope()` for NULL"},
{"if (5 % 0)\n puts(true)\nend", "division by zero not allowed"},
{"a = {(5%0): true}", "division by zero not allowed"},
{"a = {true: (5%0)}", "division by zero not allowed"},
{"def test() { puts(true) }; a = {test: true}", "unusable as hash key: FUNCTION"},
{"import(true)", "Import Error: invalid import path '&{%!s(bool=true)}'"},
{"import(5%0)", "division by zero not allowed"},
{`import("fixtures/nope")`, "Import Error: no module named 'fixtures/nope' found"},
{
`import("../fixtures/parser_error")`,
"Parse Error: [0:10: expected next token to be EOF, got EOF instead 0:10: expected next token to be EOF, got EOF instead]",
},
{"def test() { puts(true) }; test[1]", "index operator not supported: FUNCTION"},
{"[1] - [1]", "unknown operator: ARRAY - ARRAY"},
}

for _, tt := range tests {
Expand Down Expand Up @@ -297,42 +314,18 @@ func TestStringIndexExpressions(t *testing.T) {
input string
expected interface{}
}{
{
`"abc"[1]`,
"b",
},
{
`"abc"[-1]`,
"c",
},
{
`"abc"[4]`,
nil,
},
{
`"abc"[:2]`,
"ab",
},
{
`"abc"[:-2]`,
"a",
},
{
`"abc"[2:]`,
"c",
},
{
`"abc"[-2:]`,
"bc",
},
{
`s="abc";s[1]="B";s[1]`,
"B",
},
{
`s="abc";s[-2]="B";s[-2]`,
"B",
},
{`"abc"[1]`, "b"},
{`"abc"[-1]`, "c"},
{`"abc"[4]`, nil},
{`"abc"[:2]`, "ab"},
{`"abc"[:-2]`, "a"},
{`"abc"[2:]`, "c"},
{`"abc"[-2:]`, "bc"},
{`s="abc";s[1]="B";s[1]`, "B"},
{`s="abc";s[-2]="B";s[-2]`, "B"},
{`"test"[1]`, "e"},
{`"test"[-1]`, "t"},
{`"test"[7]`, nil},
}

for _, tt := range tests {
Expand Down
1 change: 1 addition & 0 deletions fixtures/parser_error.rl
Original file line number Diff line number Diff line change
@@ -0,0 +1 @@
def Test(