code wiki / _hdl_build / nx_ims_page_selftest.nx
nx_ims_page_selftest.nx source
↩ module page · 54 lines · 3084 B
1// nx_ims_page_selftest.nx -- smoke test for the reusable generator nx_ims_page.
2// Renders a throwaway page for an EXISTING reachable slug ("nist_stem") so the walk
3// furniture has a real wiki_links.tsv row to read, writes it to /tmp, and asserts the
4// emitted bytes carry the furniture markers + the type label. NOT published. Proves
5// the generator is data-driven (reads wiki_links.tsv + ims_typemap.tsv) and reusable.
6// license_tier: ORIGINAL
7import "nx_ims_page.nx"
8import "nx_syscalls.nx"
9const K_MAGIC_1781800000: i64 = 1781800000
10
11func st_w(s: *u8) -> i64 { var n: i64 = 0; while s[n] != (0 as u8) { n = n + 1 } sys_write(1, s, n); return 0 }
12func st_num(v: i64) -> i64 {
13 let bb: *u8 = sys_mmap(28); var m: i64 = v; if m < 0 { sys_write(1, "-" as *u8, 1); m = 0 - m }
14 let t: *u8 = sys_mmap(28); var k: i64 = 0
15 if m == 0 { t[0] = 48 as u8; k = 1 }
16 while m > 0 { t[k] = (48 + (m % 10)) as u8; m = m / 10; k = k + 1 }
17 var i: i64 = 0; while i < k { bb[i] = t[k - 1 - i]; i = i + 1 }
18 sys_write(1, bb, k); return 0
19}
20// substring search: 1 if needle in hay[0..n], else 0.
21func st_has(hay: *u8, n: i64, needle: *u8) -> i64 {
22 var nl: i64 = 0; while needle[nl] != 0 as u8 { nl = nl + 1 }
23 if nl == 0 { return 1 }
24 var i: i64 = 0
25 while i + nl <= n {
26 var j: i64 = 0; var ok: i64 = 1
27 while j < nl { if hay[i + j] != needle[j] { ok = 0; j = nl } else { j = j + 1 } }
28 if ok == 1 { return 1 }
29 i = i + 1
30 }
31 return 0
32}
33
34func main() -> i64 {
35 let store: *NxWikiDocStore = sh_corpus_store()
36 let h: *u8 = sys_mmap(IP_CAP)
37 let body: *u8 = "<p>Self-test body content for the reusable generator.</p>\n" as *u8
38 let w: i64 = ip_render("nist_stem" as *u8, "howto" as *u8, "IMS Page Self-Test" as *u8, body, K_MAGIC_1781800000, store, h)
39 if w < 0 { st_w("FATAL: ip_render rc="); st_num(w); st_w("\n"); sys_exit(2); return 2 }
40 st_w("ip_render bytes="); st_num(w); st_w("\n")
41
42 var pass: i64 = 0
43 if st_has(h, w, "nx-breadcrumb" as *u8) == 1 { st_w(" furniture breadcrumb PASS\n"); pass = pass + 1 } else { st_w(" breadcrumb FAIL\n") }
44 if st_has(h, w, "nx-tree" as *u8) == 1 { st_w(" furniture tree PASS\n"); pass = pass + 1 } else { st_w(" tree FAIL\n") }
45 if st_has(h, w, "nx-prevnext" as *u8) == 1 { st_w(" furniture prevnext PASS\n"); pass = pass + 1 } else { st_w(" prevnext FAIL\n") }
46 if st_has(h, w, "nx-related" as *u8) == 1 { st_w(" furniture related PASS\n"); pass = pass + 1 } else { st_w(" related FAIL\n") }
47 if st_has(h, w, "How-to guide" as *u8) == 1 { st_w(" typemap label(howto) PASS\n"); pass = pass + 1 } else { st_w(" typemap label FAIL\n") }
48 if st_has(h, w, "id=\"steps\"" as *u8) == 1 { st_w(" steps-layout PASS\n"); pass = pass + 1 } else { st_w(" steps-layout FAIL\n") }
49 if st_has(h, w, "Self-test body content" as *u8) == 1 { st_w(" body-embedded PASS\n"); pass = pass + 1 } else { st_w(" body FAIL\n") }
50
51 st_w("SELFTEST passes="); st_num(pass); st_w("/7\n")
52 if pass == 7 { sys_exit(0); return 0 }
53 sys_exit(1); return 1
54}