Skip to content

Commit

Permalink
Get coverage back to 100%
Browse files Browse the repository at this point in the history
  • Loading branch information
aantron committed Jul 25, 2024
1 parent 17c5809 commit e3d6cbb
Show file tree
Hide file tree
Showing 2 changed files with 33 additions and 1 deletion.
2 changes: 1 addition & 1 deletion src/soup.ml
Original file line number Diff line number Diff line change
Expand Up @@ -729,7 +729,7 @@ struct
begin match Stream.peek stream with
| Some '\\' -> ()
| Some c when is_identifier_char c -> ()
| _ -> parse_error "expected an identifier"
| _ -> (parse_error [@coverage off]) "expected an identifier"
end;
let rec loop () =
match Stream.peek stream with
Expand Down
32 changes: 32 additions & 0 deletions test/test.ml
Original file line number Diff line number Diff line change
Expand Up @@ -258,6 +258,30 @@ let suites = [
test "[foo&=bar]" "invalid attribute operator '&='";
);

("from_signals" >:: fun _ ->
let soup =
[
`Start_element (("", "p"), []);
`Text ["a "];
`Start_element (("", "em"), []);
`Text ["b"];
`End_element;
`Text [" c "];
`Start_element (("", "em"), [("", "class"), "foo"]);
`Text ["d"];
`End_element;
`Text [" e"];
`End_element;
]
|> Markup.of_list
|> from_signals
in
assert_equal (soup $$ ".foo" |> count) 1;
assert_equal (soup $ ".foo" |> name) "em";
assert_equal (soup $ ".foo" |> leaf_text) (Some "d");
assert_equal (soup |> texts |> String.concat "") "a b c d e";
);

("generalized-select" >:: fun _ ->
let soup = page "list" |> parse in
let test root selector expected_count =
Expand Down Expand Up @@ -761,7 +785,9 @@ let suites = [
set_attribute "id" "foo" element;
set_attribute "class" "foo bar" element;

assert_bool "not is_document" (is_document element |> not);
assert_bool "is_element" (is_element element);
assert_bool "not is_text" (is_text element |> not);
assert_equal (name element) "p";

set_name "li" element;
Expand All @@ -777,7 +803,10 @@ let suites = [
("create_text" >:: fun _ ->
let node = create_text "foo" in

assert_bool "not is_document" (is_document node |> not);
assert_bool "not is_element" (is_element node |> not);
assert_bool "is_text" (is_text node);

assert_equal (node |> leaf_text) (Some "foo");
assert_equal (node |> texts) ["foo"];
assert_equal (node |> parent) None;
Expand All @@ -786,7 +815,10 @@ let suites = [
("create_soup" >:: fun _ ->
let soup = create_soup () in

assert_bool "is_document" (is_document soup);
assert_bool "not is_element" (is_element soup |> not);
assert_bool "not is_text" (is_text soup |> not);

assert_equal (soup |> children |> count) 0);

("create_element-fancy" >:: fun _ ->
Expand Down

0 comments on commit e3d6cbb

Please sign in to comment.