nx_layout_default_display_test.nx source
↩ module page · 107 lines · 6457 B
1// nx_layout_default_display_test.nx -- smoke for HTML tag -> default
2// CSS display kind. Exercises representative tags from each kind
3// (BLOCK / INLINE_BLOCK / INLINE) plus case-insensitivity and the
4// h1..h6 family + unknown-tag fallback.
5
6import "nx_syscalls.nx"
7import "nx_layout_box.nx"
8import "nx_layout_default_display.nx"
9
10func _put_byte(buf: *u8, i: i64, v: i64) -> i64 {
11 buf[i] = v as u8
12 return 0
13}
14
15// Write an ASCII literal string into `buf` at `off`. Returns
16// `off + n`.
17func _put_ascii(buf: *u8, off: i64, b0: i64, b1: i64, b2: i64,
18 b3: i64, b4: i64, b5: i64, b6: i64) -> i64 {
19 if b0 >= 0 { _put_byte(buf, off + 0, b0) }
20 if b1 >= 0 { _put_byte(buf, off + 1, b1) }
21 if b2 >= 0 { _put_byte(buf, off + 2, b2) }
22 if b3 >= 0 { _put_byte(buf, off + 3, b3) }
23 if b4 >= 0 { _put_byte(buf, off + 4, b4) }
24 if b5 >= 0 { _put_byte(buf, off + 5, b5) }
25 if b6 >= 0 { _put_byte(buf, off + 6, b6) }
26 return off + 7
27}
28
29func main() -> i64 {
30 let src: *u8 = (sys_mmap(256)) as *u8
31
32 // Tag fixtures laid out at 8-byte stride to avoid arithmetic
33 // bookkeeping inside the test:
34 // [ 0] "p" BLOCK
35 // [ 8] "h1" BLOCK
36 // [ 16] "h6" BLOCK
37 // [ 24] "div" BLOCK
38 // [ 32] "body" BLOCK
39 // [ 40] "header" BLOCK
40 // [ 48] "article" BLOCK
41 // [ 56] "section" BLOCK
42 // [ 64] "img" INLINE_BLOCK
43 // [ 72] "INPUT" INLINE_BLOCK (upper-case proves case-insensitivity)
44 // [ 80] "button" INLINE_BLOCK
45 // [ 88] "span" INLINE
46 // [ 96] "a" INLINE
47 // [104] "em" INLINE
48 // [112] "strong" INLINE
49 // [120] "h7" INLINE (out of h-family range -> fallback)
50 // [128] "unknown" INLINE (fallback)
51 // [136] "" INLINE (empty -> fallback)
52 // [144] "DIV" BLOCK (upper-case -> case-insensitive lookup)
53 // [152] "Header" BLOCK (mixed-case)
54
55 _put_byte(src, 0, 112) // "p"
56 _put_byte(src, 8, 104) _put_byte(src, 9, 49) // "h1"
57 _put_byte(src, 16, 104) _put_byte(src, 17, 54) // "h6"
58 _put_byte(src, 24, 100) _put_byte(src, 25, 105) _put_byte(src, 26, 118) // "div"
59 _put_byte(src, 32, 98) _put_byte(src, 33, 111) _put_byte(src, 34, 100) _put_byte(src, 35, 121) // "body"
60 _put_byte(src, 40, 104) _put_byte(src, 41, 101) _put_byte(src, 42, 97) _put_byte(src, 43, 100) _put_byte(src, 44, 101) _put_byte(src, 45, 114) // "header"
61 _put_byte(src, 48, 97) _put_byte(src, 49, 114) _put_byte(src, 50, 116) _put_byte(src, 51, 105) _put_byte(src, 52, 99) _put_byte(src, 53, 108) _put_byte(src, 54, 101) // "article"
62 _put_byte(src, 56, 115) _put_byte(src, 57, 101) _put_byte(src, 58, 99) _put_byte(src, 59, 116) _put_byte(src, 60, 105) _put_byte(src, 61, 111) _put_byte(src, 62, 110) // "section"
63 _put_byte(src, 64, 105) _put_byte(src, 65, 109) _put_byte(src, 66, 103) // "img"
64 _put_byte(src, 72, 73) _put_byte(src, 73, 78) _put_byte(src, 74, 80) _put_byte(src, 75, 85) _put_byte(src, 76, 84) // "INPUT"
65 _put_byte(src, 80, 98) _put_byte(src, 81, 117) _put_byte(src, 82, 116) _put_byte(src, 83, 116) _put_byte(src, 84, 111) _put_byte(src, 85, 110) // "button"
66 _put_byte(src, 88, 115) _put_byte(src, 89, 112) _put_byte(src, 90, 97) _put_byte(src, 91, 110) // "span"
67 _put_byte(src, 96, 97) // "a"
68 _put_byte(src, 104, 101) _put_byte(src, 105, 109) // "em"
69 _put_byte(src, 112, 115) _put_byte(src, 113, 116) _put_byte(src, 114, 114) _put_byte(src, 115, 111) _put_byte(src, 116, 110) _put_byte(src, 117, 103) // "strong"
70 _put_byte(src, 120, 104) _put_byte(src, 121, 55) // "h7"
71 _put_byte(src, 128, 117) _put_byte(src, 129, 110) _put_byte(src, 130, 107) _put_byte(src, 131, 110) _put_byte(src, 132, 111) _put_byte(src, 133, 119) _put_byte(src, 134, 110) // "unknown"
72 _put_byte(src, 144, 68) _put_byte(src, 145, 73) _put_byte(src, 146, 86) // "DIV"
73 _put_byte(src, 152, 72) _put_byte(src, 153, 101) _put_byte(src, 154, 97) _put_byte(src, 155, 100) _put_byte(src, 156, 101) _put_byte(src, 157, 114) // "Header"
74
75 // ---- BLOCK assertions ----
76 if nx_layout_default_display(src, 0, 1) != NX_LAYOUT_BOX_BLOCK { return 1 } // p
77 if nx_layout_default_display(src, 8, 2) != NX_LAYOUT_BOX_BLOCK { return 2 } // h1
78 if nx_layout_default_display(src, 16, 2) != NX_LAYOUT_BOX_BLOCK { return 3 } // h6
79 if nx_layout_default_display(src, 24, 3) != NX_LAYOUT_BOX_BLOCK { return 4 } // div
80 if nx_layout_default_display(src, 32, 4) != NX_LAYOUT_BOX_BLOCK { return 5 } // body
81 if nx_layout_default_display(src, 40, 6) != NX_LAYOUT_BOX_BLOCK { return 6 } // header
82 if nx_layout_default_display(src, 48, 7) != NX_LAYOUT_BOX_BLOCK { return 7 } // article
83 if nx_layout_default_display(src, 56, 7) != NX_LAYOUT_BOX_BLOCK { return 8 } // section
84
85 // ---- INLINE_BLOCK assertions ----
86 if nx_layout_default_display(src, 64, 3) != NX_LAYOUT_BOX_INLINE_BLOCK { return 20 } // img
87 if nx_layout_default_display(src, 72, 5) != NX_LAYOUT_BOX_INLINE_BLOCK { return 21 } // INPUT (upper)
88 if nx_layout_default_display(src, 80, 6) != NX_LAYOUT_BOX_INLINE_BLOCK { return 22 } // button
89
90 // ---- INLINE assertions (default) ----
91 if nx_layout_default_display(src, 88, 4) != NX_LAYOUT_BOX_INLINE { return 30 } // span
92 if nx_layout_default_display(src, 96, 1) != NX_LAYOUT_BOX_INLINE { return 31 } // a
93 if nx_layout_default_display(src, 104, 2) != NX_LAYOUT_BOX_INLINE { return 32 } // em
94 if nx_layout_default_display(src, 112, 6) != NX_LAYOUT_BOX_INLINE { return 33 } // strong
95
96 // ---- Fallback / edge cases ----
97 if nx_layout_default_display(src, 120, 2) != NX_LAYOUT_BOX_INLINE { return 40 } // h7 (out of family)
98 if nx_layout_default_display(src, 128, 7) != NX_LAYOUT_BOX_INLINE { return 41 } // unknown
99 if nx_layout_default_display(src, 0, 0) != NX_LAYOUT_BOX_INLINE { return 42 } // empty
100 if nx_layout_default_display(src, 0, -1) != NX_LAYOUT_BOX_INLINE { return 43 } // negative len
101
102 // ---- Case-insensitivity ----
103 if nx_layout_default_display(src, 144, 3) != NX_LAYOUT_BOX_BLOCK { return 50 } // DIV
104 if nx_layout_default_display(src, 152, 6) != NX_LAYOUT_BOX_BLOCK { return 51 } // Header
105
106 return 0
107}