etag: angstrom parser

This commit is contained in:
swrup 2025-10-06 18:38:04 +02:00
parent e77761d4b3
commit aa1f64fe3e
2 changed files with 63 additions and 38 deletions

View file

@ -37,3 +37,32 @@ let () =
let r = of_string {|+EUR:4.99999999999999999999999|} in
assert (Result.is_error r);
()
let () =
let open Headers_lib.Etag in
let check input = assert (Result.is_ok (parse input)) in
let check_bad input = assert (Result.is_error (parse input)) in
check "*";
check "\"foo\"";
check "W/\"foo\"";
check "\"foo\", \"bar\"";
check " W/\"x\" , W/\"y\" , \"z\" ";
check " \"one\" , \"two\" , \"three\" ";
check "W/\"a\"";
check " W/\"a\" , \"b\"";
check_bad "";
check_bad "foo";
check_bad "W/foo";
check_bad "W/\"unterminated";
check_bad "\"foo\", W/";
check_bad "* , \"bar\"";
check_bad "\"a\" \"b\"";
check_bad "W/\"a\" W/\"b\"";
check_bad "\"fo\x7Fo\"";
(* TODO trailing comma are valid actually, I think *)
check_bad "\"foo\" ,";
check_bad ", \"foo\"";
()