Skip to content

Commit 885f0ca

Browse files
committed
async await init support
1 parent 0158351 commit 885f0ca

File tree

2 files changed

+26
-0
lines changed

2 files changed

+26
-0
lines changed

Sources/SwiftSgml/Tag.swift

Lines changed: 6 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -31,6 +31,12 @@ open class Tag {
3131
public convenience init(@TagBuilder _ builder: () -> [Tag]) {
3232
self.init(builder())
3333
}
34+
35+
/// initialize a new Tag with children using an async throwing builder
36+
public convenience init(@TagBuilder _ builder: () async throws -> [Tag]) async throws {
37+
self.init(try await builder())
38+
}
39+
3440

3541
/// initialize a new Tag with some contents
3642
public convenience init(_ contents: String?) {

Tests/SwiftSgmlTests/TagTests.swift

Lines changed: 20 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -23,4 +23,24 @@ final class TagTests: XCTestCase {
2323
""")
2424
}
2525

26+
func testConvenienceAsyncTagInit() async throws {
27+
28+
func leaf() async throws -> Leaf {
29+
Leaf("hello")
30+
}
31+
32+
let root = try await Root {
33+
try await leaf()
34+
}
35+
let doc = Document {
36+
root
37+
}
38+
39+
XCTAssertEqual(DocumentRenderer().render(doc), """
40+
<root>
41+
<leaf>hello</leaf>
42+
</root>
43+
""")
2644
}
45+
46+
}

0 commit comments

Comments
 (0)