@@ -25,107 +25,129 @@ struct HTMLKitTests {
2525}
2626
2727extension HTMLKitTests {
28- @Test func test_element_html ( ) {
28+ @Test func element_html ( ) {
2929 #expect( #html( [ ] ) == " <!DOCTYPE html><html></html> " )
3030 #expect( #html( xmlns: " test " , [ ] ) == " <!DOCTYPE html><html xmlns= \" test \" ></html> " )
3131 }
32- @Test func test_element_area ( ) {
32+ @Test func element_area ( ) {
3333 #expect( #area( coords: [ 1 , 2 , 3 ] ) == " <area coords= \" 1,2,3 \" > " )
3434 }
35- @Test func test_element_audio ( ) {
35+ @Test func element_audio ( ) {
3636 #expect( #audio( controlslist: . nodownload) == " <audio controlslist= \" nodownload \" ></audio> " )
3737 }
38- @Test func test_element_button ( ) {
38+ @Test func element_button ( ) {
3939 #expect( #button( type: . submit) == " <button type= \" submit \" ></button> " )
4040 }
41- @Test func test_element_canvas ( ) {
41+ @Test func element_canvas ( ) {
4242 #expect( #canvas( height: . percent( 4 ) , width: . em( 2.69 ) ) == " <canvas height= \" 4% \" width= \" 2.69em \" ></canvas> " )
4343 }
44- @Test func test_element_form ( ) {
44+ @Test func element_form ( ) {
4545 #expect( #form( acceptCharset: [ " utf-8 " ] , autocomplete: . on) == " <form accept-charset= \" utf-8 \" autocomplete= \" on \" ></form> " )
4646 }
47- @Test func test_element_iframe ( ) {
47+ @Test func element_iframe ( ) {
4848 #expect( #iframe(sandbox: [.allowDownloads, .allowForms]) == "<iframe sandbox=\"allow-downloads allow-forms\"></iframe>")
4949 }
50- @Test func test_element_input ( ) {
50+ @Test func element_input ( ) {
5151 #expect( #input( autocomplete: [ " email " , " password " ] , type: . text) == " <input autocomplete= \" email password \" type= \" text \" > " )
5252 #expect( #input( type: . password) == " <input type= \" password \" > " )
5353 #expect( #input( type: . datetimeLocal) == " <input type= \" datetime-local \" > " )
5454 }
55- @Test func test_element_img ( ) {
55+ @Test func element_img ( ) {
5656 #expect( #img( sizes: [ " (max-height: 500px) 1000px " , " (min-height: 25rem) " ] , srcset: [ " https://paradigm-app.com " , " https://litleagues.com " ] ) == " <img sizes= \" (max-height: 500px) 1000px,(min-height: 25rem) \" srcset= \" https://paradigm-app.com,https://litleagues.com \" > " )
5757 }
5858 @Test func test_link( ) {
5959 #expect( #link( as: . document, imagesizes: [ " lmno " , " p " ] ) == " <link as= \" document \" imagesizes= \" lmno,p \" > " )
6060 }
61- @Test func test_element_ol ( ) {
61+ @Test func element_ol ( ) {
6262 #expect( #ol( ) == " <ol></ol> " )
6363 #expect( #ol( type: . a) == " <ol type= \" a \" ></ol> " )
6464 #expect( #ol( type: . A) == " <ol type= \" A \" ></ol> " )
6565 #expect( #ol( type: . i) == " <ol type= \" i \" ></ol> " )
6666 #expect( #ol( type: . I) == " <ol type= \" I \" ></ol> " )
6767 #expect( #ol( type: . one) == " <ol type= \" 1 \" ></ol> " )
6868 }
69- @Test func test_element_script ( ) {
69+ @Test func element_script ( ) {
7070 #expect( #script( ) == " <script></script> " )
7171 #expect( #script( type: . importmap) == " <script type= \" importmap \" ></script> " )
7272 #expect( #script( type: . module) == " <script type= \" module \" ></script> " )
7373 #expect( #script( type: . speculationrules) == " <script type= \" speculationrules \" ></script> " )
7474 }
75- @Test func test_element_text_area ( ) {
75+ @Test func element_text_area ( ) {
7676 #expect( #textarea( autocomplete: [ " email " , " password " ] , rows: 5 ) == " <textarea autocomplete= \" email password \" rows= \" 5 \" ></textarea> " )
7777 }
78- @Test func test_element_video ( ) {
78+ @Test func element_video ( ) {
7979 #expect( #video( controlslist: [ . nodownload, . nofullscreen, . noremoteplayback] ) == " <video controlslist= \" nodownload nofullscreen noremoteplayback \" ></video> " )
8080 }
81+
82+ @Test func element_custom( ) {
83+ var bro : String = #custom( tag: " bro " , isVoid: false )
84+ #expect( bro == " <bro></bro> " )
85+
86+ bro = #custom( tag: " bro " , isVoid: true )
87+ #expect( bro == " <bro> " )
88+ }
89+
90+ @Test func element_events( ) {
91+ #expect( #div( attributes: [ . event( . click, " doThing() " ) , . event( . change, " doAnotherThing() " ) ] , [ ] ) == " <div onclick= \" doThing() \" onchange= \" doAnotherThing() \" ></div> " )
92+ }
93+
94+ @Test func elements_void( ) {
95+ let string : StaticString = #area( [ #base( ) , #br( ) , #col( ) , #embed( ) , #hr( ) , #img( ) , #input( ) , #link( ) , #meta( ) , #source( ) , #track( ) , #wbr( ) ] )
96+ #expect( string == " <area><base><br><col><embed><hr><img><input><link><meta><source><track><wbr> " )
97+ }
8198}
8299
83100extension HTMLKitTests {
84- @Test func test_recursive ( ) {
101+ @Test func recursive_elements ( ) {
85102 let string : StaticString = #div( [
86103 #div( ) ,
87104 #div( [ #div( ) , #div( ) , #div( ) ] ) ,
88105 #div( )
89106 ] )
90107 #expect( string == " <div><div></div><div><div></div><div></div><div></div></div><div></div></div> " )
91108 }
92- /*@Test func test_same_attribute_multiple_times () {
109+ /*@Test func same_attribute_multiple_times () {
93110 let string:StaticString = #div(attributes: [.id("1"), .id("2"), .id("3"), .id("4")])
94111 #expect(string == "<div id=\"1\"></div>")
95112 }*/
96- @Test func test_attribute_hidden( ) {
97- #expect( #div( attributes: [ . hidden( . true ) ] ) == " <div hidden></div> " )
98- #expect( #div( attributes: [ . hidden( . untilFound) ] ) == " <div hidden= \" until-found \" ></div> " )
99- }
100113
101- @Test func test_void ( ) {
102- let string : StaticString = #area ( [ #base ( ) , #br ( ) , #col ( ) , #embed ( ) , #hr ( ) , #img ( ) , #input ( ) , #link ( ) , #meta ( ) , #source ( ) , #track ( ) , #wbr ( ) ] )
103- #expect ( string == " <area><base><br><col><embed><hr><img><input><link><meta><source><track><wbr> " )
114+ @Test func no_value_type ( ) {
115+ let test1 = #html ( [ #body ( [ #h 1 ( [ " HTMLKitTests " ] ) ] ) ] )
116+ let test2 = #html ( [ #body ( [ #h 1 ( [ StaticString ( " HTMLKitTests " ) ] ) ] ) ] )
104117 }
105- @Test func test_multiline( ) {
118+
119+ @Test func multiline_value_type( ) {
106120 /*#expect(#script(["""
107121 bro
108122 """
109123 ]) == "<script>bro</script>")*/
110124 }
111- @Test func test_events( ) {
112- #expect( #div( attributes: [ . event( . click, " doThing() " ) , . event( . change, " doAnotherThing() " ) ] , [ ] ) == " <div onclick= \" doThing() \" onchange= \" doAnotherThing() \" ></div> " )
113- }
114125}
115126
116127extension HTMLKitTests {
117- @Test func test_attribute_data ( ) {
128+ @Test func attribute_data ( ) {
118129 #expect( #div( attributes: [ . data( " id " , " 5 " ) ] ) == " <div data-id= \" 5 \" ></div> " )
119130 }
131+ @Test func attribute_hidden( ) {
132+ #expect( #div( attributes: [ . hidden( . true ) ] ) == " <div hidden></div> " )
133+ #expect( #div( attributes: [ . hidden( . untilFound) ] ) == " <div hidden= \" until-found \" ></div> " )
134+ }
135+
136+ @Test func attribute_custom( ) {
137+ #expect( #div( attributes: [ . custom( " potofgold " , " north " ) ] ) == " <div potofgold= \" north \" ></div> " )
138+ #expect( #div( attributes: [ . custom( " potofgold " , " \( 1 ) " ) ] ) == " <div potofgold= \" 1 \" ></div> " )
139+ #expect( #div( attributes: [ . custom( " potofgold1 " , " \( 1 ) " ) , . custom( " potofgold2 " , " 2 " ) ] ) == " <div potofgold1= \" 1 \" potofgold2= \" 2 \" ></div> " )
140+ //#expect(#div(attributes: [.custom("potof gold1", "\(1)"), .custom("potof gold2", "2")]) == "<div potofgold1=\"1\" potofgold2=\"2\"></div>")
141+ }
120142}
121143
122144extension HTMLKitTests {
123145 enum Shrek : String {
124146 case isLove, isLife
125147 }
126- @Test func test_third_party_enum ( ) {
127- #expect( #div ( attributes: [ . title( Shrek . isLove. rawValue) ] ) == " <div title= \" isLove \" ></div > " )
128- #expect( #div ( attributes: [ . title( " \( Shrek . isLife) " ) ] ) == " <div title= \" isLife \" ></div > " )
148+ @Test func third_party_enum ( ) {
149+ #expect( #a ( attributes: [ . title( Shrek . isLove. rawValue) ] ) == " <a title= \" isLove \" ></a > " )
150+ #expect( #a ( attributes: [ . title( " \( Shrek . isLife) " ) ] ) == " <a title= \" isLife \" ></a > " )
129151 }
130152}
131153
@@ -140,7 +162,7 @@ extension HTMLKitTests {
140162 }
141163 }
142164
143- @Test func test_third_party_literal ( ) {
165+ @Test func third_party_literal ( ) {
144166 var string : String = #div( attributes: [ . title( HTMLKitTests . spongebob) ] )
145167 #expect( string == " <div title= \" Spongebob Squarepants \" ></div> " )
146168
@@ -151,13 +173,13 @@ extension HTMLKitTests {
151173 let static_string:StaticString = #div(attributes: [.title(mr_crabs)])
152174 #expect(static_string == "<div title=\"Mr. Crabs\"></div>")*/
153175 }
154- @Test func test_third_party_func ( ) {
155- #expect( #div( attributes: [ . title( HTMLKitTests . spongebobCharacter ( " patrick " ) ) ] ) == " <div title= \" Patrick Star \" ></div> " )
176+ @Test func third_party_func ( ) {
177+ // #expect(#div(attributes: [.title(HTMLKitTests.spongebobCharacter("patrick"))]) == "<div title=\"Patrick Star\"></div>")
156178 }
157179}
158180
159181extension HTMLKitTests {
160- @Test func test_example_1 ( ) {
182+ @Test func example_1 ( ) {
161183 let test: StaticString = #html( [
162184 #body( [
163185 #div(
@@ -189,7 +211,7 @@ extension HTMLKitTests {
189211}
190212
191213extension HTMLKitTests {
192- @Test func testExample2 ( ) {
214+ @Test func example2 ( ) {
193215 var test : TestStruct = TestStruct ( name: " one " , array: [ " 1 " , " 2 " , " 3 " ] )
194216 #expect( test. html == " <p>one123</p> " )
195217
0 commit comments