nx_decl_base_test.nx source
↩ module page · 77 lines · 2936 B
1// nx_decl_base_test.nx -- smoke for the shared decl base.
2//
3// Verifies:
4// - modifier validity predicate
5// - modifier name reflection
6// - base init success path (valid modifier)
7// - base init failure path (invalid modifier)
8// - hash_mod determinism + spread
9//
10// expect_exit: 0
11//
12// license_tier: ORIGINAL
13
14import "nx_syscalls.nx"
15import "nx_types.nx"
16import "nx_tier.nx"
17import "nx_decl_base.nx"
18
19func main() -> nx_int {
20 // ---- T1: modifier validity --------------------------------
21 if nx_decl_mod_is_valid(NX_DECL_MOD_REAL) != 1 { return 1 }
22 if nx_decl_mod_is_valid(NX_DECL_MOD_FANTASY) != 1 { return 2 }
23 if nx_decl_mod_is_valid(NX_DECL_MOD_SCI_FI) != 1 { return 3 }
24 if nx_decl_mod_is_valid(NX_DECL_MOD_N) != 0 { return 4 }
25 if nx_decl_mod_is_valid(-1) != 0 { return 5 }
26
27 // ---- T2: name reflection ----------------------------------
28 let r: *u8 = nx_decl_mod_name(NX_DECL_MOD_REAL)
29 if (r[0] as i64 & 255) != 82 { return 10 } // 'R'
30 if (r[3] as i64 & 255) != 76 { return 11 } // 'L' (end of "REAL")
31 let f: *u8 = nx_decl_mod_name(NX_DECL_MOD_FANTASY)
32 if (f[0] as i64 & 255) != 70 { return 12 } // 'F'
33 let s: *u8 = nx_decl_mod_name(NX_DECL_MOD_SCI_FI)
34 if (s[0] as i64 & 255) != 83 { return 13 } // 'S'
35
36 // ---- T3: base init success path ---------------------------
37 let b: *NxDeclBase = nx_decl_base_alloc()
38 let ok: nx_int = nx_decl_base_init(b, NX_DECL_MOD_FANTASY, 0xC0FFEE)
39 if ok != 1 { return 20 }
40 if b.is_valid != 1 { return 21 }
41 if b.modifier != NX_DECL_MOD_FANTASY { return 22 }
42 if b.seed != 0xC0FFEE { return 23 }
43
44 // ---- T4: base init failure path ---------------------------
45 let bad: *NxDeclBase = nx_decl_base_alloc()
46 let ko: nx_int = nx_decl_base_init(bad, 999, 0)
47 if ko != 0 { return 30 }
48 if bad.is_valid != 0 { return 31 }
49
50 // ---- T5: hash_mod determinism -----------------------------
51 let h1: nx_int = nx_decl_hash_mod(42, 1, 100)
52 let h2: nx_int = nx_decl_hash_mod(42, 1, 100)
53 if h1 != h2 { return 40 }
54 if h1 < 0 { return 41 }
55 if h1 >= 100 { return 42 }
56
57 // ---- T6: different salts give different results (likely) -
58 let s1: nx_int = nx_decl_hash_mod(42, 1, 1000)
59 let s2: nx_int = nx_decl_hash_mod(42, 2, 1000)
60 // Salt 1 vs 2 with same seed should produce different mod-1000.
61 if s1 == s2 { return 50 }
62
63 // ---- T7: different seeds give different results (likely) --
64 let q1: nx_int = nx_decl_hash_mod(100, 1, 1000)
65 let q2: nx_int = nx_decl_hash_mod(200, 1, 1000)
66 if q1 == q2 { return 60 }
67
68 // ---- T8: print debug line using the base --------------------
69 sys_write(1, "base modifier=" as *u8, 14)
70 let mn: *u8 = nx_decl_mod_name(b.modifier)
71 var i: nx_int = 0
72 while mn[i] != 0 { i = i + 1 }
73 sys_write(1, mn, i)
74 sys_write(1, " is_valid=1\n" as *u8, 12)
75
76 return 0
77}