Skip to content

Commit ecfc763

Browse files
committed
check if results are expected to be empty
test example fixes fix
1 parent 0702428 commit ecfc763

File tree

2 files changed

+70
-0
lines changed

2 files changed

+70
-0
lines changed

Sources/StructuredQueriesTestSupport/AssertQuery.swift

Lines changed: 16 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -97,6 +97,22 @@ public func assertQuery<each V: QueryRepresentable, S: Statement<(repeat each V)
9797
line: line,
9898
column: column
9999
)
100+
} else if results != nil {
101+
assertInlineSnapshot(
102+
of: table,
103+
as: .lines,
104+
message: "Results expected to be empty",
105+
syntaxDescriptor: InlineSnapshotSyntaxDescriptor(
106+
trailingClosureLabel: "results",
107+
trailingClosureOffset: snapshotTrailingClosureOffset + 1
108+
),
109+
matches: results,
110+
fileID: fileID,
111+
file: filePath,
112+
function: function,
113+
line: line,
114+
column: column
115+
)
100116
}
101117
} catch {
102118
assertInlineSnapshot(

Tests/StructuredQueriesTests/WhereTests.swift

Lines changed: 54 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -40,6 +40,60 @@ extension SnapshotTests {
4040
}
4141
}
4242

43+
@Test func emptyResults() {
44+
withKnownIssue("This assert should fail") {
45+
assertQuery(
46+
Reminder.where(\.isCompleted).and(Reminder.where(\.isFlagged))
47+
) {
48+
"""
49+
SELECT "reminders"."id", "reminders"."assignedUserID", "reminders"."dueDate", "reminders"."isCompleted", "reminders"."isFlagged", "reminders"."notes", "reminders"."priority", "reminders"."remindersListID", "reminders"."title"
50+
FROM "reminders"
51+
WHERE ("reminders"."isCompleted") AND ("reminders"."isFlagged")
52+
"""
53+
} results: {
54+
"""
55+
┌────────────────────────────────────────────┐
56+
│ Reminder( │
57+
│ id: 4, │
58+
│ assignedUserID: nil, │
59+
│ dueDate: Date(2000-06-25T00:00:00.000Z), │
60+
│ isCompleted: true, │
61+
│ isFlagged: false, │
62+
│ notes: "", │
63+
│ priority: nil, │
64+
│ remindersListID: 1, │
65+
│ title: "Take a walk"
66+
│ ) │
67+
├────────────────────────────────────────────┤
68+
│ Reminder( │
69+
│ id: 7, │
70+
│ assignedUserID: nil, │
71+
│ dueDate: Date(2000-12-30T00:00:00.000Z), │
72+
│ isCompleted: true, │
73+
│ isFlagged: false, │
74+
│ notes: "", │
75+
│ priority: .low, │
76+
│ remindersListID: 2, │
77+
│ title: "Get laundry"
78+
│ ) │
79+
├────────────────────────────────────────────┤
80+
│ Reminder( │
81+
│ id: 10, │
82+
│ assignedUserID: nil, │
83+
│ dueDate: Date(2000-12-30T00:00:00.000Z), │
84+
│ isCompleted: true, │
85+
│ isFlagged: false, │
86+
│ notes: "", │
87+
│ priority: .medium, │
88+
│ remindersListID: 3, │
89+
│ title: "Send weekly emails"
90+
│ ) │
91+
└────────────────────────────────────────────┘
92+
"""
93+
}
94+
}
95+
}
96+
4397
@Test func or() {
4498
assertQuery(
4599
Reminder.where(\.isCompleted).or(Reminder.where(\.isFlagged))

0 commit comments

Comments
 (0)