Files
swift-hpa/Tests/CliDocTests/CliDocTests.swift

157 lines
2.9 KiB
Swift

@_spi(Internal) import CliDoc
@preconcurrency import Rainbow
import Testing
import XCTest
final class CliDocTests: XCTestCase {
override func setUp() {
super.setUp()
Rainbow.outputTarget = .console
Rainbow.enabled = true
}
func testStringChecks() {
let expected = "Foo".green.bold
XCTAssert("Foo".green.bold == expected)
XCTAssert(expected != "Foo")
}
func testRepeatingModifier() {
let node = AnyNode {
Text("foo").color(.green).style(.bold)
"\n".repeating(2)
Text("bar").repeating(2, separator: " ")
}
let expected = """
\("foo".green.bold)
bar bar
"""
XCTAssert(node.render() == expected)
}
func testGroup1() {
let arguments = [
(true, "foo bar"),
(false, """
foo
bar
""")
]
for (inline, expected) in arguments {
let node = AnyNode {
Group(separator: inline ? " " : "\n") {
Text("foo")
Text("bar")
}
}
XCTAssert(node.render() == expected)
}
}
func testHeader() {
let header = Header("Foo")
let expected = "\("Foo".yellow.bold)"
XCTAssert(header.render() == expected)
let header2 = Header {
"Foo".yellow.bold
}
XCTAssert(header2.render() == expected)
}
func testGroup() {
let group = Group {
Text("foo")
Text("bar")
}
XCTAssert(group.render() == "foo bar")
let group2 = Group(separator: "\n") {
Text("foo")
Text("bar")
}
let expected = """
foo
bar
"""
XCTAssert(group2.render() == expected)
}
func testLabeledContent() {
let node = LabeledContent("Foo") {
Text("Bar")
}
.labelStyle(.green)
.labelStyle(.bold)
let expected = """
\("Foo".green.bold)
Bar
"""
XCTAssert(node.render() == expected)
}
func testLabeledContent2() {
let node = LabeledContent2 {
"Foo"
} content: {
Text("Bar")
}
// .labelStyle(.green)
// .labelStyle(.bold)
let expected = """
Foo Bar
"""
XCTAssert(node.render() == expected)
print(type(of: node.body))
XCTAssertNotNil(node.body as? _ManyNode)
}
func testShellCommand() {
let node = ShellCommand {
"ls -lah"
}
let expected = " $ ls -lah"
XCTAssert(node.render() == expected)
}
func testDiscussion() {
let node = Discussion {
Group(separator: "\n") {
LabeledContent(separator: " ") {
"NOTE:".yellow.bold
} content: {
"Foo"
}
}
}
let expected = """
\("NOTE:".yellow.bold) Foo
"""
XCTAssert(node.render() == expected)
}
func testFooNode() {
let foo = Foo()
XCTAssertNotNil(foo.body as? LabeledContent)
}
func testGroup2() {
let node = Group2 {
Text("foo")
Text("bar")
}
print(node.render())
XCTAssertNotNil(node.body as? _ManyNode)
// XCTAssert(false)
}
}