odin-jsonschema

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

check.odin (505B)


      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 	_, has_name := root.name.?
     14 	testing.expect_value(t, has_name, false)
     15 	testing.expect_value(t, root.age.? or_else 0, 30)
     16 	tag, is_int := root.tag.(i64)
     17 	testing.expect(t, is_int, "tag should parse as i64")
     18 	testing.expect_value(t, tag, 7)
     19 }