nx_tabrec_gate.nx source
↩ module page · 33 lines · 2030 B
1// nx_tabrec_gate.nx -- proves the canonical tab-record parser/builder, and demonstrates the consolidated pattern: a
2// gate with ZERO local helpers -- it imports nx_gate (gw/gn) and nx_tabrec (tr_*) and nothing is re-rolled.
3// license_tier: ORIGINAL
4import "nx_gate.nx"
5import "nx_tabrec.nx"
6
7func main() -> i64 {
8 gw("=== nx_tabrec_gate: canonical tab-record parse/build (zero local helpers) ===\n" as *u8)
9 // build a record with the canonical builders: dhash <TAB> thresh <TAB> category <TAB> status
10 let rec: *u8=sys_mmap(256); var o: i64=0
11 o=tr_cat(rec,o,"80800080204a1000" as *u8); o=tr_tab(rec,o); o=tr_cat(rec,o,"10" as *u8); o=tr_tab(rec,o); o=tr_cat(rec,o,"NCII" as *u8); o=tr_tab(rec,o); o=tr_cat(rec,o,"approved" as *u8)
12 let f2: *i64=sys_mmap(16) as *i64
13 var pass: i64=0; var tot: i64=0
14
15 tot=tot+1; tr_field(rec,0,o,0,f2); if f2[1]==16 { pass=pass+1; gw(" [PASS] " as *u8) } else { gw(" [FAIL] " as *u8) }
16 gw("T1 field 0 = 16-char fingerprint\n" as *u8)
17
18 tot=tot+1; tr_field(rec,0,o,1,f2); if tr_atoi(rec,f2[0],f2[1])==10 { pass=pass+1; gw(" [PASS] " as *u8) } else { gw(" [FAIL] " as *u8) }
19 gw("T2 field 1 atoi = 10\n" as *u8)
20
21 tot=tot+1; if tr_field_eq(rec,o,3,"approved" as *u8,f2)==1 { pass=pass+1; gw(" [PASS] " as *u8) } else { gw(" [FAIL] " as *u8) }
22 gw("T3 field 3 == \"approved\"\n" as *u8)
23
24 tot=tot+1; if tr_field_eq(rec,o,2,"NCII" as *u8,f2)==1 { pass=pass+1; gw(" [PASS] " as *u8) } else { gw(" [FAIL] " as *u8) }
25 gw("T4 field 2 == \"NCII\"\n" as *u8)
26
27 tot=tot+1; if tr_field_eq(rec,o,3,"pending" as *u8,f2)==0 { pass=pass+1; gw(" [PASS] " as *u8) } else { gw(" [FAIL] " as *u8) }
28 gw("T5 field 3 != \"pending\" (negative control)\n" as *u8)
29
30 gw("\n=== nx_tabrec_gate " as *u8); gn(pass); gw("/" as *u8); gn(tot); gw(" ===\n" as *u8)
31 if pass==tot { gw("TABREC verdict=GREEN -- one canonical parser/builder; this gate re-rolled nothing\n" as *u8); sys_exit(0); return 0 }
32 gw("TABREC RED\n" as *u8); sys_exit(1); return 1
33}