code wiki / (root) / runtime_test.nx

runtime_test.nx source

↩ module page · 33 lines · 832 B

1// runtime_test.nx -- self-test for runtime.nx library. 2 3import "runtime.nx" 4 5func main() -> i64 { 6 let s: *u8 = "hello" 7 if strlen(s) != 5 { return 1 } 8 9 let a: *u8 = "abc" 10 let b: *u8 = "abc" 11 let c: *u8 = "abd" 12 if streq(a, b) != 1 { return 2 } 13 if streq(a, c) != 0 { return 3 } 14 15 let n1: *u8 = "42" 16 if atoi(n1) != 42 { return 4 } 17 let n2: *u8 = "-99" 18 if atoi(n2) != -99 { return 5 } 19 20 let buf: *u8 = sys_mmap(32) 21 let ln: i64 = itoa(12345, buf) 22 if ln != 5 { return 6 } 23 if buf[0] != 0x31 { return 7 } 24 if buf[4] != 0x35 { return 8 } 25 if buf[5] != 0 { return 9 } 26 27 let A: *Arena = arena_new(1024) 28 let p1: *u8 = arena_alloc(A, 10) 29 let p2: *u8 = arena_alloc(A, 10) 30 if (p2 as i64) - (p1 as i64) < 10 { return 10 } 31 32 return 0 33}