Skip to content

Commit

Permalink
convenience child tag init
Browse files Browse the repository at this point in the history
  • Loading branch information
tib committed Feb 24, 2022
1 parent 8facd3e commit 0158351
Show file tree
Hide file tree
Showing 2 changed files with 32 additions and 1 deletion.
7 changes: 6 additions & 1 deletion Sources/SwiftSgml/Tag.swift
Original file line number Diff line number Diff line change
Expand Up @@ -21,7 +21,12 @@ open class Tag {
self.node = Self.createNode()
self.children = children
}


/// initialize a new Tag with a single child tag
public convenience init(_ child: Tag) {
self.init([child])
}

/// initialize a new Tag with children using a builder
public convenience init(@TagBuilder _ builder: () -> [Tag]) {
self.init(builder())
Expand Down
26 changes: 26 additions & 0 deletions Tests/SwiftSgmlTests/TagTests.swift
Original file line number Diff line number Diff line change
@@ -0,0 +1,26 @@
//
// File.swift
//
//
// Created by Tibor Bodecs on 2022. 02. 24..
//

import XCTest
@testable import SwiftSgml

final class TagTests: XCTestCase {

func testConvenienceSingleTagInit() {

let doc = Document {
Root(Leaf("hello"))
}

XCTAssertEqual(DocumentRenderer().render(doc), """
<root>
<leaf>hello</leaf>
</root>
""")
}

}

0 comments on commit 0158351

Please sign in to comment.