code wiki / _hdl_build / _pe_blockr_test.nx
_pe_blockr_test.nx source
↩ module page · 30 lines · 1325 B
1// AUTHORED BY THE NISHI BUILDER (pattern: TEMPLATE_TABLE test) -- byte-exact KATs derived from the table
2import "_pe_blockr.nx"
3import "nx_syscalls.nx"
4func _tt_eq(a: *u8, n: i64, b: *u8) -> i64 {
5 var i: i64 = 0
6 while i < n { if a[i] != b[i] { return 0 } i = i + 1 }
7 if b[n] != (0 as u8) { return 0 }
8 return 1
9}
10func main() -> i64 {
11 var bad: i64 = 0
12 let out: *u8 = sys_mmap(8192)
13 var n: i64 = 0
14 n = _pe_blockr_one(1, "x" as *u8, 1, out, 8191)
15 if _tt_eq(out, n, "<div class=\"blk\">x</div>" as *u8) != 1 { bad = bad + 1 }
16 n = _pe_blockr_one(2, "x" as *u8, 1, out, 8191)
17 if _tt_eq(out, n, "<h2>x</h2>" as *u8) != 1 { bad = bad + 1 }
18 n = _pe_blockr_one(2, "<" as *u8, 1, out, 8191)
19 if _tt_eq(out, n, "<h2><</h2>" as *u8) != 1 { bad = bad + 1 }
20 n = _pe_blockr_one(3, "x" as *u8, 1, out, 8191)
21 if _tt_eq(out, n, "<h3>x</h3>" as *u8) != 1 { bad = bad + 1 }
22 n = _pe_blockr_one(4, "x" as *u8, 1, out, 8191)
23 if _tt_eq(out, n, "<blockquote>x</blockquote>" as *u8) != 1 { bad = bad + 1 }
24 n = _pe_blockr_one(5, "x|y" as *u8, 3, out, 8191)
25 if _tt_eq(out, n, "<img src=\"x\" alt=\"y\">" as *u8) != 1 { bad = bad + 1 }
26 if _pe_blockr_one(6, "x" as *u8, 1, out, 8191) + 1 != 0 { bad = bad + 1 }
27 if bad == 0 { sys_exit(0) }
28 sys_exit(1)
29 return 1
30}