File tree Expand file tree Collapse file tree 2 files changed +26
-0
lines changed Expand file tree Collapse file tree 2 files changed +26
-0
lines changed Original file line number Diff line number Diff 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 ? ) {
Original file line number Diff line number Diff 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+ }
You can’t perform that action at this time.
0 commit comments