interplane.Get Omega
Read in your language

cortex

aien-dev/cortex

Brought by drakestapleton

branch main Branches Tags History

cortex / tests / json / t_api.om

92 lines · 1571 bytes Raw Blame History
1note tests/json/t_api.om - checks the position rules JsonNum documents for typed-struct errors against
2note serde_json::from_slice::<struct Q { query: String }>: invalid type -> js_spos (array/object) or
3note js_epos (scalar), missing field -> js_epos(root), duplicate field -> js_vpos(js_kend(second member)).
4note Run with argument "raw" to parse with jrvm = 1 (typed-struct view). Also exercises js_find (last duplicate), js_len, js_child, js_key, js_line, js_col. Needs t_io.om.
5text tq "query"
6text tty "type "
7text tmis "missing "
8text tdup "duplicate "
9text tok "OK"
10fn t_pos k ulong idx ulong to void
11put jobl 0 0
12if eq k 1
13js_raw tty
14end
15if eq k 2
16js_raw tmis
17end
18if eq k 3
19js_raw tdup
20end
21js_u64 js_line idx
22js_byte 32
23js_u64 js_col idx
24t_emitjob
25end
26fn t_one to void
27if not js_parse
28trap 11
29end
30r = get jroot 0
31seen = false
32for i ulong js_len r
33m = js_child r i
34js_key m
35ok = eq get jsvl 0 5
36if ok
37for k ulong 5
38if ne get jsv k get tq k
39ok = false
40end
41end
42end
43if ok
44if seen
45t_pos 3 js_vpos js_kend m
46ret
47end
48seen = true
49if eq js_find r tq jnone
50trap 12
51end
52k = js_kind m
53if ne k 6
54if or eq k 7 eq k 8
55t_pos 1 js_spos m
56else
57t_pos 1 js_epos m
58end
59ret
60end
61end
62end
63if not seen
64if ne js_find r tq jnone
65trap 13
66end
67t_pos 2 js_epos r
68ret
69end
70put jobl 0 0
71js_raw tok
72t_emitjob
73end
74global targ uchar 8
75fn main to int
76num_init
77note optional argument "raw": disable the RawValue collapse (put jrvm 0 1), the typed-struct view
78if gt argcnt 1
79k = argread 1 targ 0 8
80if eq k 3
81put jrvm 0 1
82end
83end
84for it ulong 100000000
85if not t_rec
86t_flush
87ret 0
88end
89t_one
90end
91ret 1
92end