Skip to content

Commit c6e9ba7

Browse files
committed
Parser: more tests
1 parent d71418d commit c6e9ba7

File tree

2 files changed

+45
-0
lines changed

2 files changed

+45
-0
lines changed

src/parser/parse_error.ml

Lines changed: 3 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -88,6 +88,9 @@ let language_tag_invalid_char lang_tag : char -> Loc.span -> Warning.t =
8888
let code_block_tag_invalid_char : char -> Loc.span -> Warning.t =
8989
Warning.make "Invalid character in code block metadata tag '%c'."
9090

91+
let invalid_char_code : int -> Loc.span -> Warning.t =
92+
Warning.make "Invalid escape sequence '\\%d"
93+
9194
let truncated_code_block_meta : Loc.span -> Warning.t =
9295
Warning.make ~suggestion:"try '{@ocaml[ ... ]}'." "Missing end of code block."
9396

src/parser/test/test.ml

Lines changed: 42 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -3230,6 +3230,48 @@ let%expect_test _ =
32303230
(warnings ()))
32313231
|}]
32323232

3233+
let empty_key =
3234+
test "{@ocaml =foo [ code ]}";
3235+
[%expect
3236+
{|
3237+
((output
3238+
(((f.ml (1 0) (1 22))
3239+
(code_block (((f.ml (1 2) (1 7)) ocaml) ())
3240+
((f.ml (1 14) (1 20)) " code ")))))
3241+
(warnings
3242+
( "File \"f.ml\", line 1, characters 8-9:\
3243+
\nInvalid character in code block metadata tag '='."
3244+
"File \"f.ml\", line 1, characters 9-14:\
3245+
\nInvalid character in code block metadata tag 'f'.")))
3246+
|}]
3247+
3248+
let no_escape_without_quotes =
3249+
test {|{@ocaml \n\t\b=hello [ code ]}|};
3250+
[%expect
3251+
{|
3252+
((output
3253+
(((f.ml (1 0) (1 30))
3254+
(code_block
3255+
(((f.ml (1 2) (1 7)) ocaml)
3256+
((binding ((f.ml (1 8) (1 14)) "\\n\\t\\b")
3257+
((f.ml (1 15) (1 20)) hello))))
3258+
((f.ml (1 22) (1 28)) " code ")))))
3259+
(warnings ()))
3260+
|}]
3261+
3262+
let escape_within_quotes =
3263+
test {|{@ocaml "\065"=hello [ code ]}|};
3264+
[%expect
3265+
{|
3266+
((output
3267+
(((f.ml (1 0) (1 30))
3268+
(code_block
3269+
(((f.ml (1 2) (1 7)) ocaml)
3270+
((binding ((f.ml (1 9) (1 13)) A) ((f.ml (1 15) (1 20)) hello))))
3271+
((f.ml (1 22) (1 28)) " code ")))))
3272+
(warnings ()))
3273+
|}]
3274+
32333275
let langtag_non_word =
32343276
test "{@ocaml,top[ code ]}";
32353277
[%expect

0 commit comments

Comments
 (0)