Interplane page as plain text, for reading tools and agents. English is the reference text: translate it with your own tool. Text in backticks and in ``` blocks (commands, fingerprints, file names) and link targets in <...> are exact: copy them, never translate them. Page: /drakestapleton/cortex/blob/main/tests/json/t_api.om # cortex aien-dev/cortex Brought by drakestapleton Sign in to star 0 stars 0 watching About Files History Releases Proposed changes Issues For developers branch `main` Branches Tags History `cortex / tests / json / t_api.om` 92 lines ยท 1571 bytes Raw Blame History 1 note tests/json/t_api.om - checks the position rules JsonNum documents for typed-struct errors against 2 note serde_json::from_slice::: invalid type -> js_spos (array/object) or 3 note js_epos (scalar), missing field -> js_epos(root), duplicate field -> js_vpos(js_kend(second member)). 4 note 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. 5 text tq "query" 6 text tty "type " 7 text tmis "missing " 8 text tdup "duplicate " 9 text tok "OK" 10 fn t_pos k ulong idx ulong to void 11 put jobl 0 0 12 if eq k 1 13 js_raw tty 14 end 15 if eq k 2 16 js_raw tmis 17 end 18 if eq k 3 19 js_raw tdup 20 end 21 js_u64 js_line idx 22 js_byte 32 23 js_u64 js_col idx 24 t_emitjob 25 end 26 fn t_one to void 27 if not js_parse 28 trap 11 29 end 30 r = get jroot 0 31 seen = false 32 for i ulong js_len r 33 m = js_child r i 34 js_key m 35 ok = eq get jsvl 0 5 36 if ok 37 for k ulong 5 38 if ne get jsv k get tq k 39 ok = false 40 end 41 end 42 end 43 if ok 44 if seen 45 t_pos 3 js_vpos js_kend m 46 ret 47 end 48 seen = true 49 if eq js_find r tq jnone 50 trap 12 51 end 52 k = js_kind m 53 if ne k 6 54 if or eq k 7 eq k 8 55 t_pos 1 js_spos m 56 else 57 t_pos 1 js_epos m 58 end 59 ret 60 end 61 end 62 end 63 if not seen 64 if ne js_find r tq jnone 65 trap 13 66 end 67 t_pos 2 js_epos r 68 ret 69 end 70 put jobl 0 0 71 js_raw tok 72 t_emitjob 73 end 74 global targ uchar 8 75 fn main to int 76 num_init 77 note optional argument "raw": disable the RawValue collapse (put jrvm 0 1), the typed-struct view 78 if gt argcnt 1 79 k = argread 1 targ 0 8 80 if eq k 3 81 put jrvm 0 1 82 end 83 end 84 for it ulong `100000000` 85 if not t_rec 86 t_flush 87 ret 0 88 end 89 t_one 90 end 91 ret 1 92 end