test_parser.odin 1.1 KB

1234567891011121314151617181920212223242526272829303132333435363738394041424344454647484950515253
  1. package test_core_odin_parser
  2. import "core:odin/ast"
  3. import "core:odin/parser"
  4. import "base:runtime"
  5. import "core:testing"
  6. @test
  7. test_parse_demo :: proc(t: ^testing.T) {
  8. context.allocator = context.temp_allocator
  9. runtime.DEFAULT_TEMP_ALLOCATOR_TEMP_GUARD()
  10. pkg, ok := parser.parse_package_from_path(ODIN_ROOT + "examples/demo")
  11. testing.expect(t, ok, "parser.parse_package_from_path failed")
  12. for key, value in pkg.files {
  13. testing.expectf(t, value.syntax_error_count == 0, "%v should contain zero errors", key)
  14. }
  15. }
  16. @test
  17. test_parse_bitfield :: proc(t: ^testing.T) {
  18. context.allocator = context.temp_allocator
  19. runtime.DEFAULT_TEMP_ALLOCATOR_TEMP_GUARD()
  20. file := ast.File{
  21. fullpath = "test.odin",
  22. src = `
  23. package main
  24. Foo :: bit_field uint {}
  25. Foo :: bit_field uint {hello: bool | 1}
  26. Foo :: bit_field uint {
  27. hello: bool | 1,
  28. hello: bool | 5,
  29. }
  30. // Hellope 1.
  31. Foo :: bit_field uint {
  32. // Hellope 2.
  33. hello: bool | 1,
  34. hello: bool | 5, // Hellope 3.
  35. }
  36. `,
  37. }
  38. p := parser.default_parser()
  39. ok := parser.parse_file(&p, &file)
  40. testing.expect(t, ok, "bad parse")
  41. }