Skip to content

Commit de7ad80

Browse files
authored
fix(OptimizelyConfig): add more tests for experiment audiences serialization (#420)
1 parent 1b477a2 commit de7ad80

File tree

3 files changed

+13
-2
lines changed

3 files changed

+13
-2
lines changed

.travis.yml

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -79,7 +79,7 @@ jobs:
7979
- pod repo update
8080
- pod install
8181
# install jq without cleaning up
82-
- HOMEBREW_NO_INSTALL_CLEANUP=true brew install jq
82+
- HOMEBREW_NO_INSTALL_CLEANUP=true brew update && brew install jq
8383
# preload simulator
8484
- Scripts/start_simulator.sh
8585
script:

Sources/Data Model/Audience/ConditionHolder.swift

Lines changed: 6 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -170,7 +170,12 @@ extension Array where Element == ConditionHolder {
170170
// extract it first and join the rest of the array items with the logical op
171171
switch firstItem {
172172
case .logicalOp(.not):
173-
result = (self.count < 2) ? "" : "NOT \(self[1].serialized)"
173+
if self.count < 2 {
174+
result = ""
175+
} else {
176+
let desc = self[1].serialized
177+
return "NOT " + (self[1].isArray ? "(\(desc))" : desc)
178+
}
174179
case .logicalOp(let op):
175180
result = self.enumerated()
176181
.filter { $0.offset > 0 }

Tests/OptimizelyTests-DataModel/ExperimentTests.swift

Lines changed: 6 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -170,6 +170,7 @@ extension ExperimentTests {
170170
]
171171

172172
let audiencesInput: [Any] = [
173+
[],
173174
["or", "1", "2"],
174175
["and", "1", "2", "3"],
175176
["not", "1"],
@@ -179,10 +180,13 @@ extension ExperimentTests {
179180
["1", "2"],
180181
["and", ["or", "1", "2"], "3"],
181182
["and", ["or", "1", ["and", "2", "3"]], ["and", "11", ["or", "12", "13"]]],
183+
["not", ["and", "1", "2"]],
184+
["or", "1", "100000"],
182185
["and", "and"]
183186
]
184187

185188
let audiencesOutput: [String] = [
189+
"",
186190
"\"us\" OR \"female\"",
187191
"\"us\" AND \"female\" AND \"adult\"",
188192
"NOT \"us\"",
@@ -192,6 +196,8 @@ extension ExperimentTests {
192196
"\"us\" OR \"female\"",
193197
"(\"us\" OR \"female\") AND \"adult\"",
194198
"(\"us\" OR (\"female\" AND \"adult\")) AND (\"fr\" AND (\"male\" OR \"kid\"))",
199+
"NOT (\"us\" AND \"female\")",
200+
"\"us\" OR \"100000\"",
195201
""
196202
]
197203

0 commit comments

Comments
 (0)