forked from JohnSundell/Plot
-
Notifications
You must be signed in to change notification settings - Fork 0
/
Copy pathControlFlowTests.swift
42 lines (35 loc) · 1.2 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
/**
* 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(), "")
XCTAssertEqual(Node<Any>.unwrap(optional, Node.text, else: .text("Is nil") ).render(), "Is nil")
}
func testForEach() {
let array = ["A", "B", "C"]
XCTAssertEqual(Node<Any>.forEach(array, Node.text).render(), "ABC")
XCTAssertEqual(Node<Any>.forEach([], Node.text).render(), "")
}
}