Skip to content

Commit 2137e5f

Browse files
committed
Port more integration tests from Android.
1 parent d59843f commit 2137e5f

File tree

1 file changed

+168
-0
lines changed

1 file changed

+168
-0
lines changed

Firestore/Swift/Tests/Integration/BsonTypesIntegrationTests.swift

Lines changed: 168 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -303,6 +303,56 @@ class BsonTypesIntegrationTests: FSTIntegrationTestCase {
303303
expectedResult: ["h", "g", "e", "d", "c"]
304304
)
305305

306+
query = collection
307+
.whereField("key", isNotEqualTo: Decimal128Value("0"))
308+
.order(by: "key")
309+
try await assertSdkQueryResultsConsistentWithBackend(
310+
testDocs,
311+
collection: collection,
312+
query: query,
313+
expectedResult: ["b", "a", "f", "g", "h"]
314+
)
315+
316+
query = collection
317+
.whereField("key", isNotEqualTo: Decimal128Value("NaN"))
318+
.order(by: "key")
319+
try await assertSdkQueryResultsConsistentWithBackend(
320+
testDocs,
321+
collection: collection,
322+
query: query,
323+
expectedResult: ["a", "f", "c", "d", "e", "g", "h"]
324+
)
325+
326+
query = collection
327+
.whereField("key", isEqualTo: Decimal128Value("-01.23e-4"))
328+
.order(by: "key")
329+
try await assertSdkQueryResultsConsistentWithBackend(
330+
testDocs,
331+
collection: collection,
332+
query: query,
333+
expectedResult: ["f"]
334+
)
335+
336+
query = collection
337+
.whereField("key", isNotEqualTo: Decimal128Value("-01.23e-4"))
338+
.order(by: "key")
339+
try await assertSdkQueryResultsConsistentWithBackend(
340+
testDocs,
341+
collection: collection,
342+
query: query,
343+
expectedResult: ["b", "a", "c", "d", "e", "g", "h"]
344+
)
345+
346+
query = collection
347+
.whereField("key", in: [Decimal128Value("0")])
348+
.order(by: "key", descending: true)
349+
try await assertSdkQueryResultsConsistentWithBackend(
350+
testDocs,
351+
collection: collection,
352+
query: query,
353+
expectedResult: ["e", "d", "c"]
354+
)
355+
306356
query = collection
307357
.whereField("key", notIn: [Decimal128Value("NaN"), Decimal128Value("Infinity")])
308358
.order(by: "key", descending: true)
@@ -314,6 +364,124 @@ class BsonTypesIntegrationTests: FSTIntegrationTestCase {
314364
)
315365
}
316366

367+
func testCanFilterAndOrderNumericalValues() async throws {
368+
let testDocs: [String: [String: Any]] = [
369+
"a": ["key": Decimal128Value("-1.2e3")],
370+
"b": ["key": Int32Value(0)],
371+
"c": ["key": Decimal128Value("1")],
372+
"d": ["key": Int32Value(1)],
373+
"e": ["key": 1],
374+
"f": ["key": 1.0],
375+
"g": ["key": Decimal128Value("1.2e-3")],
376+
"h": ["key": Int32Value(2)],
377+
"i": ["key": Decimal128Value("NaN")],
378+
"j": ["key": Decimal128Value("-Infinity")],
379+
"k": ["key": Double.nan],
380+
"l": ["key": Decimal128Value("Infinity")],
381+
]
382+
383+
let collection = collectionRef()
384+
await setDocumentData(testDocs, toCollection: collection)
385+
386+
// TODO(b/421432611): This is currently failing due to Quadruple.cc bugs.
387+
// let query = collection.order(by: "key", descending: true)
388+
// try await assertSdkQueryResultsConsistentWithBackend(
389+
// testDocs,
390+
// collection: collection,
391+
// query: query,
392+
// expectedResult: [
393+
// "l", // Infinity
394+
// "h", // 2
395+
// "f", // 1.0
396+
// "e", // 1
397+
// "d", // 1
398+
// "c", // 1
399+
// "g", // 0.0012
400+
// "b", // 0
401+
// "a", // -1200
402+
// "j", // -Infinity
403+
// "k", // NaN
404+
// "i" // NaN
405+
// ]
406+
// )
407+
408+
let query2 = collection
409+
.whereField("key", isNotEqualTo: Decimal128Value("1.0"))
410+
.order(by: "key", descending: true)
411+
try await assertSdkQueryResultsConsistentWithBackend(
412+
testDocs,
413+
collection: collection,
414+
query: query2,
415+
expectedResult: ["l", "h", "g", "b", "a", "j", "k", "i"]
416+
)
417+
418+
let query3 = collection
419+
.whereField("key", isEqualTo: 1)
420+
.order(by: "key", descending: true)
421+
try await assertSdkQueryResultsConsistentWithBackend(
422+
testDocs,
423+
collection: collection,
424+
query: query3,
425+
expectedResult: ["f", "e", "d", "c"]
426+
)
427+
}
428+
429+
func testDecimal128ValuesWithNo2sComplementRepresentation() async throws {
430+
let testDocs: [String: [String: Any]] = [
431+
"a": ["key": Decimal128Value("-1.1e-3")], // -0.0011
432+
"b": ["key": Decimal128Value("1.1")],
433+
"c": ["key": 1.1],
434+
"d": ["key": 1.0],
435+
"e": ["key": Decimal128Value("1.1e-3")], // 0.0011
436+
]
437+
438+
let collection = collectionRef()
439+
await setDocumentData(testDocs, toCollection: collection)
440+
441+
// TODO(b/421432611): This is currently failing due to Quadruple.cc bugs.
442+
// let query = collection
443+
// .whereField("key", isEqualTo: Decimal128Value("1.1"))
444+
// .order(by: "key", descending: true)
445+
// try await assertSdkQueryResultsConsistentWithBackend(
446+
// testDocs,
447+
// collection: collection,
448+
// query: query,
449+
// expectedResult: ["b"]
450+
// )
451+
452+
// TODO(b/421432611): This is currently failing due to Quadruple.cc bugs.
453+
// let query2 = collection
454+
// .whereField("key", isNotEqualTo: Decimal128Value("1.1"))
455+
// .order(by: "key", descending: false)
456+
// try await assertSdkQueryResultsConsistentWithBackend(
457+
// testDocs,
458+
// collection: collection,
459+
// query: query2,
460+
// expectedResult: ["a", "e", "d", "c"]
461+
// )
462+
463+
let query3 = collection
464+
.whereField("key", isEqualTo: 1.1)
465+
.order(by: "key", descending: false)
466+
try await assertSdkQueryResultsConsistentWithBackend(
467+
testDocs,
468+
collection: collection,
469+
query: query3,
470+
expectedResult: ["c"]
471+
)
472+
473+
// TODO(b/421432611): This is currently failing due to Quadruple.cc bugs.
474+
// let query4 = collection
475+
// .whereField("key", isNotEqualTo: 1.1)
476+
// .order(by: "key", descending: false)
477+
// try await assertSdkQueryResultsConsistentWithBackend(
478+
// testDocs,
479+
// collection: collection,
480+
// query: query4,
481+
// expectedResult: ["a", "e", "d", "b"]
482+
// )
483+
}
484+
317485
func testCanFilterAndOrderTimestampValues() async throws {
318486
let testDocs: [String: [String: Any]] = [
319487
"a": ["key": BSONTimestamp(seconds: 1, increment: 1)],

0 commit comments

Comments
 (0)