aboutsummaryrefslogtreecommitdiff
path: root/tests
diff options
context:
space:
mode:
authorgingerBill <bill@gingerbill.org>2024-04-10 12:32:32 +0100
committergingerBill <bill@gingerbill.org>2024-04-10 12:32:32 +0100
commit97e2d8916a2b5018cdee15c5057edbbdcb9128d5 (patch)
treeacadc8e0407447a50e9aa0a14429de15917a631e /tests
parent3dfd61dd4f1aec7525a8d6820c9c977f6a3ed14e (diff)
parent0f39b9ef22c4b73448bc0ccc58369ea36723103e (diff)
Merge branch 'master' of https://github.com/odin-lang/Odin
Diffstat (limited to 'tests')
-rw-r--r--tests/core/odin/test_parser.odin50
1 files changed, 47 insertions, 3 deletions
diff --git a/tests/core/odin/test_parser.odin b/tests/core/odin/test_parser.odin
index 3837436bc..08f73a732 100644
--- a/tests/core/odin/test_parser.odin
+++ b/tests/core/odin/test_parser.odin
@@ -1,9 +1,12 @@
package test_core_odin_parser
-import "core:testing"
import "core:fmt"
-import "core:os"
+import "core:odin/ast"
import "core:odin/parser"
+import "core:odin/printer"
+import "core:os"
+import "core:strings"
+import "core:testing"
TEST_count := 0
@@ -30,6 +33,7 @@ when ODIN_TEST {
main :: proc() {
t := testing.T{}
test_parse_demo(&t)
+ test_parse_bitfield(&t)
fmt.printf("%v/%v tests successful.\n", TEST_count - TEST_fail, TEST_count)
if TEST_fail > 0 {
@@ -47,4 +51,44 @@ test_parse_demo :: proc(t: ^testing.T) {
for key, value in pkg.files {
expect(t, value.syntax_error_count == 0, fmt.tprintf("%v should contain zero errors", key))
}
-} \ No newline at end of file
+}
+
+@test
+test_parse_bitfield :: proc(t: ^testing.T) {
+ file := ast.File{
+ fullpath = "test.odin",
+ src = `
+package main
+
+Foo :: bit_field uint {}
+
+Foo :: bit_field uint {hello: bool | 1}
+
+Foo :: bit_field uint {
+ hello: bool | 1,
+ hello: bool | 5,
+}
+
+// Hellope 1.
+Foo :: bit_field uint {
+ // Hellope 2.
+ hello: bool | 1,
+ hello: bool | 5, // Hellope 3.
+}
+ `,
+ }
+
+ p := parser.default_parser()
+ ok := parser.parse_file(&p, &file)
+ expect(t, ok == true, "bad parse")
+
+ cfg := printer.default_style
+ cfg.newline_style = .LF
+ print := printer.make_printer(cfg)
+ out := printer.print(&print, &file)
+
+ tsrc := strings.trim_space(file.src)
+ tout := strings.trim_space(out)
+
+ expect(t, tsrc == tout, fmt.tprintf("\n%s\n!=\n%s", tsrc, tout))
+}