-
Notifications
You must be signed in to change notification settings - Fork 1
/
PredicateBuilderTests.swift
188 lines (154 loc) · 5.66 KB
/
PredicateBuilderTests.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
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
124
125
126
127
128
129
130
131
132
133
134
135
136
137
138
139
140
141
142
143
144
145
146
147
148
149
150
151
152
153
154
155
156
157
158
159
160
161
162
163
164
165
166
167
168
169
170
171
172
173
174
175
176
177
178
179
180
181
182
183
184
185
186
187
188
//
// PredicateBuilderTests.swift
// PredicateBuilderTests
//
// Created by Muronaka Hiroaki on 2017/06/11.
// Copyright © 2017年 Muronaka Hiroaki. All rights reserved.
//
//
// PredicateBuilderTest.swift
// PredicateDSL
//
// Created by Muronaka Hiroaki on 2017/06/11.
// Copyright © 2017年 Muronaka Hiroaki. All rights reserved.
//
import XCTest
@testable import PredicateBuilder
class PredicateBuilderTest: XCTestCase {
override func setUp() {
super.setUp()
// Put setup code here. This method is called before the invocation of each test method in the class.
}
override func tearDown() {
// Put teardown code here. This method is called after the invocation of each test method in the class.
super.tearDown()
}
func testEqStr() {
let val = "abc"
let predicate = NSPredicate(format: "key == %@", val)
XCTAssertEqual(predicate, "key".pred.eq(val))
}
func testEqInt() {
let val = 123
let predicate = NSPredicate(format: "key == %d", val)
XCTAssertEqual(predicate, "key".pred.eq(123))
}
func testEqInt2() {
let val = 123
let predicate = NSPredicate(format: "key == %d", val)
XCTAssertEqual(predicate, "key".pred == 123)
}
func testLess() {
let val = 123
let predicate = NSPredicate(format: "key < %d", val)
XCTAssertEqual(predicate, "key".pred.less(123))
}
func testLess2() {
let val = 123
let predicate = NSPredicate(format: "key < %d", val)
XCTAssertEqual(predicate, "key".pred < 123)
}
func testLessThanEquals() {
let val = 123
let predicate = NSPredicate(format: "key <= %d", val)
XCTAssertEqual(predicate, "key".pred.lessThanEquals(123))
}
func testLessThanEquals2() {
let val = 123
let predicate = NSPredicate(format: "key <= %d", val)
XCTAssertEqual(predicate, "key".pred <= val)
}
func testEqDate() {
let val = Date()
let predicate = NSPredicate(format: "key == %@", val as NSDate)
XCTAssertEqual(predicate, "key".pred.eq(val))
}
func testEqDate2() {
let val = Date()
let predicate = NSPredicate(format: "key == %@", val as NSDate)
XCTAssertEqual(predicate, "key".pred == val)
}
func testGreater() {
let val = Date()
let predicate = NSPredicate(format: "key > %@", val as NSDate)
XCTAssertEqual(predicate, "key".pred.greater(val))
}
func testGreater2() {
let val = Date()
let predicate = NSPredicate(format: "key > %@", val as NSDate)
XCTAssertEqual(predicate, "key".pred > val)
}
func testGreaterThanEquals() {
let val = Date()
let predicate = NSPredicate(format: "key >= %@", val as NSDate)
XCTAssertEqual(predicate, "key".pred.greaterThanEquals(val))
}
func testGreaterThanEquals2() {
let val = Date()
let predicate = NSPredicate(format: "key >= %@", val as NSDate)
XCTAssertEqual(predicate, "key".pred >= val)
}
func testIn1() {
let val = [1,2,3]
let predicate = NSPredicate(format: "SELF in %@", val)
XCTAssertEqual(predicate, "SELF".pred.in(val))
}
func testBetween() {
let val = [1,10]
let predicate = NSPredicate(format: "attr between %@", val as NSArray)
XCTAssertEqual(predicate, "attr".pred.between(val))
}
func testBeginWith() {
let val = "prefix"
let predicate = NSPredicate(format: "attr beginswith %@", val)
XCTAssertEqual(predicate, "attr".pred.beginsWith(val))
}
func testBeginWithC() {
let val = "prefix"
let predicate = NSPredicate(format: "attr beginswith[c] %@", val)
XCTAssertEqual(predicate, "attr".pred.beginsWith(val, options: .c))
}
func testBeginWithD() {
let val = "prefix"
let predicate = NSPredicate(format: "attr beginswith[d] %@", val)
XCTAssertEqual(predicate, "attr".pred.beginsWith(val, options: .d))
}
func testBeginWithCD() {
let val = "prefix"
let predicate = NSPredicate(format: "attr beginswith[cd] %@", val)
XCTAssertEqual(predicate, "attr".pred.beginsWith(val, options: .cd))
}
func testAny() {
let predicate = NSPredicate(format: "ANY employees.firstname LIKE 'Matthew'")
XCTAssertEqual(predicate, pred.any("employees.firstname").like("Matthew"))
}
func testNot() {
let predicate = NSPredicate(format: "NOT attr == 123")
XCTAssertEqual(predicate, !("attr".pred.eq(123)))
}
func testAve() {
let predicate = NSPredicate(format: "expenses.@avg.doubleValue > 123")
XCTAssertEqual(predicate, "expenses".pred.avg(.doubleValue).greater(123))
}
func testAnd() {
let val = "str"
let predicate = NSPredicate(format: "a == 1 AND b != %@", val)
XCTAssertEqual(predicate, "a".pred == 1 && "b".pred != val)
}
func testOr() {
let val = "str"
let predicate = NSPredicate(format: "a == 1 OR b != %@", val)
XCTAssertEqual(predicate, "a".pred == 1 || "b".pred != val)
}
func testAndOr() {
let val = "str"
let predicate = NSPredicate(format: "a == 1 AND b != %@ OR c == 123", val)
XCTAssertEqual(predicate, "a".pred == 1 && "b".pred != val || "c".pred == 123)
}
func testPerformanceExample() {
// This is an example of a performance test case.
self.measure {
// Put the code you want to measure the time of here.
}
}
}