nx_search_extern_gate.nx source
↩ module page · 40 lines · 2660 B
1// nx_search_extern_gate.nx -- deterministic parser gate for the external-search federator (NO network: the
2// live fetch is proven by running the organ; this locks the arXiv/GitHub response PARSING so a regression is
3// caught reproducibly). Imports the federator (main stripped) + drives its pure parse fns.
4import "nx_search_extern.nx"
5import "nx_syscalls.nx"
6
7func gp(s: *u8) -> i64 { var n: i64=0; while s[n]!=(0 as u8){n=n+1} sys_write(1,s,n); return 0 }
8func gnum(v: i64) -> i64 { if v==0 { sys_write(1,"0" as *u8,1); return 0 } var m: i64=v; if m<0 { sys_write(1,"-" as *u8,1); m=0-m } let t: *u8=sys_mmap(28); var k: i64=0; while m>0 { t[k]=(48+(m%10)) as u8; m=m/10; k=k+1 } while k>0 { k=k-1; sys_write(1,(((t as i64)+k) as *u8),1) } return 0 }
9func glen(s: *u8) -> i64 { var n: i64=0; while s[n]!=(0 as u8){n=n+1} return n }
10func chk(name: *u8, got: i64, want: i64, pass: *i64, fail: *i64) -> i64 {
11 if got==want { pass[0]=pass[0]+1; gp(" ok " as *u8) } else { fail[0]=fail[0]+1; gp(" FAIL " as *u8) }
12 gp(name); gp(" got=" as *u8); gnum(got); gp(" want=" as *u8); gnum(want); gp("\n" as *u8)
13 return 0
14}
15
16func main() -> i64 {
17 gp("=== nx_search_extern_gate ===\n" as *u8)
18 let pass: *i64=sys_mmap(16) as *i64; let fail: *i64=sys_mmap(16) as *i64; pass[0]=0; fail[0]=0
19
20 // canned arXiv Atom: a feed <title> then 2 entries each with a <title>
21 let arx: *u8="<feed><title>arXiv Query</title><entry><title>Photonic Neural Nets</title></entry><entry><title>Quantum Walks</title></entry></feed>" as *u8
22 let al: i64=glen(arx)
23 chk("T1 arxiv entries==2" as *u8, se_count(arx, al, "<entry>" as *u8), 2, pass, fail)
24 // se_spans skips the feed title (skip=1), prints the 2 entry titles -> returns 2
25 gp(" (arxiv titles:)\n" as *u8)
26 chk("T2 arxiv titles printed==2" as *u8, se_spans(arx, al, "<title>" as *u8, 60, 4, 1), 2, pass, fail)
27
28 // canned GitHub JSON: 2 repo full_names
29 let gh: *u8="{\"items\":[{\"full_name\": \"laserlab/CountingPhotons\"},{\"full_name\": \"griffith/onn-sim\"}]}" as *u8
30 let gl: i64=glen(gh)
31 chk("T3 github repos==2" as *u8, se_count(gh, gl, "\"full_name\"" as *u8), 2, pass, fail)
32 gp(" (github repos:)\n" as *u8)
33 chk("T4 github names printed==2" as *u8, se_spans(gh, gl, "\"full_name\": \"" as *u8, 34, 4, 0), 2, pass, fail)
34
35 chk("T5 count-no-match==0" as *u8, se_count(arx, al, "zzz_absent" as *u8), 0, pass, fail)
36
37 gp("\n-- RESULT pass=" as *u8); gnum(pass[0]); gp(" fail=" as *u8); gnum(fail[0]); gp("\n" as *u8)
38 if fail[0]==0 { gp("GATE verdict=GREEN\n" as *u8); sys_exit(0) } else { gp("GATE verdict=RED\n" as *u8); sys_exit(1) }
39 return 0
40}