|
1 | 1 | (* Unit tests for conversion from Omd.t to Tyxml.t *)
|
2 |
| -let () = assert false |
| 2 | + |
| 3 | +let tyxml_to_string t = |
| 4 | + Format.asprintf "%a" Tyxml.Html.(pp ()) t |
| 5 | + |
| 6 | +let html_of_string s = |
| 7 | + s |> Omd.of_string |> Omd_tyxml.of_omd |> tyxml_to_string |
| 8 | + |
| 9 | +let test name ~actual ~expected = |
| 10 | + try |
| 11 | + assert (actual = expected) |
| 12 | + with Assert_failure (file, line, _) -> |
| 13 | + Printf.eprintf "Test '%s' failed (file %s, line %d):\n expected: %s\n actual: %s\n\n" |
| 14 | + name file line expected actual |
| 15 | + |
| 16 | +let () = |
| 17 | + test "the empty document" |
| 18 | + ~actual:(html_of_string "") |
| 19 | + ~expected:{|<!DOCTYPE html> |
| 20 | +<html xmlns="http://www.w3.org/1999/xhtml"><head><title></title></head><body></body></html>|}; |
| 21 | + |
| 22 | + test "a plain line" |
| 23 | + ~actual:(html_of_string "a plain line") |
| 24 | + ~expected:{|<!DOCTYPE html> |
| 25 | +<html xmlns="http://www.w3.org/1999/xhtml"><head><title></title></head><body><p>a plain line</p></body></html>|}; |
| 26 | + |
| 27 | + test "emphasized text" |
| 28 | + ~actual:(html_of_string "some *emphasized* text") |
| 29 | + ~expected:{||} |
| 30 | + |
| 31 | +(* TODO(shon) Tie this into the generated specs tests *) |
| 32 | +(* let li_begin_re = Str.regexp_string "<li>\n" |
| 33 | + * let li_end_re = Str.regexp_string "\n</li>" |
| 34 | + * |
| 35 | + * let normalize_html s = |
| 36 | + * Str.global_replace li_end_re "</li>" |
| 37 | + * (Str.global_replace li_begin_re "<li>" s) |
| 38 | + * |
| 39 | + * let with_open_in fn f = |
| 40 | + * let ic = open_in fn in |
| 41 | + * Fun.protect ~finally:(fun () -> close_in_noerr ic) |
| 42 | + * (fun () -> f ic) |
| 43 | + * |
| 44 | + * let () = |
| 45 | + * with_open_in Sys.argv.(1) @@ fun ic -> |
| 46 | + * ic |
| 47 | + * |> Omd.of_channel |
| 48 | + * |> Omd_tyxml.of_omd |
| 49 | + * |> tyxml_to_string |
| 50 | + * |> normalize_html |
| 51 | + * |> print_string *) |
0 commit comments