odin-jsonschema

Implementation of JSON schema for Odin
Log | Files | Refs | LICENSE

check.odin (589B)


      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 	testing.expect_value(t, root.one.? or_else "", "hello")
     14 	testing.expect_value(t, root.two.? or_else 0, 4.5)
     15 	three := root.three.? or_else nil
     16 	testing.expect_value(t, len(three), 2)
     17 	testing.expect_value(t, three[0], "a")
     18 	four := root.four.? or_else Root_Four{}
     19 	testing.expect_value(t, four.foobar.? or_else "", "baz")
     20 }