nx_html_emit_test.nx source
↩ module page · 65 lines · 1929 B
1// nx_html_emit_test.nx -- HTML5 writer shape verification.
2//
3// Writes to fd=1 (stdout) so the smoke captures the rendered output.
4// Assertions verify return codes from the API calls + a simple
5// end-to-end render that any browser will load.
6
7import "nx_syscalls.nx"
8import "nx_runtime.nx"
9import "nx_tier.nx"
10import "nx_html_emit.nx"
11
12func main() -> nx_int {
13 let fd: nx_int = 1
14
15 // ===== Full document end-to-end ==============================
16 nx_html_doc_open(fd, "Batch 42 -- live-fire audit")
17 nx_html_h1(fd, "Pool utilization")
18 nx_html_p(fd, "Substrate audit of arc + outfit + pose pools.")
19
20 nx_html_table_open(fd)
21 nx_html_thead_open(fd)
22 nx_html_th(fd, "Scene")
23 nx_html_th(fd, "Outfit")
24 nx_html_th(fd, "Pose")
25 nx_html_th(fd, "Verdict")
26 nx_html_thead_close(fd)
27
28 nx_html_tr_open(fd)
29 nx_html_td_int(fd, 1)
30 nx_html_td_int(fd, 200)
31 nx_html_td_int(fd, 300)
32 nx_html_td_text(fd, "consistent")
33 nx_html_tr_close(fd)
34
35 nx_html_tr_open(fd)
36 nx_html_td_int(fd, 2)
37 nx_html_td_int(fd, 200)
38 nx_html_td_int(fd, 300)
39 nx_html_td_text(fd, "consistent")
40 nx_html_tr_close(fd)
41
42 nx_html_table_close(fd)
43
44 nx_html_h2(fd, "Verdict bands")
45 nx_html_badge(fd, NX_HTML_BADGE_GOOD, "GOOD" as *u8)
46 nx_html_badge(fd, NX_HTML_BADGE_DRIFT, "DRIFT" as *u8)
47 nx_html_badge(fd, NX_HTML_BADGE_BROKEN, "BROKEN" as *u8)
48 nx_html_p(fd, "")
49
50 nx_html_h2(fd, "Span dump")
51 nx_html_pre_open(fd)
52 _html_write_z(fd, "{\"trace\":42,\"kind\":13}" as *u8)
53 nx_html_pre_close(fd)
54
55 // ===== Test escaping (& < > ") ===============================
56 //
57 // Verify all four escape paths fire. Returning 0 from the
58 // escaper is success; failure would be a write-error rc.
59 let rc1: nx_int = _html_write_escaped_z(fd, "<>&\"" as *u8)
60 if rc1 != 4 { return 1 } // 4 bytes of input
61
62 nx_html_doc_close(fd)
63
64 return 0
65}