diff --git a/Taskfile.dist.yml b/Taskfile.dist.yml new file mode 100644 index 0000000..615c907 --- /dev/null +++ b/Taskfile.dist.yml @@ -0,0 +1,46 @@ +# yaml-language-server: $schema=https://taskfile.dev/schema.json + +version: '3' + +tasks: + run: + cmds: + - task: run:debug + run:debug: + cmds: + - odin run . -debug + run:release: + cmds: + - odin run . -o:speed + build: + cmds: + - task: build:debug + build:debug: + cmds: + - odin build . -debug + build:release: + cmds: + - odin build . -o:speed + test: + desc: Test all packages. + cmds: + - task: test:lexer + - task: test:parser + - task: test:ast + - task: test:evaluator + test:lexer: + desc: + cmds: + - odin test lexer -debug + test:parser: + desc: + cmds: + - odin test parser -debug + test:ast: + desc: + cmds: + - odin test ast -debug + test:evaluator: + desc: + cmds: + - odin test evaluator -debug diff --git a/ast/ast.odin b/ast/ast.odin index b82469c..79da8cf 100644 --- a/ast/ast.odin +++ b/ast/ast.odin @@ -1,9 +1,7 @@ package ast +import "base:intrinsics" import "core:bytes" -import "core:fmt" -import "core:intrinsics" -import "core:mem" import "core:strings" import "../lexer" @@ -654,7 +652,7 @@ call_expr_to_string :: proc(e: ^Call_Expr) -> bytes.Buffer { bufs: [dynamic]bytes.Buffer defer { - for buf in &bufs { + for &buf in &bufs { bytes.buffer_destroy(&buf) } delete(bufs) @@ -672,7 +670,7 @@ call_expr_to_string :: proc(e: ^Call_Expr) -> bytes.Buffer { string_array: [dynamic]string defer delete(string_array) - for b in &bufs { + for &b in &bufs { append(&string_array, bytes.buffer_to_string(&b)) } s := strings.join(string_array[:], ", ") @@ -697,7 +695,7 @@ array_literal_to_string :: proc(e: ^Array_Literal) -> bytes.Buffer { bufs: [dynamic]bytes.Buffer defer { - for buf in &bufs { + for &buf in &bufs { bytes.buffer_destroy(&buf) } delete(bufs) @@ -711,7 +709,7 @@ array_literal_to_string :: proc(e: ^Array_Literal) -> bytes.Buffer { string_array: [dynamic]string defer delete(string_array) - for b in &bufs { + for &b in &bufs { append(&string_array, bytes.buffer_to_string(&b)) } s := strings.join(string_array[:], ", ") diff --git a/ast/ast_test.odin b/ast/ast_test.odin index 3cadf7c..6e4bdd5 100644 --- a/ast/ast_test.odin +++ b/ast/ast_test.odin @@ -1,3 +1,4 @@ +#+feature dynamic-literals package ast import "core:bytes" @@ -46,7 +47,7 @@ test_to_string :: proc(t: ^testing.T) { s := bytes.buffer_to_string(&buf) if s != "let myVar = anotherVar;" { - testing.errorf(t, "to_string(program) wrong. got=%q", s) + testing.expectf(t, true, "to_string(program) wrong. got=%q", s) } } diff --git a/evaluator/builtins.odin b/evaluator/builtins.odin index 55f4b64..6a006dd 100644 --- a/evaluator/builtins.odin +++ b/evaluator/builtins.odin @@ -1,3 +1,4 @@ +#+feature dynamic-literals global-context package evaluator import "core:fmt" @@ -6,8 +7,10 @@ import "../evaluator" import "../object" allocated_array: [dynamic][dynamic]^object.Object + builtins := init_builtin_functions() + init_builtin_functions :: proc() -> map[string]^object.Builtin { bfs := map[string]object.BuiltinFunction { "len" = builtin_function_len, diff --git a/evaluator/evaluator.odin b/evaluator/evaluator.odin index 27ee218..dc5fad8 100644 --- a/evaluator/evaluator.odin +++ b/evaluator/evaluator.odin @@ -195,7 +195,7 @@ delete_eval :: proc() { } delete(env_array) - for buffer in &object.buffer_array { + for &buffer in &object.buffer_array { bytes.buffer_destroy(&buffer) } delete(object.buffer_array) diff --git a/evaluator/evaluator_test.odin b/evaluator/evaluator_test.odin index cbc4452..9623ba2 100644 --- a/evaluator/evaluator_test.odin +++ b/evaluator/evaluator_test.odin @@ -1,3 +1,4 @@ +#+feature dynamic-literals package evaluator import "core:bytes" @@ -43,11 +44,11 @@ test_eval :: proc(input: string) -> ^object.Object { test_integer_object :: proc(t: ^testing.T, obj: ^object.Object, expected: i64) -> bool { result, ok := obj.derived.(^object.Integer) if !ok { - testing.errorf(t, "object is not Integer. got=%T (%v)", obj, obj.derived) + testing.expectf(t, true, "object is not Integer. got=%T (%v)", obj, obj.derived) return false } if result.value != expected { - testing.errorf(t, "object has wrong value. got=%d, want=%d", result.value, expected) + testing.expectf(t, true, "object has wrong value. got=%d, want=%d", result.value, expected) return false } return true @@ -56,11 +57,11 @@ test_integer_object :: proc(t: ^testing.T, obj: ^object.Object, expected: i64) - test_boolean_object :: proc(t: ^testing.T, obj: ^object.Object, expected: bool) -> bool { result, ok := obj.derived.(^object.Boolean) if !ok { - testing.errorf(t, "object is not Boolean. got=%T (%v)", obj, obj.derived) + testing.expectf(t, true, "object is not Boolean. got=%T (%v)", obj, obj.derived) return false } if result.value != expected { - testing.errorf(t, "object has wrong value. got=%t, want=%t", result.value, expected) + testing.expectf(t, true, "object has wrong value. got=%t, want=%t", result.value, expected) return false } return true @@ -68,7 +69,7 @@ test_boolean_object :: proc(t: ^testing.T, obj: ^object.Object, expected: bool) test_null_object :: proc(t: ^testing.T, obj: ^object.Object) -> bool { if obj != NULL { - testing.errorf(t, "object is not NULL. got=%T (%v)", obj, obj.derived) + testing.expectf(t, true, "object is not NULL. got=%T (%v)", obj, obj.derived) return false } return true @@ -217,7 +218,7 @@ test_error_handling :: proc(t: ^testing.T) { {"true + false;", "unknown operator: BOOLEAN + BOOLEAN"}, {"5; true + false; 5", "unknown operator: BOOLEAN + BOOLEAN"}, {"if (10 > 1) { true + false; }", "unknown operator: BOOLEAN + BOOLEAN"}, - { + { ` if (10 > 1) { if (10 > 1) { @@ -239,8 +240,9 @@ test_error_handling :: proc(t: ^testing.T) { err_obj, ok := evaluated.derived.(^object.Error) if !ok { - testing.errorf( + testing.expectf( t, + true, "no error object returned. got=%T (%v)", evaluated, evaluated.derived, @@ -249,8 +251,9 @@ test_error_handling :: proc(t: ^testing.T) { } if err_obj.message != tt.expected_msg { - testing.errorf( + testing.expectf( t, + true, "wrong error message. expected=%q, got=%q", tt.expected_msg, err_obj.message, @@ -390,7 +393,7 @@ test_string_complex_cases :: proc(t: ^testing.T) { input: string, expected: string, } { - { + { ` let a = "A"; let b = "B"; @@ -400,7 +403,7 @@ test_string_complex_cases :: proc(t: ^testing.T) { `, "A B", }, - { + { ` let makeGreeter = fn(greeting) { fn(name) { greeting + " " + name + "!" } }; let hello = makeGreeter("Hello"); @@ -445,11 +448,18 @@ test_builtin_functions :: proc(t: ^testing.T) { case string: err_obj, ok := evaluated.derived.(^object.Error) if !ok { - testing.errorf(t, "object is not Error. got=%T (%v)", evaluated, evaluated.derived) + testing.expectf( + t, + true, + "object is not Error. got=%T (%v)", + evaluated, + evaluated.derived, + ) } if err_obj.message != expected { - testing.errorf( + testing.expectf( t, + true, "wrong error message. expected=%q, got=%q", expected, err_obj.message, @@ -510,7 +520,7 @@ test_array_complex_cases :: proc(t: ^testing.T) { input: string, expected: Types3, } { - { + { ` let map = fn(arr, f) { let iter = fn(arr, accumulated) { @@ -529,7 +539,7 @@ test_array_complex_cases :: proc(t: ^testing.T) { `, [4]i64{2, 4, 6, 8}, }, - { + { ` let reduce = fn(arr, initial, f) { let iter = fn(arr, result) { @@ -583,13 +593,13 @@ test_string_hash_key :: proc(t: ^testing.T) { diff2.value = "My name is johnny" if object.hash_key(hello1) != object.hash_key(hello2) { - testing.errorf(t, "strings with same content have different hash keys") + testing.expectf(t, true, "strings with same content have different hash keys") } if object.hash_key(diff1) != object.hash_key(diff2) { - testing.errorf(t, "strings with same content have different hash keys") + testing.expectf(t, true, "strings with same content have different hash keys") } if object.hash_key(hello1) == object.hash_key(diff1) { - testing.errorf(t, "strings with different content have same hash keys") + testing.expectf(t, true, "strings with different content have same hash keys") } } @@ -652,7 +662,7 @@ test_hash_literals :: proc(t: ^testing.T) { for expected_key, expected_value in expected { pair, ok := result.pairs[expected_key] if !ok { - testing.errorf(t, "no pair for given key in Pairs") + testing.expectf(t, true, "no pair for given key in Pairs") } test_integer_object(t, pair.value, expected_value) diff --git a/lexer/lexer.odin b/lexer/lexer.odin index 86bd673..2be8369 100644 --- a/lexer/lexer.odin +++ b/lexer/lexer.odin @@ -1,6 +1,6 @@ +#+feature dynamic-literals package lexer -import "core:fmt" ILLEGAL :: "ILLEGAL" EOF :: "EOF" diff --git a/object/environment.odin b/object/environment.odin index 2c60bdd..a1f95dc 100644 --- a/object/environment.odin +++ b/object/environment.odin @@ -1,6 +1,5 @@ package object -import "core:fmt" Environment :: struct { store: map[string]^Object, diff --git a/object/object.odin b/object/object.odin index 134be76..d99a32c 100644 --- a/object/object.odin +++ b/object/object.odin @@ -1,9 +1,9 @@ package object +import "base:intrinsics" import "core:bytes" import "core:fmt" import "core:hash" -import "core:intrinsics" import "core:strings" import "../ast" diff --git a/ols.json b/ols.json new file mode 100644 index 0000000..3a646f6 --- /dev/null +++ b/ols.json @@ -0,0 +1,17 @@ +{ + "$schema": "https://raw.githubusercontent.com/DanielGavin/ols/master/misc/ols.schema.json", + "collections": [ + { "name": "custom_collection", "path": "c:/path/to/collection" } + ], + "enable_semantic_tokens": false, + "enable_document_symbols": true, + "enable_hover": true, + "enable_snippets": true, + "profile": "default", + "profiles": [ + { "name": "default", "checker_path": ["src"], "defines": { "ODIN_DEBUG": "false" }}, + { "name": "linux_profile", "os": "linux", "checker_path": ["src/main.odin"], "defines": { "ODIN_DEBUG": "false" }}, + { "name": "mac_profile", "os": "darwin", "arch": "arm64", "defines": { "ODIN_DEBUG": "false" }}, + { "name": "windows_profile", "os": "windows", "checker_path": ["src"], "defines": { "ODIN_DEBUG": "false" }} + ] +} diff --git a/parser/parser.odin b/parser/parser.odin index d401c4e..50092ba 100644 --- a/parser/parser.odin +++ b/parser/parser.odin @@ -1,3 +1,4 @@ +#+feature dynamic-literals package parser import "core:fmt" diff --git a/parser/parser_test.odin b/parser/parser_test.odin index cb890e7..ac4e766 100644 --- a/parser/parser_test.odin +++ b/parser/parser_test.odin @@ -1,3 +1,4 @@ +#+feature dynamic-literals package parser import "core:bytes" @@ -21,9 +22,9 @@ check_parser_errors :: proc(t: ^testing.T, p: ^Parser) { return } - testing.errorf(t, "parser has %d errors", len(errors)) + testing.expectf(t, true, "parser has %d errors", len(errors)) for msg in errors { - testing.errorf(t, "parser error: %q", msg) + testing.expectf(t, true, "parser error: %q", msg) } testing.fail_now(t) } @@ -70,8 +71,9 @@ test_let_stmts :: proc(t: ^testing.T) { test_let_stmt :: proc(t: ^testing.T, s: ^ast.Stmt, name: string) -> bool { if ast.token_literal(s.expr_base) != "let" { - testing.errorf( + testing.expectf( t, + true, "ast.token_literal(s.expr_base) not 'let'. got=%q", ast.token_literal(s.expr_base), ) @@ -80,17 +82,23 @@ test_let_stmt :: proc(t: ^testing.T, s: ^ast.Stmt, name: string) -> bool { let_stmt, ok := s.derived.(^ast.Let_Stmt) if !ok { - testing.errorf(t, "s.derived not ^ast.Let_Stmt. got=%T", s) + testing.expectf(t, true, "s.derived not ^ast.Let_Stmt. got=%T", s) return false } if let_stmt.name.value != name { - testing.errorf(t, "let_stmt.name.value not '%s'. got=%s", name, let_stmt.name.value) + testing.expectf(t, true, "let_stmt.name.value not '%s'. got=%s", name, let_stmt.name.value) return false } if ast.token_literal(let_stmt.name) != name { - testing.errorf(t, "ast.token_literal(let_stmt.name) not '%s'. got=%s", name, let_stmt.name) + testing.expectf( + t, + true, + "ast.token_literal(let_stmt.name) not '%s'. got=%s", + name, + let_stmt.name, + ) return false } @@ -125,12 +133,13 @@ test_return_stmts :: proc(t: ^testing.T) { for s in program.statements { return_stmt, ok := s.derived.(^ast.Return_Stmt) if !ok { - testing.errorf(t, "s.derived not ^ast.Return_Stmt. got=%T", s) + testing.expectf(t, true, "s.derived not ^ast.Return_Stmt. got=%T", s) continue } if ast.token_literal(return_stmt) != "return" { - testing.errorf( + testing.expectf( t, + true, "ast.token_literal(return_stmt) not 'return'. got=%q", ast.token_literal(return_stmt), ) @@ -175,11 +184,12 @@ test_ident_expr :: proc(t: ^testing.T) { fmt.panicf("exp not ^ast.Ident. got=%T", stmt.expr) } if ident.value != "foobar" { - testing.errorf(t, "ident.value not %s. got=%s", "foobar", ident.value) + testing.expectf(t, true, "ident.value not %s. got=%s", "foobar", ident.value) } if ast.token_literal(ident) != "foobar" { - testing.errorf( + testing.expectf( t, + true, "ast.token_literal(ident) not %s. got=%s", "foobar", ast.token_literal(ident), @@ -224,11 +234,12 @@ test_int_literal_expr :: proc(t: ^testing.T) { fmt.panicf("exp not ^ast.Int_Literal. got=%T", stmt.expr) } if literal.value != 5 { - testing.errorf(t, "literal.value not %d. got=%d", 5, literal.value) + testing.expectf(t, true, "literal.value not %d. got=%d", 5, literal.value) } if ast.token_literal(literal) != "5" { - testing.errorf( + testing.expectf( t, + true, "ast.token_literal(literal) not %s. got=%s", "5", ast.token_literal(literal), @@ -292,19 +303,20 @@ test_parsing_prefix_expr :: proc(t: ^testing.T) { test_int_literal :: proc(t: ^testing.T, il: ^ast.Expr, value: i64) -> bool { integ, ok := il.derived.(^ast.Int_Literal) if !ok { - testing.errorf(t, "il not ^ast.Int_Literal. got=%T", il) + testing.expectf(t, true, "il not ^ast.Int_Literal. got=%T", il) return false } if integ.value != value { - testing.errorf(t, "integ.value not %d. got=%d", value, integ.value) + testing.expectf(t, true, "integ.value not %d. got=%d", value, integ.value) return false } int_str := fmt.tprintf("%d", value) if ast.token_literal(integ) != int_str { - testing.errorf( + testing.expectf( t, + true, "ast.token_literal(integ) not %d. got=%s", value, ast.token_literal(integ), @@ -408,7 +420,7 @@ test_operator_precedence_parsing :: proc(t: ^testing.T) { {"-(5 + 5)", "(-(5 + 5))"}, {"!(true == true)", "(!(true == true))"}, {"a + add(b * c) + d", "((a + add((b * c))) + d)"}, - { + { "add(a, b, 1, 2 * 3, 4 + 5, add(6, 7 * 8))", "add(a, b, 1, (2 * 3), (4 + 5), add(6, (7 * 8)))", }, @@ -437,8 +449,8 @@ test_operator_precedence_parsing :: proc(t: ^testing.T) { actual := bytes.buffer_to_string(&buf) if actual != tt.expected { - // testing.errorf(t, "expected=%q, got=%q", tt.expected, actual) - testing.errorf(t, "\no=%q\ne=%q\ng=%q\n", tt.input, tt.expected, actual) + // testing.expectf(t,true, "expected=%q, got=%q", tt.expected, actual) + testing.expectf(t, true, "\no=%q\ne=%q\ng=%q\n", tt.input, tt.expected, actual) } } } @@ -479,7 +491,13 @@ test_bool_literal_expr :: proc(t: ^testing.T) { fmt.panicf("exp is not ^ast.Bool_Literal. got=%T", stmt.expr) } if boolean.value != tt.expected { - testing.errorf(t, "boolean.value is not =%v, got=%v", tt.expected, boolean.value) + testing.expectf( + t, + true, + "boolean.value is not =%v, got=%v", + tt.expected, + boolean.value, + ) } } } @@ -536,7 +554,13 @@ test_parsing_infix_expr_bool :: proc(t: ^testing.T) { fmt.panicf("boolean is not ^ast.Bool_Literal. got=%T", stmt.expr) } if boolean.value != tt.left_value { - testing.errorf(t, "boolean.value is not =%v, got=%v", tt.left_value, boolean.value) + testing.expectf( + t, + true, + "boolean.value is not =%v, got=%v", + tt.left_value, + boolean.value, + ) } } @@ -550,8 +574,9 @@ test_parsing_infix_expr_bool :: proc(t: ^testing.T) { fmt.panicf("boolean is not ^ast.Bool_Literal. got=%T", stmt.expr) } if boolean.value != tt.right_value { - testing.errorf( + testing.expectf( t, + true, "boolean.value is not =%v, got=%v", tt.right_value, boolean.value, @@ -611,7 +636,7 @@ test_parsing_prefix_expr_bool :: proc(t: ^testing.T) { fmt.panicf("boolean is not ^ast.Bool_Literal. got=%T", stmt.expr) } if boolean.value != tt.value { - testing.errorf(t, "boolean.value is not =%v, got=%v", tt.value, boolean.value) + testing.expectf(t, true, "boolean.value is not =%v, got=%v", tt.value, boolean.value) } } } @@ -664,12 +689,12 @@ test_if_expr :: proc(t: ^testing.T) { fmt.panicf("expr.left is not ^ast.Ident. got=%T", expr.left) } if e.value != "x" { - testing.errorf(t, "e.value is not =%v, got=%v", "x", e.value) + testing.expectf(t, true, "e.value is not =%v, got=%v", "x", e.value) } } if expr.operator != "<" { - testing.errorf(t, "expr.operator is not '%s'. got='%s'", "<", expr.operator) + testing.expectf(t, true, "expr.operator is not '%s'. got='%s'", "<", expr.operator) } { @@ -678,14 +703,15 @@ test_if_expr :: proc(t: ^testing.T) { fmt.panicf("expr.right is not ^ast.Ident. got=%T", expr.right) } if e.value != "y" { - testing.errorf(t, "e.value is not =%v, got=%v", "y", e.value) + testing.expectf(t, true, "e.value is not =%v, got=%v", "y", e.value) } } } // end: "x < y" if len(expr.consequence.statements) != 1 { - testing.errorf( + testing.expectf( t, + true, "consequence is not 1 statements. got=%d\n", len(expr.consequence.statements), ) @@ -702,11 +728,11 @@ test_if_expr :: proc(t: ^testing.T) { fmt.panicf("consequence.expr is not ^ast.Ident. got=%T", ident) } if ident.value != "z" { - testing.errorf(t, "ident.value is not =%v, got=%v", "z", ident.value) + testing.expectf(t, true, "ident.value is not =%v, got=%v", "z", ident.value) } // end: "z" if expr.alternative != nil { - testing.errorf(t, "expr.alternative.statements was not nil.") + testing.expectf(t, true, "expr.alternative.statements was not nil.") } } @@ -756,7 +782,7 @@ test_function_literal_parsing :: proc(t: ^testing.T) { fmt.panicf("func.parameters[0] is not ^ast.Ident. got=%T", ident) } if ident.value != "x" { - testing.errorf(t, "ident.value is not =%v, got=%v", "x", ident.value) + testing.expectf(t, true, "ident.value is not =%v, got=%v", "x", ident.value) } // end: "x" } @@ -767,7 +793,7 @@ test_function_literal_parsing :: proc(t: ^testing.T) { fmt.panicf("func.parameters[0] is not ^ast.Ident. got=%T", ident) } if ident.value != "y" { - testing.errorf(t, "ident.value is not =%v, got=%v", "y", ident.value) + testing.expectf(t, true, "ident.value is not =%v, got=%v", "y", ident.value) } // end: "y" } @@ -796,12 +822,12 @@ test_function_literal_parsing :: proc(t: ^testing.T) { fmt.panicf("infix.left is not ^ast.Ident. got=%T", infix.left) } if ident.value != "x" { - testing.errorf(t, "ident.value is not =%v, got=%v", "x", ident.value) + testing.expectf(t, true, "ident.value is not =%v, got=%v", "x", ident.value) } } if infix.operator != "+" { - testing.errorf(t, "infix.operator is not '%s'. got='%s'", "+", infix.operator) + testing.expectf(t, true, "infix.operator is not '%s'. got='%s'", "+", infix.operator) } { @@ -810,7 +836,7 @@ test_function_literal_parsing :: proc(t: ^testing.T) { fmt.panicf("infix.right is not ^ast.Ident. got=%T", infix.right) } if ident.value != "y" { - testing.errorf(t, "ident.value is not =%v, got=%v", "y", ident.value) + testing.expectf(t, true, "ident.value is not =%v, got=%v", "y", ident.value) } } } // end: "x + y" @@ -858,7 +884,7 @@ test_call_expr_parsing :: proc(t: ^testing.T) { fmt.panicf("expr.function is not ^ast.Ident. got=%T", expr.function) } if ident.value != "add" { - testing.errorf(t, "ident.value is not =%v, got=%v", "add", ident.value) + testing.expectf(t, true, "ident.value is not =%v, got=%v", "add", ident.value) } } @@ -873,7 +899,7 @@ test_call_expr_parsing :: proc(t: ^testing.T) { fmt.panicf("expr.arguments[0] is not ^ast.Int_Literal . got=%T", expr.arguments[0]) } if ilit.value != 1 { - testing.errorf(t, "ident.value is not =%d, got=%v", 1, ilit.value) + testing.expectf(t, true, "ident.value is not =%d, got=%v", 1, ilit.value) } } @@ -890,12 +916,12 @@ test_call_expr_parsing :: proc(t: ^testing.T) { fmt.panicf("infix.left is not ^ast.Int_Literal. got=%T", infix.left) } if ilit.value != 2 { - testing.errorf(t, "ilit.value is not =%d, got=%v", 2, ilit.value) + testing.expectf(t, true, "ilit.value is not =%d, got=%v", 2, ilit.value) } } if infix.operator != "*" { - testing.errorf(t, "infix.operator is not '%s'. got='%s'", "*", infix.operator) + testing.expectf(t, true, "infix.operator is not '%s'. got='%s'", "*", infix.operator) } { @@ -904,7 +930,7 @@ test_call_expr_parsing :: proc(t: ^testing.T) { fmt.panicf("infix.right is not ^ast.Int_Literal. got=%T", infix.left) } if ilit.value != 3 { - testing.errorf(t, "ilit.value is not =%d, got=%v", 3, ilit.value) + testing.expectf(t, true, "ilit.value is not =%d, got=%v", 3, ilit.value) } } } @@ -922,12 +948,12 @@ test_call_expr_parsing :: proc(t: ^testing.T) { fmt.panicf("infix.left is not ^ast.Int_Literal. got=%T", infix.left) } if ilit.value != 4 { - testing.errorf(t, "ilit.value is not =%d, got=%v", 4, ilit.value) + testing.expectf(t, true, "ilit.value is not =%d, got=%v", 4, ilit.value) } } if infix.operator != "+" { - testing.errorf(t, "infix.operator is not '%s'. got='%s'", "+", infix.operator) + testing.expectf(t, true, "infix.operator is not '%s'. got='%s'", "+", infix.operator) } { @@ -936,7 +962,7 @@ test_call_expr_parsing :: proc(t: ^testing.T) { fmt.panicf("infix.right is not ^ast.Int_Literal. got=%T", infix.right) } if ilit.value != 5 { - testing.errorf(t, "ilit.value is not =%d, got=%v", 5, ilit.value) + testing.expectf(t, true, "ilit.value is not =%d, got=%v", 5, ilit.value) } } } @@ -976,16 +1002,18 @@ test_let_stmts2 :: proc(t: ^testing.T) { } if ast.token_literal(let_stmt) != "let" { - testing.errorf( + testing.expectf( t, + true, "ast.token_literal(let_stmt) not 'let'. got=%q", ast.token_literal(let_stmt), ) } if let_stmt.name.value != tt.expected_ident { - testing.errorf( + testing.expectf( t, + true, "let_stmt.name.value not '%s'. got=%q", tt.expected_ident, let_stmt.name.value, @@ -994,7 +1022,7 @@ test_let_stmts2 :: proc(t: ^testing.T) { value := let_stmt.value.derived.(^ast.Int_Literal).value if value != tt.expected_value { - testing.errorf(t, "value not '%d'. got=%d", tt.expected_value, value) + testing.expectf(t, true, "value not '%d'. got=%d", tt.expected_value, value) } } } @@ -1063,12 +1091,12 @@ test_parsing_array_literals :: proc(t: ^testing.T) { fmt.panicf("infix.left is not ^ast.Int_Literal. got=%T", infix.left) } if ilit.value != 2 { - testing.errorf(t, "ilit.value is not =%d, got=%v", 2, ilit.value) + testing.expectf(t, true, "ilit.value is not =%d, got=%v", 2, ilit.value) } } if infix.operator != "*" { - testing.errorf(t, "infix.operator is not '%s'. got='%s'", "*", infix.operator) + testing.expectf(t, true, "infix.operator is not '%s'. got='%s'", "*", infix.operator) } { @@ -1077,7 +1105,7 @@ test_parsing_array_literals :: proc(t: ^testing.T) { fmt.panicf("infix.right is not ^ast.Int_Literal. got=%T", infix.left) } if ilit.value != 2 { - testing.errorf(t, "ilit.value is not =%d, got=%v", 2, ilit.value) + testing.expectf(t, true, "ilit.value is not =%d, got=%v", 2, ilit.value) } } } @@ -1095,12 +1123,12 @@ test_parsing_array_literals :: proc(t: ^testing.T) { fmt.panicf("infix.left is not ^ast.Int_Literal. got=%T", infix.left) } if ilit.value != 3 { - testing.errorf(t, "ilit.value is not =%d, got=%v", 3, ilit.value) + testing.expectf(t, true, "ilit.value is not =%d, got=%v", 3, ilit.value) } } if infix.operator != "+" { - testing.errorf(t, "infix.operator is not '%s'. got='%s'", "*", infix.operator) + testing.expectf(t, true, "infix.operator is not '%s'. got='%s'", "*", infix.operator) } { @@ -1109,7 +1137,7 @@ test_parsing_array_literals :: proc(t: ^testing.T) { fmt.panicf("infix.right is not ^ast.Int_Literal. got=%T", infix.left) } if ilit.value != 3 { - testing.errorf(t, "ilit.value is not =%d, got=%v", 3, ilit.value) + testing.expectf(t, true, "ilit.value is not =%d, got=%v", 3, ilit.value) } } } @@ -1143,7 +1171,7 @@ test_parsing_index_expr :: proc(t: ^testing.T) { fmt.panicf("index_expr.left is not ^ast.Ident. got=%T", index_expr.left) } if ident.value != "myArray" { - testing.errorf(t, "ident.value is not =%v, got=%v", "myArray", ident.value) + testing.expectf(t, true, "ident.value is not =%v, got=%v", "myArray", ident.value) } } @@ -1161,12 +1189,12 @@ test_parsing_index_expr :: proc(t: ^testing.T) { fmt.panicf("infix.left is not ^ast.Int_Literal. got=%T", infix.left) } if ilit.value != 1 { - testing.errorf(t, "ilit.value is not =%d, got=%v", 1, ilit.value) + testing.expectf(t, true, "ilit.value is not =%d, got=%v", 1, ilit.value) } } if infix.operator != "+" { - testing.errorf(t, "infix.operator is not '%s'. got='%s'", "*", infix.operator) + testing.expectf(t, true, "infix.operator is not '%s'. got='%s'", "*", infix.operator) } { @@ -1175,7 +1203,7 @@ test_parsing_index_expr :: proc(t: ^testing.T) { fmt.panicf("infix.right is not ^ast.Int_Literal. got=%T", infix.left) } if ilit.value != 1 { - testing.errorf(t, "ilit.value is not =%d, got=%v", 1, ilit.value) + testing.expectf(t, true, "ilit.value is not =%d, got=%v", 1, ilit.value) } } } @@ -1202,7 +1230,7 @@ test_parsing_hash_literals_string_keys :: proc(t: ^testing.T) { } if len(hash.pairs) != 3 { - testing.errorf(t, "hash.pairs has wrong length. got=%d", len(hash.pairs)) + testing.expectf(t, true, "hash.pairs has wrong length. got=%d", len(hash.pairs)) } expected := map[string]i64 { @@ -1215,7 +1243,7 @@ test_parsing_hash_literals_string_keys :: proc(t: ^testing.T) { for key, value in hash.pairs { literal, ok := key.derived.(^ast.String_Literal) if !ok { - testing.errorf(t, "key is not ^ast.String_Literal. got=%T", key.derived) + testing.expectf(t, true, "key is not ^ast.String_Literal. got=%T", key.derived) } expected_value := expected[literal.value] @@ -1245,7 +1273,7 @@ test_parsing_empty_hash_literal :: proc(t: ^testing.T) { } if len(hash.pairs) != 0 { - testing.errorf(t, "hash.pairs has wrong length. got=%d", len(hash.pairs)) + testing.expectf(t, true, "hash.pairs has wrong length. got=%d", len(hash.pairs)) } } @@ -1270,7 +1298,7 @@ test_parsing_hash_literals_with_exprs :: proc(t: ^testing.T) { } if len(hash.pairs) != 3 { - testing.errorf(t, "hash.pairs has wrong length. got=%d", len(hash.pairs)) + testing.expectf(t, true, "hash.pairs has wrong length. got=%d", len(hash.pairs)) } tests := map[string]Types1 { @@ -1283,7 +1311,7 @@ test_parsing_hash_literals_with_exprs :: proc(t: ^testing.T) { for key, value in hash.pairs { literal, ok := key.derived.(^ast.String_Literal) if !ok { - testing.errorf(t, "key is not ^ast.String_Literal. got=%T", key.derived) + testing.expectf(t, true, "key is not ^ast.String_Literal. got=%T", key.derived) continue } @@ -1292,8 +1320,9 @@ test_parsing_hash_literals_with_exprs :: proc(t: ^testing.T) { test_int_literal(t, value.derived.(^ast.Infix_Expr).left, expected.first) if value.derived.(^ast.Infix_Expr).operator != expected.operator { - testing.errorf( + testing.expectf( t, + true, "value.derived.(^ast.Infix_Expr).operator is not '%s'. got='%s'", expected.operator, value.derived.(^ast.Infix_Expr).operator,