CommandLineToolkit
88 строк · 2.1 Кб
1import PlistLib
2import TestHelpers
3import XCTest
4
5final class PlistEntryTests: XCTestCase {
6func test___accessing_entries_in_array() {
7let entry = PlistEntry.array([.string("hello")])
8XCTAssertEqual(
9try entry.entry(atIndex: 0),
10.string("hello")
11)
12}
13
14func test___accessing_entries_in_dict() {
15let entry = PlistEntry.dict(["key": .string("hello")])
16
17XCTAssertEqual(
18try entry.entry(forKey: "key"),
19.string("hello")
20)
21}
22
23func test___string() {
24let entry = PlistEntry.string("hello")
25XCTAssertEqual(
26try entry.stringValue(),
27"hello"
28)
29}
30
31func test___bool() {
32let entry = PlistEntry.bool(true)
33XCTAssertEqual(
34try entry.boolValue(),
35true
36)
37}
38
39func test___date() {
40let date = Date()
41
42let entry = PlistEntry.date(date)
43XCTAssertEqual(
44try entry.dateValue(),
45date
46)
47}
48
49func test___data() {
50let data = Data([0x11, 0x22])
51
52let entry = PlistEntry.data(data)
53XCTAssertEqual(
54try entry.dataValue(),
55data
56)
57}
58
59func test___accessing_incorrect_value() {
60let entry = PlistEntry.string("hello")
61
62assertThrows { try entry.dateValue() }
63}
64
65func test___accesing_via_typed_functions() {
66let entry = PlistEntry.dict([
67"root": .array([
68.string("hello"),
69.array([.data(Data([0xFF]))])
70])
71])
72
73XCTAssertEqual(
74try entry.entry(forKey: "root").entry(atIndex: 1).entry(atIndex: 0).dataValue(),
75Data([0xFF])
76)
77}
78
79func test___accessing_bool_using_number___throws() {
80let entry = PlistEntry.bool(true)
81assertThrows { _ = try entry.numberValue() }
82}
83
84func test___accessing_number_using_bool___throws() {
85let entry = PlistEntry.number(3.14)
86assertThrows { _ = try entry.boolValue() }
87}
88}
89