///|
let truncation_inputs : Array[String] = [
"User-agent: *\nDisallow: /private/\nAllow: /private/public/\n", "User-agent: bot\nDisallow: /a*b$\nSitemap: https://example.test/s.xml\n",
"User-agent: a\nUser-agent: b\nAllow: /x\n\nUser-agent: c\nDisallow: /y\n", "# c\n\nUser-agent: *\nDisallow: /私人/%E2%82%AC\n",
"User-agent: *\nDisallow: /one\nDisallow: /two\nAllow: /two/public\nHost: example.test\n",
]
///|
fn prefix_chars(input : String, n : Int) -> String {
let chars = input.to_array()
let end = if n > chars.length() { chars.length() } else { n }
String::from_array(chars[0:end])
}
///|
test "truncation prefixes never panic for selected inputs" {
let mut cases = 0
for input in truncation_inputs {
for n = 0; n <= input.length(); n = n + 1 {
ignore(parse_robots(prefix_chars(input, n)))
cases = cases + 1
}
}
assert_true(cases > 200)
}