@@ -63,77 +63,80 @@ struct SwiftHTMLTestSuite {
6363 #expect( result == expectation)
6464 }
6565
66- //
67- // func testHtmlDocument() {
68- // let doc = Document(.html) {
69- // Html {
70- // Head {
71- // Title("Hello Swift DSL")
72- //
73- // Meta().charset("utf-8")
74- // Meta().name(.viewport)
75- // .content("width=device-width, initial-scale=1")
76- //
77- // Link(rel: .stylesheet).href("./css/style.css")
78- // }
79- // Body {
80- // Main {
81- // Div {
82- // Section {
83- // Img(
84- // src: "./images/swift.png",
85- // alt: "Swift Logo"
86- // )
87- // .title("Picture of the Swift Logo")
88- // H1("Lorem ipsum")
89- // .class("red")
90- // P(
91- // "Lorem ipsum dolor sit amet, consectetur adipiscing elit. Nulla pretium leo eu euismod porta."
92- // )
93- // .class(["green", "blue"])
94- // .spellcheck(false)
95- // }
96- // A("Hello Swift HTML DSL!")
97- // .href("https://swift.org")
98- // .target(.blank)
99- // .download()
100- // Abbr("WHO")
101- // .title("World Health Organization")
102- // }
103- // }
104- // .class("container")
105- //
106- // Script()
107- // .src("./javascript/main.js")
108- // }
109- // }
110- // }
111- //
112- // let html = """
113- // <!DOCTYPE html>
114- // <html>
115- // <head>
116- // <title>Hello Swift DSL</title>
117- // <meta charset="utf-8">
118- // <meta name="viewport" content="width=device-width, initial-scale=1">
119- // <link rel="stylesheet" href="./css/style.css">
120- // </head>
121- // <body>
122- // <main class="container">
123- // <div>
124- // <section>
125- // <img src="./images/swift.png" alt="Swift Logo" title="Picture of the Swift Logo">
126- // <h1 class="red">Lorem ipsum</h1>
127- // <p class="green blue" spellcheck="false">Lorem ipsum dolor sit amet, consectetur adipiscing elit. Nulla pretium leo eu euismod porta.</p>
128- // </section>
129- // <a href="https://swift.org" target="_blank" download>Hello Swift HTML DSL!</a>
130- // <abbr title="World Health Organization">WHO</abbr>
131- // </div>
132- // </main>
133- // <script src="./javascript/main.js"></script>
134- // </body>
135- // </html>
136- // """
137- // assert(doc: doc, html: html)
138- // }
66+ @Test
67+ func compatiblityWithVersion1Syntax( ) async throws {
68+ let html = Html {
69+ Head {
70+ Title ( " Hello Swift DSL " )
71+
72+ Meta ( ) . charset ( " utf-8 " )
73+ Meta ( ) . name ( . viewport)
74+ . content ( " width=device-width, initial-scale=1 " )
75+
76+ Link ( rel: . stylesheet) . href ( " ./css/style.css " )
77+ }
78+ Body {
79+ Main {
80+ Div {
81+ Section {
82+ Img (
83+ src: " ./images/swift.png " ,
84+ alt: " Swift Logo "
85+ )
86+ . title ( " Picture of the Swift Logo " )
87+ H1 ( " Lorem ipsum " )
88+ . class ( " red " )
89+ P (
90+ " Lorem ipsum dolor sit amet, consectetur adipiscing elit. Nulla pretium leo eu euismod porta. "
91+ )
92+ . class ( [ " green " , " blue " ] )
93+ . spellcheck ( false )
94+ }
95+ A ( " Hello Swift HTML DSL! " )
96+ . href ( " https://swift.org " )
97+ . target ( . blank)
98+ . download ( )
99+ Abbr ( " WHO " )
100+ . title ( " World Health Organization " )
101+ }
102+ }
103+ . class ( " container " )
104+
105+ Script ( )
106+ . src ( " ./javascript/main.js " )
107+ }
108+ }
109+
110+ let renderer = Renderer ( indent: 4 )
111+ let doc = Document ( type: . html, root: html)
112+
113+ let expectation = #"""
114+ <!doctype html>
115+ <html>
116+ <head>
117+ <title>Hello Swift DSL</title>
118+ <meta charset="utf-8">
119+ <meta content="width=device-width, initial-scale=1" name="viewport">
120+ <link href="./css/style.css" rel="stylesheet">
121+ </head>
122+ <body>
123+ <main class="container">
124+ <div>
125+ <section>
126+ <img alt="Swift Logo" src="./images/swift.png" title="Picture of the Swift Logo">
127+ <h1 class="red">Lorem ipsum</h1>
128+ <p class="blue green" spellcheck="false">Lorem ipsum dolor sit amet, consectetur adipiscing elit. Nulla pretium leo eu euismod porta.</p>
129+ </section>
130+ <a href="https://swift.org" target="_blank" download>Hello Swift HTML DSL!</a>
131+ <abbr title="World Health Organization">WHO</abbr>
132+ </div>
133+ </main>
134+ <script src="./javascript/main.js">
135+ </body>
136+ </html>
137+ """#
138+
139+ let result = renderer. render ( document: doc)
140+ #expect( result == expectation)
141+ }
139142}
0 commit comments