Thanks to visit codestin.com
Credit goes to github.com

Skip to content

Commit c0cb073

Browse files
updated tests to have nested query structure
1 parent 7d18e50 commit c0cb073

File tree

18 files changed

+62
-33
lines changed

18 files changed

+62
-33
lines changed

templates/go/query.go.twig

Lines changed: 12 additions & 12 deletions
Original file line numberDiff line numberDiff line change
@@ -318,95 +318,95 @@ func And(queries []string) string {
318318
})
319319
}
320320

321-
func DistanceEqual(attribute string, values []interface{}, distance float64, meters bool) string {
321+
func DistanceEqual(attribute string, values interface{}, distance float64, meters bool) string {
322322
return parseQuery(queryOptions{
323323
Method: "distanceEqual",
324324
Attribute: &attribute,
325325
Values: &[]interface{}{values, distance, meters},
326326
})
327327
}
328328

329-
func DistanceNotEqual(attribute string, values []interface{}, distance float64, meters bool) string {
329+
func DistanceNotEqual(attribute string, values interface{}, distance float64, meters bool) string {
330330
return parseQuery(queryOptions{
331331
Method: "distanceNotEqual",
332332
Attribute: &attribute,
333333
Values: &[]interface{}{values, distance, meters},
334334
})
335335
}
336336

337-
func DistanceGreaterThan(attribute string, values []interface{}, distance float64, meters bool) string {
337+
func DistanceGreaterThan(attribute string, values interface{}, distance float64, meters bool) string {
338338
return parseQuery(queryOptions{
339339
Method: "distanceGreaterThan",
340340
Attribute: &attribute,
341341
Values: &[]interface{}{values, distance, meters},
342342
})
343343
}
344344

345-
func DistanceLessThan(attribute string, values []interface{}, distance float64, meters bool) string {
345+
func DistanceLessThan(attribute string, values interface{}, distance float64, meters bool) string {
346346
return parseQuery(queryOptions{
347347
Method: "distanceLessThan",
348348
Attribute: &attribute,
349349
Values: &[]interface{}{values, distance, meters},
350350
})
351351
}
352352

353-
func Intersects(attribute string, values []interface{}) string {
353+
func Intersects(attribute string, values interface{}) string {
354354
return parseQuery(queryOptions{
355355
Method: "intersects",
356356
Attribute: &attribute,
357357
Values: &values,
358358
})
359359
}
360360

361-
func NotIntersects(attribute string, values []interface{}) string {
361+
func NotIntersects(attribute string, values interface{}) string {
362362
return parseQuery(queryOptions{
363363
Method: "notIntersects",
364364
Attribute: &attribute,
365365
Values: &values,
366366
})
367367
}
368368

369-
func Crosses(attribute string, values []interface{}) string {
369+
func Crosses(attribute string, values interface{}) string {
370370
return parseQuery(queryOptions{
371371
Method: "crosses",
372372
Attribute: &attribute,
373373
Values: &values,
374374
})
375375
}
376376

377-
func NotCrosses(attribute string, values []interface{}) string {
377+
func NotCrosses(attribute string, values interface{}) string {
378378
return parseQuery(queryOptions{
379379
Method: "notCrosses",
380380
Attribute: &attribute,
381381
Values: &values,
382382
})
383383
}
384384

385-
func Overlaps(attribute string, values []interface{}) string {
385+
func Overlaps(attribute string, values interface{}) string {
386386
return parseQuery(queryOptions{
387387
Method: "overlaps",
388388
Attribute: &attribute,
389389
Values: &values,
390390
})
391391
}
392392

393-
func NotOverlaps(attribute string, values []interface{}) string {
393+
func NotOverlaps(attribute string, values interface{}) string {
394394
return parseQuery(queryOptions{
395395
Method: "notOverlaps",
396396
Attribute: &attribute,
397397
Values: &values,
398398
})
399399
}
400400

401-
func Touches(attribute string, values []interface{}) string {
401+
func Touches(attribute string, values interface{}) string {
402402
return parseQuery(queryOptions{
403403
Method: "touches",
404404
Attribute: &attribute,
405405
Values: &values,
406406
})
407407
}
408408

409-
func NotTouches(attribute string, values []interface{}) string {
409+
func NotTouches(attribute string, values interface{}) string {
410410
return parseQuery(queryOptions{
411411
Method: "notTouches",
412412
Attribute: &attribute,

templates/swift/Sources/Query.swift.twig

Lines changed: 33 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -6,11 +6,11 @@ enum QueryValue: Codable {
66
case double(Double)
77
case bool(Bool)
88
case query(Query)
9-
case array([QueryValue])
9+
case array([QueryValue]) // for nested arrays
1010

1111
init(from decoder: Decoder) throws {
1212
let container = try decoder.singleValueContainer()
13-
// Attempt to decode each type
13+
1414
if let stringValue = try? container.decode(String.self) {
1515
self = .string(stringValue)
1616
} else if let intValue = try? container.decode(Int.self) {
@@ -21,8 +21,13 @@ enum QueryValue: Codable {
2121
self = .bool(boolValue)
2222
} else if let queryValue = try? container.decode(Query.self) {
2323
self = .query(queryValue)
24+
} else if let arrayValue = try? container.decode([QueryValue].self) {
25+
self = .array(arrayValue)
2426
} else {
25-
throw DecodingError.dataCorruptedError(in: container, debugDescription: "QueryValue cannot be decoded")
27+
throw DecodingError.dataCorruptedError(
28+
in: container,
29+
debugDescription: "QueryValue cannot be decoded"
30+
)
2631
}
2732
}
2833

@@ -39,6 +44,8 @@ enum QueryValue: Codable {
3944
try container.encode(value)
4045
case .query(let value):
4146
try container.encode(value)
47+
case .array(let value):
48+
try container.encode(value)
4249
}
4350
}
4451
}
@@ -87,7 +94,29 @@ public struct Query : Codable, CustomStringConvertible {
8794
case let queryValue as Query:
8895
return [.query(queryValue)]
8996
case let anyArray as [Any]:
90-
return [.array(anyArray.compactMap { convertToQueryValueArray($0).map { .array($0) } })]
97+
// Handle nested arrays
98+
let nestedValues = anyArray.compactMap { item -> QueryValue? in
99+
if let stringValue = item as? String {
100+
return .string(stringValue)
101+
} else if let intValue = item as? Int {
102+
return .int(intValue)
103+
} else if let doubleValue = item as? Double {
104+
return .double(doubleValue)
105+
} else if let boolValue = item as? Bool {
106+
return .bool(boolValue)
107+
} else if let queryValue = item as? Query {
108+
return .query(queryValue)
109+
} else if let nestedArray = item as? [Any] {
110+
// Convert nested array to QueryValue.array
111+
if let converted = convertToQueryValueArray(nestedArray) {
112+
return .array(converted)
113+
}
114+
return nil
115+
}
116+
return nil
117+
}
118+
return nestedValues.isEmpty ? nil : nestedValues
119+
91120
default:
92121
return nil
93122
}

tests/Base.php

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -118,8 +118,8 @@ abstract class Base extends TestCase
118118
'{"method":"createdAfter","values":["2023-01-01"]}',
119119
'{"method":"updatedBefore","values":["2023-01-01"]}',
120120
'{"method":"updatedAfter","values":["2023-01-01"]}',
121-
'{"method":"distanceEqual","attribute":"location","values":[[40.7128,-74],1000,false]}',
122-
'{"method":"distanceEqual","attribute":"location","values":[[40.7128,-74],1000,true]}',
121+
'{"method":"distanceEqual","attribute":"location","values":[[[40.7128, -74],[40.7128, -74]],1000,false]}',
122+
'{"method":"distanceEqual","attribute":"location","values":[[[40.7128, -74],[40.7128, -74]],1000,true]}',
123123
'{"method":"distanceNotEqual","attribute":"location","values":[[40.7128,-74],1000,false]}',
124124
'{"method":"distanceNotEqual","attribute":"location","values":[[40.7128,-74],1000,true]}',
125125
'{"method":"distanceGreaterThan","attribute":"location","values":[[40.7128,-74],1000,false]}',

tests/languages/android/Tests.kt

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -222,7 +222,7 @@ class ServiceTest {
222222
writeToFile(Query.updatedAfter("2023-01-01"))
223223

224224
// Spatial Distance query tests
225-
writeToFile(Query.distanceEqual("location", listOf(40.7128, -74), 1000))
225+
writeToFile(Query.distanceEqual("location", listOf(listOf(40.7128, -74), listOf(40.7128, -74)), 1000))
226226
writeToFile(Query.distanceEqual("location", listOf(40.7128, -74), 1000, true))
227227
writeToFile(Query.distanceNotEqual("location", listOf(40.7128, -74), 1000))
228228
writeToFile(Query.distanceNotEqual("location", listOf(40.7128, -74), 1000, true))

tests/languages/apple/Tests.swift

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -196,7 +196,7 @@ class Tests: XCTestCase {
196196
print(Query.updatedAfter("2023-01-01"))
197197

198198
// Spatial Distance query tests
199-
print(Query.distanceEqual("location", values: [40.7128, -74], distance: 1000))
199+
print(Query.distanceEqual("location", values: [[40.7128, -74],[40.7128, -74]], distance: 1000))
200200
print(Query.distanceEqual("location", values: [40.7128, -74], distance: 1000, meters: true))
201201
print(Query.distanceNotEqual("location", values: [40.7128, -74], distance: 1000))
202202
print(Query.distanceNotEqual("location", values: [40.7128, -74], distance: 1000, meters: true))

tests/languages/dart/tests.dart

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -162,7 +162,7 @@ void main() async {
162162
print(Query.updatedAfter("2023-01-01"));
163163

164164
// Spatial Distance query tests
165-
print(Query.distanceEqual("location", [40.7128, -74], 1000));
165+
print(Query.distanceEqual("location", [[40.7128, -74], [40.7128, -74]], 1000));
166166
print(Query.distanceEqual("location", [40.7128, -74], 1000, true));
167167
print(Query.distanceNotEqual("location", [40.7128, -74], 1000));
168168
print(Query.distanceNotEqual("location", [40.7128, -74], 1000, true));

tests/languages/deno/tests.ts

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -188,7 +188,7 @@ async function start() {
188188
console.log(Query.updatedAfter("2023-01-01"));
189189

190190
// Spatial Distance query tests
191-
console.log(Query.distanceEqual("location", [40.7128, -74], 1000));
191+
console.log(Query.distanceEqual("location", [[40.7128, -74], [40.7128, -74]], 1000));
192192
console.log(Query.distanceEqual("location", [40.7128, -74], 1000, true));
193193
console.log(Query.distanceNotEqual("location", [40.7128, -74], 1000));
194194
console.log(Query.distanceNotEqual("location", [40.7128, -74], 1000, true));

tests/languages/dotnet/Tests.cs

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -170,7 +170,7 @@ public async Task Test1()
170170
TestContext.WriteLine(Query.UpdatedAfter("2023-01-01"));
171171

172172
// Spatial Distance query tests
173-
TestContext.WriteLine(Query.DistanceEqual("location", new List<object> { 40.7128, -74 }, 1000));
173+
TestContext.WriteLine(Query.DistanceEqual("location", new List<List<object>> { new List<object> { 40.7128, -74 }, new List<object> { 40.7128, -74 } }, 1000));
174174
TestContext.WriteLine(Query.DistanceEqual("location", new List<object> { 40.7128, -74 }, 1000, true));
175175
TestContext.WriteLine(Query.DistanceNotEqual("location", new List<object> { 40.7128, -74 }, 1000));
176176
TestContext.WriteLine(Query.DistanceNotEqual("location", new List<object> { 40.7128, -74 }, 1000, true));

tests/languages/flutter/tests.dart

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -196,7 +196,7 @@ void main() async {
196196
print(Query.updatedAfter("2023-01-01"));
197197

198198
// Spatial Distance query tests
199-
print(Query.distanceEqual("location", [40.7128, -74], 1000));
199+
print(Query.distanceEqual("location", [[40.7128, -74], [40.7128, -74]], 1000));
200200
print(Query.distanceEqual("location", [40.7128, -74], 1000, true));
201201
print(Query.distanceNotEqual("location", [40.7128, -74], 1000));
202202
print(Query.distanceNotEqual("location", [40.7128, -74], 1000, true));

tests/languages/go/tests.go

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -221,7 +221,7 @@ func testQueries() {
221221
fmt.Println(query.UpdatedAfter("2023-01-01"))
222222

223223
// Spatial Distance query tests
224-
fmt.Println(query.DistanceEqual("location", []interface{}{40.7128, -74}, 1000, false))
224+
fmt.Println(query.DistanceEqual("location", []interface{}{[]interface{}{40.7128, -74}, []interface{}{40.7128, -74}}, 1000, false))
225225
fmt.Println(query.DistanceEqual("location", []interface{}{40.7128, -74}, 1000, true))
226226
fmt.Println(query.DistanceNotEqual("location", []interface{}{40.7128, -74}, 1000, false))
227227
fmt.Println(query.DistanceNotEqual("location", []interface{}{40.7128, -74}, 1000, true))

0 commit comments

Comments
 (0)