code wiki / (root) / nx_robots_test.nx

nx_robots_test.nx source

↩ module page · 28 lines · 1513 B

1// nx_robots_test.nx -- KAT for the RFC 9309 robots.txt matcher. 2// Native sovereign lane; exit 0 = pass, N = assertion N failed. 3 4import "nx_str.nx" 5import "nx_robots.nx" 6 7func main() -> i64 { 8 let robots: *u8 = "User-agent: BadBot\nDisallow: /\n\nUser-agent: *\nDisallow: /private\nDisallow: /tmp\nAllow: /private/public\nCrawl-delay: 3\n" 9 let rlen: i64 = nx_str_len(robots) 10 let ua: *u8 = "NishiBot" 11 let ual: i64 = nx_str_len(ua) 12 13 // NishiBot has no specific group -> uses '*' group 14 if nx_robots_allowed(robots, rlen, ua, ual, "/private", 8) != 0 { return 1 } // disallowed 15 if nx_robots_allowed(robots, rlen, ua, ual, "/private/public", 15) != 1 { return 2 } // Allow (longer) wins 16 if nx_robots_allowed(robots, rlen, ua, ual, "/tmp", 4) != 0 { return 3 } // disallowed 17 if nx_robots_allowed(robots, rlen, ua, ual, "/about", 6) != 1 { return 4 } // no rule -> allowed 18 if nx_robots_allowed(robots, rlen, ua, ual, "/", 1) != 1 { return 5 } // no rule prefixes "/" 19 if nx_robots_crawl_delay(robots, rlen, ua, ual) != 3 { return 6 } // from '*' group 20 21 // BadBot has a SPECIFIC group (Disallow: /) -> everything disallowed 22 let bb: *u8 = "BadBot" 23 let bbl: i64 = nx_str_len(bb) 24 if nx_robots_allowed(robots, rlen, bb, bbl, "/anything", 9) != 0 { return 7 } 25 if nx_robots_allowed(robots, rlen, bb, bbl, "/private/public", 15) != 0 { return 8 } // specific group ignores '*' 26 27 return 0 28}