nx_file_result_test.nx source
↩ module page · 32 lines · 1198 B
1// nx_file_result_test.nx -- smoke for Result-wrapped file read.
2
3import "nx_syscalls.nx"
4import "nx_runtime.nx"
5import "nx_tier.nx"
6import "nx_result.nx"
7import "nx_file_result.nx"
8
9func main() -> nx_exit {
10 println("=== nx_file_result smoke ===" as *u8)
11
12 // OK case: an existing file (the QED corpus)
13 let r1: *NxResult = nx_count_lines_result("nxc2/specs/nx_qed_corpus.jsonl" as *u8)
14 if nx_result_is_ok(r1) != 1 {
15 print("FAIL: expected OK on real file; got err=" as *u8)
16 print(nx_err_name(nx_result_err_code(r1))); println("" as *u8)
17 return 1
18 }
19 let n1: nx_int = nx_result_unwrap(r1)
20 print(" count_lines(qed_corpus.jsonl) = " as *u8); print_i64(n1); println("" as *u8)
21 if n1 < 1000 { return 2 }
22
23 // ERR case: a nonexistent file -> NX_ERR_FILE_NOT_FOUND
24 let r2: *NxResult = nx_count_lines_result("/nonexistent/path/xyz.txt" as *u8)
25 if nx_result_is_err(r2) != 1 { return 10 }
26 if nx_result_err_code(r2) != NX_ERR_FILE_NOT_FOUND { return 11 }
27 print(" nonexistent file -> ERR=" as *u8); print(nx_err_name(nx_result_err_code(r2)))
28 println("" as *u8)
29
30 println("=== nx_file_result smoke PASS ===" as *u8)
31 return 0
32}