check.odin (805B)
1 package check 2 3 import "core:encoding/json" 4 import "core:testing" 5 6 SAMPLE :: #load("sample.json", string) 7 8 @(test) 9 parses :: proc(t: ^testing.T) { 10 root: Root 11 err := json.unmarshal_string(SAMPLE, &root) 12 testing.expectf(t, err == nil, "unmarshal failed: %v", err) 13 tree := root.tree.? or_else Node{} 14 testing.expect_value(t, tree.value, "root") 15 children := tree.children.? or_else nil 16 testing.expect_value(t, len(children), 2) 17 testing.expect_value(t, children[0].value, "leaf-a") 18 grandchildren := children[1].children.? or_else nil 19 testing.expect_value(t, len(grandchildren), 1) 20 testing.expect_value(t, grandchildren[0].value, "leaf-b") 21 loop := root.loop.? or_else Loop{} 22 _, next_is_object := loop.next.(json.Object) 23 testing.expect(t, next_is_object, "loop.next should hold a raw json.Object") 24 }