Browse Source

Merge pull request #1182 from DanielGavin/parser-fix

Make optional semicolons the default on odin/parser, and add parser test on demo.odin
Jeroen van Rijn 3 years ago
parent
commit
b3dc3f5908
3 changed files with 57 additions and 2 deletions
  1. 1 1
      core/odin/parser/parser.odin
  2. 6 1
      tests/core/build.bat
  3. 50 0
      tests/core/odin/test_parser.odin

+ 1 - 1
core/odin/parser/parser.odin

@@ -116,7 +116,7 @@ end_pos :: proc(tok: tokenizer.Token) -> tokenizer.Pos {
 	return pos
 	return pos
 }
 }
 
 
-default_parser :: proc(flags := Flags{}) -> Parser {
+default_parser :: proc(flags := Flags{.Optional_Semicolons}) -> Parser {
 	return Parser {
 	return Parser {
 		flags = flags,
 		flags = flags,
 		err  = default_error_handler,
 		err  = default_error_handler,

+ 6 - 1
tests/core/build.bat

@@ -20,4 +20,9 @@ echo ---
 echo ---
 echo ---
 echo Running core:hash tests
 echo Running core:hash tests
 echo ---
 echo ---
-%PATH_TO_ODIN% run hash %COMMON% -o:size
+%PATH_TO_ODIN% run hash %COMMON% -o:size
+
+echo ---
+echo Running core:odin tests
+echo ---
+%PATH_TO_ODIN% run odin %COMMON% -o:size

+ 50 - 0
tests/core/odin/test_parser.odin

@@ -0,0 +1,50 @@
+package test_core_odin_parser
+
+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))
+	}
+}