diff --git a/tests/ast/ast.odin b/tests/ast/ast.odin index 2fab00c..f322cec 100644 --- a/tests/ast/ast.odin +++ b/tests/ast/ast.odin @@ -98,25 +98,28 @@ return_statement :: proc(t: ^testing.T) { } @(test) -return_without_integer :: proc(t: ^testing.T) { - tokens := []token.Token{{type = .Return}, {type = .Semicolon}} - program, errors := ast.parse(tokens) - defer free_all() - - testing.expect_value(t, len(program.statements), 0) - testing.expect_value(t, len(errors), 1) - testing.expect_value(t, errors[0], "expected Integer, but got Semicolon") -} - -@(test) -return_without_semicolon :: proc(t: ^testing.T) { - tokens := []token.Token{{type = .Return}, {type = .Integer, literal = "5"}} - program, errors := ast.parse(tokens) +return_statement_error :: proc(t: ^testing.T) { + tests := map[string]struct { + input: [dynamic]token.Token, + output: string, + } { + "missing integer" = { + input = [dynamic]token.Token{{type = .Return}, {type = .Semicolon}}, + output = "expected Integer, but got Semicolon", + }, + "missing semicolon" = { + input = [dynamic]token.Token{{type = .Return}, {type = .Integer, literal = "0"}}, + output = "expected Semicolon, but got Illegal", + }, + } defer free_all() - testing.expect_value(t, len(program.statements), 0) - testing.expect_value(t, len(errors), 1) - testing.expect_value(t, errors[0], "expected Semicolon, but got Illegal") + for name, data in tests { + program, errors := ast.parse(data.input[:]) + expect.value(t, name, len(program.statements), 0) + expect.value(t, name, len(errors), 1) + expect.value(t, name, string(errors[0]), data.output) + } } @(test)