test_parser.odin 1.0 KB

1234567891011121314151617181920212223242526272829303132333435363738394041424344454647484950
  1. package test_core_odin_parser
  2. import "core:testing"
  3. import "core:fmt"
  4. import "core:os"
  5. import "core:odin/parser"
  6. TEST_count := 0
  7. TEST_fail := 0
  8. when ODIN_TEST {
  9. expect :: testing.expect
  10. log :: testing.log
  11. } else {
  12. expect :: proc(t: ^testing.T, condition: bool, message: string, loc := #caller_location) {
  13. TEST_count += 1
  14. if !condition {
  15. TEST_fail += 1
  16. fmt.printf("[%v] %v\n", loc, message)
  17. return
  18. }
  19. }
  20. log :: proc(t: ^testing.T, v: any, loc := #caller_location) {
  21. fmt.printf("[%v] ", loc)
  22. fmt.printf("log: %v\n", v)
  23. }
  24. }
  25. main :: proc() {
  26. t := testing.T{}
  27. test_parse_demo(&t)
  28. fmt.printf("%v/%v tests successful.\n", TEST_count - TEST_fail, TEST_count)
  29. if TEST_fail > 0 {
  30. os.exit(1)
  31. }
  32. }
  33. @test
  34. test_parse_demo :: proc(t: ^testing.T) {
  35. pkg, ok := parser.parse_package_from_path("examples/demo")
  36. expect(t, ok == true, "parser.parse_package_from_path failed")
  37. for key, value in pkg.files {
  38. expect(t, value.syntax_error_count == 0, fmt.tprintf("%v should contain zero errors", key))
  39. }
  40. }