code wiki / (root) / nx_lib_std_gate.nx

nx_lib_std_gate.nx source

↩ module page · 138 lines · 4064 B

1// nx_lib_std_gate.nx -- gate for the sovereign stdlib seed. KATs per function + NEGATIVE 2// CONTROLS (streq must reject differing strings incl. prefix case; atoi must return 0 on 3// garbage; itoa/atoi must round-trip negatives). Exits nonzero unless every tooth passes. 4// license_tier: ORIGINAL expect_exit: 0 5import "nx_syscalls.nx" 6import "nx_lib_std.nx" 7 8func g_report(name: *u8, ok: i64) -> i64 { 9 std_puts(name) 10 if ok == 1 { std_putln(" PASS" as *u8) } 11 if ok == 0 { std_putln(" FAIL" as *u8) } 12 return ok 13} 14 15func main(argc: i64, argv: *i64) -> i64 { 16 var pass: i64 = 0 17 var total: i64 = 0 18 19 total = total + 1 20 let l1: i64 = std_slen("abc" as *u8) 21 var ok: i64 = 0 22 if l1 == 3 { ok = 1 } 23 let r1: i64 = g_report("T01 slen-abc" as *u8, ok) 24 pass = pass + r1 25 26 total = total + 1 27 let l2: i64 = std_slen("\x00" as *u8) 28 ok = 0 29 if l2 == 0 { ok = 1 } 30 let r2: i64 = g_report("T02 slen-empty" as *u8, ok) 31 pass = pass + r2 32 33 total = total + 1 34 let e1: i64 = std_streq("forge" as *u8, "forge" as *u8) 35 ok = 0 36 if e1 == 1 { ok = 1 } 37 let r3: i64 = g_report("T03 streq-same" as *u8, ok) 38 pass = pass + r3 39 40 total = total + 1 41 let e2: i64 = std_streq("forge" as *u8, "forgd" as *u8) 42 ok = 0 43 if e2 == 0 { ok = 1 } 44 let r4: i64 = g_report("T04 streq-diff-NEG" as *u8, ok) 45 pass = pass + r4 46 47 total = total + 1 48 let e3: i64 = std_streq("for" as *u8, "forge" as *u8) 49 ok = 0 50 if e3 == 0 { ok = 1 } 51 let r5: i64 = g_report("T05 streq-prefix-NEG" as *u8, ok) 52 pass = pass + r5 53 54 total = total + 1 55 let cb: *u8 = sys_mmap(64) as *u8 56 let cl: i64 = std_scopy("sovereign" as *u8, cb) 57 let ce: i64 = std_streq(cb, "sovereign" as *u8) 58 ok = 0 59 if cl == 9 { if ce == 1 { ok = 1 } } 60 let r6: i64 = g_report("T06 scopy" as *u8, ok) 61 pass = pass + r6 62 63 total = total + 1 64 let f1: i64 = std_find("k1=7" as *u8, 61) 65 let f2: i64 = std_find("bad" as *u8, 61) 66 ok = 0 67 if f1 == 2 { if f2 == 0 - 1 { ok = 1 } } 68 let r7: i64 = g_report("T07 find+find-NEG" as *u8, ok) 69 pass = pass + r7 70 71 total = total + 1 72 let mb: *u8 = sys_mmap(64) as *u8 73 std_memset(mb, 120, 3) 74 let m0: i64 = mb[0] as i64 75 let m2: i64 = mb[2] as i64 76 let m3: i64 = mb[3] as i64 77 ok = 0 78 if m0 == 120 { if m2 == 120 { if m3 == 0 { ok = 1 } } } 79 let r8: i64 = g_report("T08 memset" as *u8, ok) 80 pass = pass + r8 81 82 total = total + 1 83 let mc: *u8 = sys_mmap(64) as *u8 84 std_memcpy(mc, "abcde" as *u8, 5) 85 mc[5] = 0 as u8 86 let me: i64 = std_streq(mc, "abcde" as *u8) 87 ok = 0 88 if me == 1 { ok = 1 } 89 let r9: i64 = g_report("T09 memcpy" as *u8, ok) 90 pass = pass + r9 91 92 total = total + 1 93 let a1: i64 = std_atoi("42" as *u8) 94 let a2: i64 = std_atoi("-17" as *u8) 95 let a3: i64 = std_atoi("21;rest" as *u8) 96 ok = 0 97 if a1 == 42 { if a2 == 0 - 17 { if a3 == 21 { ok = 1 } } } 98 let r10: i64 = g_report("T10 atoi" as *u8, ok) 99 pass = pass + r10 100 101 total = total + 1 102 let a4: i64 = std_atoi("bad" as *u8) 103 ok = 0 104 if a4 == 0 { ok = 1 } 105 let r11: i64 = g_report("T11 atoi-garbage-NEG" as *u8, ok) 106 pass = pass + r11 107 108 total = total + 1 109 let ib: *u8 = sys_mmap(64) as *u8 110 let il: i64 = std_itoa(0 - 4507, ib) 111 let ie: i64 = std_streq(ib, "-4507" as *u8) 112 let rt: i64 = std_atoi(ib) 113 ok = 0 114 if il == 5 { if ie == 1 { if rt == 0 - 4507 { ok = 1 } } } 115 let r12: i64 = g_report("T12 itoa-atoi-roundtrip" as *u8, ok) 116 pass = pass + r12 117 118 total = total + 1 119 let zb: *u8 = sys_mmap(64) as *u8 120 let zl: i64 = std_itoa(0, zb) 121 let ze: i64 = std_streq(zb, "0" as *u8) 122 ok = 0 123 if zl == 1 { if ze == 1 { ok = 1 } } 124 let r13: i64 = g_report("T13 itoa-zero" as *u8, ok) 125 pass = pass + r13 126 127 std_puts("NX-LIB-STD-GATE " as *u8) 128 std_pdec(pass) 129 std_puts("/" as *u8) 130 std_pdec(total) 131 if pass == total { 132 std_putln(" GREEN" as *u8) 133 sys_exit(0) 134 } 135 std_putln(" RED" as *u8) 136 sys_exit(1) 137 return 0 138}