···11-open Bytesrw
22-33-module Parser = Html5rw_parser
44-module Dom = Html5rw_dom
55-66-let () =
77- print_endline "=== Test: &AMp; ===";
88- let input = "&AMp;" in
99- print_endline ("Input: " ^ input);
1010- let result = Parser.parse ~collect_errors:true (Bytes.Reader.of_string input) in
1111- print_endline "Result:";
1212- print_endline (Dom.to_test_format (Parser.root result));
1313- print_endline "";
1414-1515- print_endline "=== Test: & ===";
1616- let input = "&" in
1717- print_endline ("Input: " ^ input);
1818- let result = Parser.parse ~collect_errors:true (Bytes.Reader.of_string input) in
1919- print_endline "Result:";
2020- print_endline (Dom.to_test_format (Parser.root result))
-28
test/entity_test.ml
···11-open Bytesrw
22-33-module Parser = Html5rw_parser
44-module Dom = Html5rw_dom
55-66-let () =
77- print_endline "=== Test 1: Single & ===";
88- let input = "&" in
99- print_endline ("Input: " ^ input);
1010- let result = Parser.parse ~collect_errors:true (Bytes.Reader.of_string input) in
1111- print_endline "Result:";
1212- print_endline (Dom.to_test_format (Parser.root result));
1313- print_endline "";
1414-1515- print_endline "=== Test 2: - (decimal ref) ===";
1616- let input = "-" in
1717- print_endline ("Input: " ^ input);
1818- let result = Parser.parse ~collect_errors:true (Bytes.Reader.of_string input) in
1919- print_endline "Result:";
2020- print_endline (Dom.to_test_format (Parser.root result));
2121- print_endline "";
2222-2323- print_endline "=== Test 3: &#X (hex ref incomplete) ===";
2424- let input = "&#X" in
2525- print_endline ("Input: " ^ input);
2626- let result = Parser.parse ~collect_errors:true (Bytes.Reader.of_string input) in
2727- print_endline "Result:";
2828- print_endline (Dom.to_test_format (Parser.root result))
-39
test/frag_debug.ml
···11-open Bytesrw
22-33-module Parser = Html5rw_parser
44-55-let () =
66- (* Test 77 - template with adoption agency *)
77- print_endline "=== Template test 77 ===";
88- print_endline "Input: <body><template><i><menu>Foo</i>";
99- let result = Html5rw_parser.parse (Bytes.Reader.of_string "<body><template><i><menu>Foo</i>") in
1010- print_endline "Actual:";
1111- print_endline (Html5rw_dom.to_test_format (Parser.root result));
1212- print_newline ();
1313-1414- (* Simpler test - just template with content *)
1515- print_endline "=== Simpler template test ===";
1616- print_endline "Input: <template><i>X</i></template>";
1717- let result = Html5rw_parser.parse (Bytes.Reader.of_string "<template><i>X</i></template>") in
1818- print_endline (Html5rw_dom.to_test_format (Parser.root result));
1919- print_newline ();
2020-2121- (* Test without template *)
2222- print_endline "=== Without template ===";
2323- print_endline "Input: <i><menu>Foo</i>";
2424- let result = Html5rw_parser.parse (Bytes.Reader.of_string "<i><menu>Foo</i>") in
2525- print_endline (Html5rw_dom.to_test_format (Parser.root result));
2626- print_newline ();
2727-2828- (* Test 31 - foreignObject/math *)
2929- print_endline "=== Test 31 - foreignObject ===";
3030- print_endline "Input: <div><svg><path><foreignObject><math></div>a";
3131- let result = Html5rw_parser.parse (Bytes.Reader.of_string "<div><svg><path><foreignObject><math></div>a") in
3232- print_endline (Html5rw_dom.to_test_format (Parser.root result));
3333- print_newline ();
3434-3535- (* namespace-sensitivity test *)
3636- print_endline "=== Namespace sensitivity ===";
3737- print_endline "Input: <body><table><tr><td><svg><td><foreignObject><span></td>Foo";
3838- let result = Html5rw_parser.parse (Bytes.Reader.of_string "<body><table><tr><td><svg><td><foreignObject><span></td>Foo") in
3939- print_endline (Html5rw_dom.to_test_format (Parser.root result))
-40
test/frag_debug2.ml
···11-open Bytesrw
22-33-module Parser = Html5rw_parser
44-55-let () =
66- (* Test: svg end tag handling *)
77- print_endline "=== Test: <div><svg></div> ===";
88- let result = Html5rw_parser.parse (Bytes.Reader.of_string "<div><svg></div>") in
99- print_endline (Html5rw_dom.to_test_format (Parser.root result));
1010- print_newline ();
1111-1212- (* Test: foreignObject text integration *)
1313- print_endline "=== Test: <div><svg><foreignObject></div> ===";
1414- let result = Html5rw_parser.parse (Bytes.Reader.of_string "<div><svg><foreignObject></div>") in
1515- print_endline (Html5rw_dom.to_test_format (Parser.root result));
1616- print_newline ();
1717-1818- (* Test: math inside foreignObject with end tag *)
1919- print_endline "=== Test: <div><svg><foreignObject><math></div>a ===";
2020- let result = Html5rw_parser.parse (Bytes.Reader.of_string "<div><svg><foreignObject><math></div>a") in
2121- print_endline (Html5rw_dom.to_test_format (Parser.root result));
2222- print_newline ();
2323-2424- (* Without path element *)
2525- print_endline "=== Test: <div><svg><foreignObject><b></div>text ===";
2626- let result = Html5rw_parser.parse (Bytes.Reader.of_string "<div><svg><foreignObject><b></div>text") in
2727- print_endline (Html5rw_dom.to_test_format (Parser.root result));
2828- print_newline ();
2929-3030- (* Template adoption agency test *)
3131- print_endline "=== Test: <template><b><menu>text</b> ===";
3232- let result = Html5rw_parser.parse (Bytes.Reader.of_string "<template><b><menu>text</b>") in
3333- print_endline (Html5rw_dom.to_test_format (Parser.root result));
3434- print_newline ();
3535-3636- (* Without template for comparison *)
3737- print_endline "=== Test: <b><menu>text</b> (no template) ===";
3838- let result = Html5rw_parser.parse (Bytes.Reader.of_string "<b><menu>text</b>") in
3939- print_endline (Html5rw_dom.to_test_format (Parser.root result));
4040- print_newline ()
-34
test/frag_debug3.ml
···11-open Bytesrw
22-33-module Parser = Html5rw_parser
44-55-let () =
66- (* Simple svg with child *)
77- print_endline "=== Test: <svg><path></path></svg>text ===";
88- let result = Html5rw_parser.parse (Bytes.Reader.of_string "<svg><path></path></svg>text") in
99- print_endline (Html5rw_dom.to_test_format (Parser.root result));
1010- print_newline ();
1111-1212- (* The failing test - foreignObject inside svg *)
1313- print_endline "=== Test: <div><svg><path><foreignObject><math></div>a ===";
1414- let result = Html5rw_parser.parse (Bytes.Reader.of_string "<div><svg><path><foreignObject><math></div>a") in
1515- print_endline (Html5rw_dom.to_test_format (Parser.root result));
1616- print_newline ();
1717-1818- (* Expected output for test 31:
1919- <html>
2020- <head>
2121- <body>
2222- <div>
2323- <svg svg>
2424- <svg path>
2525- <svg foreignObject>
2626- <math math>
2727- "a"
2828- *)
2929-3030- (* Simple svg structure *)
3131- print_endline "=== Test: <svg><rect/><circle/></svg> ===";
3232- let result = Html5rw_parser.parse (Bytes.Reader.of_string "<svg><rect/><circle/></svg>") in
3333- print_endline (Html5rw_dom.to_test_format (Parser.root result));
3434- print_newline ()
-10
test/html_frag_test.ml
···11-open Bytesrw
22-33-module Parser = Html5rw_parser
44-module Dom = Html5rw_dom
55-66-let () =
77- let input = "Hello" in
88- let context = Parser.make_fragment_context ~tag_name:"div" () in
99- let result = Parser.parse ~collect_errors:true ~fragment_context:context (Bytes.Reader.of_string input) in
1010- print_endline (Dom.to_test_format (Parser.root result))
-22
test/nobr_debug.ml
···11-open Bytesrw
22-33-module Parser = Html5rw_parser
44-module Dom = Html5rw_dom
55-66-let rec print_tree indent node =
77- Printf.printf "%s%s (ns=%s, %d children)\n"
88- indent
99- node.Dom.name
1010- (match node.Dom.namespace with Some s -> s | None -> "html")
1111- (List.length node.Dom.children);
1212- List.iter (print_tree (indent ^ " ")) node.Dom.children
1313-1414-let () =
1515- let input = "<nobr>X" in
1616- print_endline "Starting...";
1717- let context = Parser.make_fragment_context ~tag_name:"path" ~namespace:(Some "svg") () in
1818- let result = Parser.parse ~collect_errors:true ~fragment_context:context (Bytes.Reader.of_string input) in
1919- print_endline "\nFinal tree structure:";
2020- print_tree "" (Parser.root result);
2121- print_endline "\nTest format:";
2222- print_endline (Dom.to_test_format (Parser.root result))
-29
test/nobr_debug2.ml
···11-(*---------------------------------------------------------------------------
22- Copyright (c) 2025 Anil Madhavapeddy <anil@recoil.org>. All rights reserved.
33- SPDX-License-Identifier: MIT
44- ---------------------------------------------------------------------------*)
55-66-(* Test nobr element handling in SVG fragment context *)
77-88-open Bytesrw
99-1010-module Parser = Html5rw_parser
1111-module Dom = Html5rw_dom
1212-1313-let rec print_tree indent node =
1414- Printf.printf "%s%s (ns=%s, %d children)\n"
1515- indent
1616- node.Dom.name
1717- (match node.Dom.namespace with Some s -> s | None -> "html")
1818- (List.length node.Dom.children);
1919- List.iter (print_tree (indent ^ " ")) node.Dom.children
2020-2121-let () =
2222- let input = "<nobr>X" in
2323- print_endline "Starting...";
2424- let context = Parser.make_fragment_context ~tag_name:"path" ~namespace:(Some "svg") () in
2525- let result = Parser.parse ~collect_errors:true ~fragment_context:context (Bytes.Reader.of_string input) in
2626- print_endline "\nFinal tree structure:";
2727- print_tree "" (Parser.root result);
2828- print_endline "\nTest format:";
2929- print_endline (Dom.to_test_format (Parser.root result))
-13
test/nobr_test.ml
···11-open Bytesrw
22-33-module Parser = Html5rw_parser
44-module Dom = Html5rw_dom
55-66-let () =
77- let input = "<nobr>X" in
88- print_endline "Starting...";
99- let context = Parser.make_fragment_context ~tag_name:"path" ~namespace:(Some "svg") () in
1010- print_endline "Created context";
1111- let result = Parser.parse ~collect_errors:true ~fragment_context:context (Bytes.Reader.of_string input) in
1212- print_endline "Parsed";
1313- print_endline (Dom.to_test_format (Parser.root result))
-35
test/ns_sens_test.ml
···11-open Bytesrw
22-33-module Parser = Html5rw_parser
44-55-let () =
66- print_endline "=== Test: <body><table><tr><td><svg><td><foreignObject><span></td>Foo ===";
77- let result = Html5rw_parser.parse (Bytes.Reader.of_string "<body><table><tr><td><svg><td><foreignObject><span></td>Foo") in
88- print_endline (Html5rw_dom.to_test_format (Parser.root result));
99- print_newline ();
1010-1111- (* Expected:
1212- <html>
1313- <head>
1414- <body>
1515- "Foo"
1616- <table>
1717- <tbody>
1818- <tr>
1919- <td>
2020- <svg svg>
2121- <svg td>
2222- <svg foreignObject>
2323- <span>
2424- *)
2525-2626- (* Let's also test simpler case *)
2727- print_endline "=== Test: <table><td><svg><foreignObject></td>text ===";
2828- let result = Html5rw_parser.parse (Bytes.Reader.of_string "<table><td><svg><foreignObject></td>text") in
2929- print_endline (Html5rw_dom.to_test_format (Parser.root result));
3030- print_newline ();
3131-3232- print_endline "=== Test: <table><td></td>text ===";
3333- let result = Html5rw_parser.parse (Bytes.Reader.of_string "<table><td></td>text") in
3434- print_endline (Html5rw_dom.to_test_format (Parser.root result));
3535- print_newline ()
-10
test/quick_test.ml
···11-open Bytesrw
22-33-module Parser = Html5rw_parser
44-module Dom = Html5rw_dom
55-66-let () =
77- let input = "<nobr>X" in
88- let context = Parser.make_fragment_context ~tag_name:"path" ~namespace:(Some "svg") () in
99- let result = Parser.parse ~collect_errors:true ~fragment_context:context (Bytes.Reader.of_string input) in
1010- print_endline (Dom.to_test_format (Parser.root result))
-22
test/script_attr_test.ml
···11-open Bytesrw
22-33-module Parser = Html5rw_parser
44-module Dom = Html5rw_dom
55-66-let () =
77- (* Test incomplete script tag with attribute *)
88- let input = "<!doctypehtml><scrIPt type=text/x-foobar;baz>X</SCRipt" in
99- print_endline "=== Test: script tag with attribute at incomplete end ===";
1010- print_endline ("Input: " ^ input);
1111- let result = Parser.parse ~collect_errors:true (Bytes.Reader.of_string input) in
1212- print_endline "Result:";
1313- print_endline (Dom.to_test_format (Parser.root result));
1414- print_endline "";
1515-1616- (* Test simpler case *)
1717- let input = "<script type=text>X</script>" in
1818- print_endline "=== Test: Complete script tag with attribute ===";
1919- print_endline ("Input: " ^ input);
2020- let result = Parser.parse ~collect_errors:true (Bytes.Reader.of_string input) in
2121- print_endline "Result:";
2222- print_endline (Dom.to_test_format (Parser.root result))
-12
test/script_eof_test.ml
···11-open Bytesrw
22-33-module Parser = Html5rw_parser
44-module Dom = Html5rw_dom
55-66-let () =
77- (* Test incomplete script tag *)
88- let input = "<!doctype html><script><" in
99- print_endline ("Input: " ^ input);
1010- let result = Parser.parse ~collect_errors:true (Bytes.Reader.of_string input) in
1111- print_endline "Result:";
1212- print_endline (Dom.to_test_format (Parser.root result))
-13
test/select_debug.ml
···11-open Bytesrw
22-33-module Parser = Html5rw_parser
44-module Dom = Html5rw_dom
55-66-let () =
77- let input = "<select><b><option><select><option></b></select>X" in
88- print_endline "Input:";
99- print_endline input;
1010- print_endline "";
1111- let result = Parser.parse ~collect_errors:true (Bytes.Reader.of_string input) in
1212- print_endline "Result:";
1313- print_endline (Dom.to_test_format (Parser.root result))
-9
test/simple_test.ml
···11-open Bytesrw
22-33-module Parser = Html5rw_parser
44-module Dom = Html5rw_dom
55-66-let () =
77- let input = "<p>Hello</p>" in
88- let result = Parser.parse ~collect_errors:true (Bytes.Reader.of_string input) in
99- print_endline (Dom.to_test_format (Parser.root result))
-13
test/svg_frag_test.ml
···11-open Bytesrw
22-33-module Parser = Html5rw_parser
44-module Dom = Html5rw_dom
55-66-let () =
77- let input = "Hello" in
88- print_endline "Starting...";
99- let context = Parser.make_fragment_context ~tag_name:"path" ~namespace:(Some "svg") () in
1010- print_endline "Created context";
1111- let result = Parser.parse ~collect_errors:true ~fragment_context:context (Bytes.Reader.of_string input) in
1212- print_endline "Parsed";
1313- print_endline (Dom.to_test_format (Parser.root result))
-21
test/template_debug.ml
···11-open Bytesrw
22-33-module Parser = Html5rw_parser
44-module Dom = Html5rw_dom
55-66-let () =
77- (* Template test 45: div inside tr inside template *)
88- let input1 = "<body><template><tr><div></div></tr></template>" in
99- print_endline "=== Test 1 ===";
1010- print_endline ("Input: " ^ input1);
1111- let result1 = Parser.parse ~collect_errors:true (Bytes.Reader.of_string input1) in
1212- print_endline "Result:";
1313- print_endline (Dom.to_test_format (Parser.root result1));
1414-1515- (* Template test 91: select inside tbody inside nested template *)
1616- let input2 = "<template><template><tbody><select>" in
1717- print_endline "\n=== Test 2 ===";
1818- print_endline ("Input: " ^ input2);
1919- let result2 = Parser.parse ~collect_errors:true (Bytes.Reader.of_string input2) in
2020- print_endline "Result:";
2121- print_endline (Dom.to_test_format (Parser.root result2))
-13
test/template_debug2.ml
···11-open Bytesrw
22-33-module Parser = Html5rw_parser
44-module Dom = Html5rw_dom
55-66-let () =
77- (* Test i then menu in template *)
88- let input = "<template><i><menu>Foo" in
99- print_endline "=== Test: i then menu in template ===";
1010- print_endline ("Input: " ^ input);
1111- let result = Parser.parse ~collect_errors:true (Bytes.Reader.of_string input) in
1212- print_endline "Result:";
1313- print_endline (Dom.to_test_format (Parser.root result))