code wiki / (root) / nx_crawl_frontier_test.nx

nx_crawl_frontier_test.nx source

↩ module page · 43 lines · 1477 B

1// nx_crawl_frontier_test.nx -- KAT for outbound-link extraction. 2// Native sovereign lane; exit 0 = pass, N = assertion N failed. 3// Single-quoted attrs in the fixture avoid NishiLang quote-escaping. 4 5import "nx_str.nx" 6import "nx_crawl_frontier.nx" 7 8func main() -> i64 { 9 // 2 absolute http(s) links, 1 relative (must be skipped), 1 exact dup of #1 10 let html: *u8 = "<a href='https://www.imdb.com/name/nm1401531/'>IMDb</a> <a href='http://example.com/page'>x</a> <a href='/relative/path'>rel</a> <a href='https://www.imdb.com/name/nm1401531/'>dup</a>" 11 12 let cap: i64 = 1024 13 let ub: *u8 = sys_mmap(cap) 14 let offs: *i64 = sys_mmap(32 * 8) as *i64 15 let lens: *i64 = sys_mmap(32 * 8) as *i64 16 17 let n: i64 = nx_crawl_extract_links(html, nx_str_len(html), ub, cap, offs, lens, 32) 18 19 // exactly 2 unique absolute links (relative dropped, duplicate collapsed) 20 if n != 2 { return 1 } 21 22 // first link is the imdb url, length 38 23 let imdb: *u8 = "https://www.imdb.com/name/nm1401531/" 24 let ilen: i64 = nx_str_len(imdb) 25 if lens[0] != ilen { return 2 } 26 var k: i64 = 0 27 while k < ilen { 28 if ub[offs[0] + k] != imdb[k] { return 3 } 29 k = k + 1 30 } 31 32 // second link is the example.com url 33 let ex: *u8 = "http://example.com/page" 34 let elen: i64 = nx_str_len(ex) 35 if lens[1] != elen { return 4 } 36 k = 0 37 while k < elen { 38 if ub[offs[1] + k] != ex[k] { return 5 } 39 k = k + 1 40 } 41 42 return 0 43}