example.com -> example.org
[Seppo.git] / test / t_xmlm.ml
blob23ebeccec9f654d955e4fd5a93f2c1b90eba3a74
2 open Seppo_lib
4 (* https://erratique.ch/software/xmlm/doc/Xmlm/index.html#outns *)
5 let test_ezxmlm_out () =
6 Logr.info (fun m -> m "%s.%s" "xmlm_test" "text_ezxmlm_out");
7 []
8 |> Ezxmlm.to_string
9 |> Assrt.equals_string __LOC__ "";
10 [ `El ((("", "uhu"), []), []) ]
11 |> Ezxmlm.to_string
12 |> Assrt.equals_string __LOC__ "<uhu/>";
13 [ `El ((("", "e"), [ (("", "a"), "v") ]), [ `Data "foo" ]) ]
14 |> Ezxmlm.to_string
15 |> Assrt.equals_string __LOC__ "<e a=\"v\">foo</e>";
16 [ `El ((("", "e"), [ (("", "xmlns"), "A") ]), [ `Data "foo" ]) ]
17 |> Ezxmlm.to_string
18 |> Assrt.equals_string __LOC__ "<e xmlns=\"A\">foo</e>";
19 [ `El ((("A", "e"), [((Xmlm.ns_xmlns, "xmlns"), "A")]), [`Data "foo"]) ]
20 |> Ezxmlm.to_string
21 |> Assrt.equals_string __LOC__ "<e xmlns=\"A\">foo</e>";
22 [ `El ((("N", "e"), [((Xmlm.ns_xmlns, "n"), "N")]), [`Data "foo"]) ]
23 |> Ezxmlm.to_string
24 |> Assrt.equals_string __LOC__ "<n:e xmlns:n=\"N\">foo</n:e>";
25 assert true
27 let test_ezxmlm_out2() =
28 Logr.info (fun m -> m "%s.%s" "xmlm_test" "text_ezxmlm_out2");
29 [`El ((("","elm"),[(("","nam"),"val")]),[])]
30 |> Ezxmlm.to_string
31 |> Assrt.equals_string __LOC__ {|<elm nam="val"/>|};
32 [`El ((("uri 2","root"),[
33 ((Xmlm.ns_xmlns,"n2"),"uri 2");
34 ]),[
35 `El ((("uri 2","c1"),[
36 ]),[
37 `Data "uh";
38 `Data "u";
39 ])]);
41 |> Ezxmlm.to_string ~decl:true
42 |> Assrt.equals_string __LOC__ {|<?xml version="1.0" encoding="UTF-8"?>
43 <n2:root xmlns:n2="uri 2"><n2:c1>uhu</n2:c1></n2:root>|};
44 assert true
46 let test_xmlm_signals () =
47 Logr.info (fun m -> m "%s.%s" "xmlm_test" "test_xmlm_signals");
48 let dst = Buffer.create 1024 in
49 Buffer.add_string dst {|<?xml version="1.0" encoding="UTF-8"?>
50 |};
51 Buffer.add_string dst "<!-- huhu -->\n";
52 let o = Xmlm.make_output ~decl:false ~indent:(Some 2) (`Buffer dst) in
53 let out = Xmlm.output o in
54 out (`Dtd None);
55 out (`El_start (("uri","e"),[
56 ((Xmlm.ns_xmlns,"n"),"uri");
57 ("","k"),"v"]));
58 out (`Data "uhu");
59 out `El_end;
60 dst
61 |> Buffer.to_bytes
62 |> Bytes.to_string
63 |> Assrt.equals_string __LOC__ {|<?xml version="1.0" encoding="UTF-8"?>
64 <!-- huhu -->
65 <n:e xmlns:n="uri" k="v">
66 uhu
67 </n:e>|};
68 assert true
70 let test_xmlm_frag () =
71 Logr.info (fun m -> m "%s.%s" "xmlm_test" "test_xmlm_signals");
72 let x : _ Xmlm.frag = `El ((("uri", "e"), [
73 ((Xmlm.ns_xmlns, "n"), "uri");
74 (("", "k"), "v");
75 ]), [`Data "uhu"]) in
76 let dst = Buffer.create 1024 in
77 Buffer.add_string dst {|<?xml version="1.0" encoding="UTF-8"?>
78 |};
79 Buffer.add_string dst "<!-- huhu -->\n";
80 let o = Xmlm.make_output ~decl:false ~indent:(Some 2) (`Buffer dst) in
81 Xmlm.output_doc_tree (fun x -> x) o (None,x);
82 dst
83 |> Buffer.to_bytes
84 |> Bytes.to_string
85 |> Assrt.equals_string __LOC__ {|<?xml version="1.0" encoding="UTF-8"?>
86 <!-- huhu -->
87 <n:e xmlns:n="uri" k="v">
88 uhu
89 </n:e>|};
90 assert true
92 let () =
93 Unix.chdir "../../../test/";
94 test_ezxmlm_out ();
95 test_ezxmlm_out2 ();
96 test_xmlm_signals ();
97 test_xmlm_frag ();
98 assert true