-
Notifications
You must be signed in to change notification settings - Fork 0
/
XPathSpec.swift
59 lines (48 loc) · 1.89 KB
/
XPathSpec.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
53
54
55
56
57
58
59
//
// Created by Vladimir Burdukov on 8/21/20.
//
import XCTest
import Nimble
@testable import miniGnomon
class XPathSpec: XCTestCase {
override func setUp() {
continueAfterFailure = false
}
static let testDictionary: [String: Any] = [
"root": [
"inner": ["@attributes": ["uID": "p180593"], "@value": "Ronald Matarrita"],
"multiple": [
["@attributes": ["uID": "p180593"], "@value": "Ronald Matarrita"],
["@attributes": ["uID": "p50122"], "@value": "Sean Franklin"],
["@attributes": ["uID": "p60152"], "@value": "Chris Pontius"]
]
],
"one_level": ["key": "value"]
]
func testOneLevelDictionaryXPath() {
let result = XPathSpec.testDictionary.dictionary(byPath: "one_level")
expect(result?["key"] as? String).to(equal("value"))
}
func testMoreLevelsDictionaryXPath() {
let result = XPathSpec.testDictionary.dictionary(byPath: "root/inner")
expect(result?["@value"] as? String).to(equal("Ronald Matarrita"))
expect(result?["@attributes"] as? [String: String]).to(equal(["uID": "p180593"]))
}
func testArrayXPath() {
let result = XPathSpec.testDictionary.array(byPath: "root/multiple")
guard let array = result else {
fail()
return
}
expect(array).to(haveCount(3))
expect(array[0]["@value"] as? String).to(equal("Ronald Matarrita"))
expect(array[1]["@value"] as? String).to(equal("Sean Franklin"))
expect(array[2]["@value"] as? String).to(equal("Chris Pontius"))
}
func testInvalidXPaths() {
let firstLevel = XPathSpec.testDictionary.dictionary(byPath: "invalid")
let secondLevel = XPathSpec.testDictionary.dictionary(byPath: "root/invalid")
expect(firstLevel).to(beNil())
expect(secondLevel).to(beNil())
}
}