-
Notifications
You must be signed in to change notification settings - Fork 87
Expand file tree
/
Copy pathAttributeTests.swift
More file actions
123 lines (96 loc) · 3.42 KB
/
AttributeTests.swift
File metadata and controls
123 lines (96 loc) · 3.42 KB
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
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
103
104
105
106
107
108
109
110
111
112
113
114
115
116
117
118
119
120
121
122
123
//
// AttributeTests.swift
// QueryKit
//
// Created by Kyle Fuller on 19/06/2014.
//
//
import XCTest
import QueryKit
class AttributeTests: XCTestCase {
var attribute:Attribute<Int>!
override func setUp() {
super.setUp()
attribute = Attribute("age")
}
func testAttributeHasName() {
XCTAssertEqual(attribute.name, "age")
}
func testAttributeExpression() {
XCTAssertEqual(attribute.expression.keyPath, "age")
}
func testEqualAttributesAreEquatable() {
XCTAssertEqual(attribute, Attribute<Int>("age"))
}
func testCompoundAttributeCreation() {
let personCompanyNameAttribute = Attribute<NSString>(attributes:["company", "name"])
XCTAssertEqual(personCompanyNameAttribute.name, "company.name")
XCTAssertEqual(personCompanyNameAttribute.expression.keyPath, "company.name")
}
// Sorting
func testAscendingSortDescriptor() {
XCTAssertEqual(attribute.ascending(), NSSortDescriptor(key: "age", ascending: true))
}
func testDescendingSortDescriptor() {
XCTAssertEqual(attribute.descending(), NSSortDescriptor(key: "age", ascending: false))
}
// Operators
func testEqualityOperator() {
var predicate:NSPredicate = (attribute == 10)
XCTAssertEqual(predicate, NSPredicate(format:"age == 10")!)
}
func testInequalityOperator() {
var predicate:NSPredicate = (attribute != 10)
XCTAssertEqual(predicate, NSPredicate(format:"age != 10")!)
}
func testGreaterThanOperator() {
var predicate:NSPredicate = (attribute > 10)
XCTAssertEqual(predicate, NSPredicate(format:"age > 10")!)
}
func testGreaterOrEqualThanOperator() {
var predicate:NSPredicate = (attribute >= 10)
XCTAssertEqual(predicate, NSPredicate(format:"age >= 10")!)
}
func testLessThanOperator() {
var predicate:NSPredicate = (attribute < 10)
XCTAssertEqual(predicate, NSPredicate(format:"age < 10")!)
}
func testLessOrEqualThanOperator() {
var predicate:NSPredicate = (attribute <= 10)
XCTAssertEqual(predicate, NSPredicate(format:"age <= 10")!)
}
func testLikeOperator() {
var predicate:NSPredicate = (attribute ~= 10)
XCTAssertEqual(predicate, NSPredicate(format:"age LIKE 10")!)
}
func testInOperator() {
var predicate:NSPredicate = (attribute << [5, 10])
XCTAssertEqual(predicate, NSPredicate(format:"age IN %@", [5, 10])!)
}
func testBetweenRangeOperator() {
var predicate:NSPredicate = attribute << (5..<10)
XCTAssertEqual(predicate, NSPredicate(format:"age BETWEEN %@", [5, 10])!)
}
}
class CollectionAttributeTests: XCTestCase {
func testCountOfSet() {
let setAttribute = Attribute<NSSet>("names")
let countAttribute = count(setAttribute)
XCTAssertEqual(countAttribute, Attribute<Int>("names.@count"))
}
func testCountOfOrderedSet() {
let setAttribute = Attribute<NSOrderedSet>("names")
let countAttribute = count(setAttribute)
XCTAssertEqual(countAttribute, Attribute<Int>("names.@count"))
}
}
class BoolAttributeTests: XCTestCase {
var attribute:Attribute<Bool>!
override func setUp() {
super.setUp()
attribute = Attribute("hasName")
}
func testNotAttributeReturnsPredicate() {
XCTAssertEqual(!attribute, NSPredicate(format:"hasName == NO")!)
}
}