1 2 3 4 5 6 7 8 9 10 11 12 13 14 15 16 17 18 19 20 21 22 23 24 25 26 27 28 29 30 31 32 33 34 35 36 37 38 39 40 41 42 43 44 45 46 47 48 49 50 51 52 53 54 55 56 57 58 59 60 61 62 63 64 65 66 67 68 69 70 71 72 73 74 75 76 77 78 79 80 81 82 83 84 85 86 87 88 89 90 91 92 93 94 95 96 97 98 99 100 101 102 103 104 105 106 107 108 109 110 111 112 113 114 115
|
open Tyxml_test
let html_elements = "html elements", tyxml_tests Html.[
"dialog",
dialog ~a:[a_open ()] [div []],
"<dialog open=\"open\"><div></div></dialog>" ;
"div",
div [a []],
"<div><a></a></div>" ;
"input",
input ~a:[a_formaction "post.html"; a_formmethod `Post] (),
"<input formaction=\"post.html\" formmethod=\"POST\"/>";
"a",
canvas [a []],
"<canvas><a></a></canvas>";
"template",
template ~a:[a_id "idtmpl"] [p [txt "Template"]],
"<template id=\"idtmpl\"><p>Template</p></template>" ;
"picture_src",
div [
picture ~a:[a_id "idpicture"]
~img:(img ~a:[a_id "idimg"] ~src:"picture/img.png" ~alt:"test picture/img.png" ()) [
source ~a:[a_mime_type "image/webp"; a_src "picture/img1.webp"] ()
; source ~a:[a_mime_type "image/jpeg"; a_src "picture/img2.jpg"] ()
]
],
{|<div><picture id="idpicture">|}
^ {|<source type="image/webp" src="picture/img1.webp"/>|}
^ {|<source type="image/jpeg" src="picture/img2.jpg"/>|}
^ {|<img src="picture/img.png" alt="test picture/img.png" id="idimg"/>|}
^ {|</picture></div>|} ;
"picture_srcset",
div [
picture ~a:[a_id "idpicture"]
~img:(img ~a:[a_id "idimg"] ~src:"picture/img.png" ~alt:"test picture/img.png" ()) [
source ~a:[a_mime_type "image/webp";
a_srcset [`Url (Xml.uri_of_string "picture/img1.webp")]] ()
; source ~a:[a_mime_type "image/jpeg";
a_srcset [`Url (Xml.uri_of_string "picture/img2.jpg")]] ()
]
],
{|<div><picture id="idpicture">|}
^ {|<source type="image/webp" srcset="picture/img1.webp"/>|}
^ {|<source type="image/jpeg" srcset="picture/img2.jpg"/>|}
^ {|<img src="picture/img.png" alt="test picture/img.png" id="idimg"/>|}
^ {|</picture></div>|} ;
]
let html_attributes = "html attributes", tyxml_tests Html.[
"translate",
div ~a:[a_translate `No] [p ~a:[a_translate `Yes] []],
"<div translate=\"no\"><p translate=\"yes\"></p></div>" ;
]
let escaping = "html escaping", tyxml_tests Html.[
"cdata",
cdata "<bar>]]>foo<bar/>",
"\n<![CDATA[\n<bar>foo<bar/>\n]]>\n" ;
"cdata multi",
cdata "<bar>]]>foo<b]]>ar/>",
"\n<![CDATA[\n<bar>foo<bar/>\n]]>\n" ;
"cdata_script" ,
cdata_script "<bar>]]>foo<bar/>" ,
"\n//<![CDATA[\n<bar>foo<bar/>\n//]]>\n" ;
"cdata_style" ,
cdata_style "<bar>]]>foo<bar/>" ,
"\n/* <![CDATA[ */\n<bar>foo<bar/>\n/* ]]> */\n" ;
"comment",
tot (Xml.comment
{|[if IE 8]> <html class="no-js lt-ie9" lang="en"> <![endif]|}),
{|<!--[if IE 8]> <html class="no-js lt-ie9" lang="en"> <![endif]-->|} ;
"dodgy comment 1",
tot (Xml.comment {|><script BOUM/>|}),
{|<!--><script BOUM/>-->|} ;
"dodgy comment 2",
tot (Xml.comment {|-><script BOUM/>|}),
{|<!---><script BOUM/>-->|} ;
"dodgy comment 3",
tot (Xml.comment {|foo--><script BOUM/>|}),
{|<!--foo--><script BOUM/>-->|} ;
"dodgy comment 4",
tot (Xml.comment {|foo--!><script BOUM/>|}),
{|<!--foo--!><script BOUM/>-->|} ;
"utf8",
a ~a:[a_href "/text/λαμδα"] [txt "λαμδα"],
{|<a href="/text/λαμδα">λαμδα</a>|} ;
]
let tests = [
html_elements ;
html_attributes ;
escaping ;
]
let () = Alcotest.run "tyxml" tests
|