CommandLineToolkit

Форк
0
/
PlistEntryTests.swift 
88 строк · 2.1 Кб
1
import PlistLib
2
import TestHelpers
3
import XCTest
4

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

Использование cookies

Мы используем файлы cookie в соответствии с Политикой конфиденциальности и Политикой использования cookies.

Нажимая кнопку «Принимаю», Вы даете АО «СберТех» согласие на обработку Ваших персональных данных в целях совершенствования нашего веб-сайта и Сервиса GitVerse, а также повышения удобства их использования.

Запретить использование cookies Вы можете самостоятельно в настройках Вашего браузера.