Skip to content

Commit 0158351

Browse files
committed
convenience child tag init
1 parent 8facd3e commit 0158351

File tree

2 files changed

+32
-1
lines changed

2 files changed

+32
-1
lines changed

Sources/SwiftSgml/Tag.swift

Lines changed: 6 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -21,7 +21,12 @@ open class Tag {
2121
self.node = Self.createNode()
2222
self.children = children
2323
}
24-
24+
25+
/// initialize a new Tag with a single child tag
26+
public convenience init(_ child: Tag) {
27+
self.init([child])
28+
}
29+
2530
/// initialize a new Tag with children using a builder
2631
public convenience init(@TagBuilder _ builder: () -> [Tag]) {
2732
self.init(builder())
Lines changed: 26 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,26 @@
1+
//
2+
// File.swift
3+
//
4+
//
5+
// Created by Tibor Bodecs on 2022. 02. 24..
6+
//
7+
8+
import XCTest
9+
@testable import SwiftSgml
10+
11+
final class TagTests: XCTestCase {
12+
13+
func testConvenienceSingleTagInit() {
14+
15+
let doc = Document {
16+
Root(Leaf("hello"))
17+
}
18+
19+
XCTAssertEqual(DocumentRenderer().render(doc), """
20+
<root>
21+
<leaf>hello</leaf>
22+
</root>
23+
""")
24+
}
25+
26+
}

0 commit comments

Comments
 (0)