forked from JohnSundell/Plot
-
Notifications
You must be signed in to change notification settings - Fork 0
/
ControlFlowTests.swift
52 lines (44 loc) · 1.42 KB
/
ControlFlowTests.swift
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
/**
* Plot
* Copyright (c) John Sundell 2019
* MIT license, see LICENSE file for details
*/
import XCTest
import Plot
final class ControlFlowTests: XCTestCase {
func testIfCondition() {
XCTAssertEqual(Node<Any>.if(true, .text("True")).render(), "True")
XCTAssertEqual(Node<Any>.if(false, .text("True")).render(), "")
}
func testIfElseCondition() {
XCTAssertEqual(
Node<Any>.if(true, .text("If"), else: .text("Else")).render(),
"If"
)
XCTAssertEqual(
Node<Any>.if(false, .text("If"), else: .text("Else")).render(),
"Else"
)
}
func testUnwrappingOptional() {
var optional: String? = "Hello"
XCTAssertEqual(Node<Any>.unwrap(optional, Node.text).render(), "Hello")
optional = nil
XCTAssertEqual(Node<Any>.unwrap(optional, Node.text).render(), "")
}
func testForEach() {
let array = ["A", "B", "C"]
XCTAssertEqual(Node<Any>.forEach(array, Node.text).render(), "ABC")
XCTAssertEqual(Node<Any>.forEach([], Node.text).render(), "")
}
}
extension ControlFlowTests {
static var allTests: Linux.TestList<ControlFlowTests> {
[
("testIfCondition", testIfCondition),
("testIfElseCondition", testIfElseCondition),
("testUnwrappingOptional", testUnwrappingOptional),
("testForEach", testForEach)
]
}
}