From 50ee65ea9e86879308a5d41aca88b0cf35423b36 Mon Sep 17 00:00:00 2001 From: Daniel Gavin Date: Mon, 20 Sep 2021 20:50:01 +0200 Subject: [PATCH 1/2] Make default_parser use the optional_semicolons and add odin parser test. --- core/odin/parser/parser.odin | 2 +- tests/core/build.bat | 7 ++++- tests/core/odin/test_parse.odin | 50 +++++++++++++++++++++++++++++++++ 3 files changed, 57 insertions(+), 2 deletions(-) create mode 100644 tests/core/odin/test_parse.odin diff --git a/core/odin/parser/parser.odin b/core/odin/parser/parser.odin index 503836ec9..d6935c925 100644 --- a/core/odin/parser/parser.odin +++ b/core/odin/parser/parser.odin @@ -116,7 +116,7 @@ end_pos :: proc(tok: tokenizer.Token) -> tokenizer.Pos { return pos } -default_parser :: proc(flags := Flags{}) -> Parser { +default_parser :: proc(flags := Flags{.Optional_Semicolons}) -> Parser { return Parser { flags = flags, err = default_error_handler, diff --git a/tests/core/build.bat b/tests/core/build.bat index d7f7de902..d90759841 100644 --- a/tests/core/build.bat +++ b/tests/core/build.bat @@ -20,4 +20,9 @@ echo --- echo --- echo Running core:hash tests echo --- -%PATH_TO_ODIN% run hash %COMMON% -o:size \ No newline at end of file +%PATH_TO_ODIN% run hash %COMMON% -o:size + +echo --- +echo Running core:odin tests +echo --- +%PATH_TO_ODIN% run odin %COMMON% -o:size \ No newline at end of file diff --git a/tests/core/odin/test_parse.odin b/tests/core/odin/test_parse.odin new file mode 100644 index 000000000..b7c85c59e --- /dev/null +++ b/tests/core/odin/test_parse.odin @@ -0,0 +1,50 @@ +package test_core_odin_parse + +import "core:testing" +import "core:fmt" + +import "core:odin/parser" + + +TEST_count := 0 +TEST_fail := 0 + +when ODIN_TEST { + expect :: testing.expect + log :: testing.log +} else { + expect :: proc(t: ^testing.T, condition: bool, message: string, loc := #caller_location) { + fmt.printf("[%v] ", loc) + TEST_count += 1 + if !condition { + TEST_fail += 1 + fmt.println(message) + return + } + fmt.println(" PASS") + } + log :: proc(t: ^testing.T, v: any, loc := #caller_location) { + fmt.printf("[%v] ", loc) + fmt.printf("log: %v\n", v) + } +} + + +main :: proc() { + t := testing.T{} + test_parse_demo(&t) + + fmt.printf("%v/%v tests successful.\n", TEST_count - TEST_fail, TEST_count) +} + + +@test +test_parse_demo :: proc(t: ^testing.T) { + pkg, ok := parser.parse_package_from_path("examples/demo") + + expect(t, ok == true, "parser.parse_package_from_path failed") + + for key, value in pkg.files { + expect(t, value.syntax_error_count == 0, fmt.tprintf("%v should contain zero errors", key)) + } +} From 46d99395ce421042a9dfdb26a4d7d90e2c54f516 Mon Sep 17 00:00:00 2001 From: Daniel Gavin Date: Mon, 20 Sep 2021 20:53:39 +0200 Subject: [PATCH 2/2] typo in filename --- tests/core/odin/{test_parse.odin => test_parser.odin} | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) rename tests/core/odin/{test_parse.odin => test_parser.odin} (97%) diff --git a/tests/core/odin/test_parse.odin b/tests/core/odin/test_parser.odin similarity index 97% rename from tests/core/odin/test_parse.odin rename to tests/core/odin/test_parser.odin index b7c85c59e..90d913d10 100644 --- a/tests/core/odin/test_parse.odin +++ b/tests/core/odin/test_parser.odin @@ -1,4 +1,4 @@ -package test_core_odin_parse +package test_core_odin_parser import "core:testing" import "core:fmt"