Skip to content

Commit 045a745

Browse files
natemannmbrandonw
andauthored
check if results are expected to be empty (pointfreeco#65)
* check if results are expected to be empty test example fixes fix * clean up * wip --------- Co-authored-by: Brandon Williams <[email protected]>
1 parent 1146653 commit 045a745

File tree

3 files changed

+34
-9
lines changed

3 files changed

+34
-9
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/InsertTests.swift

Lines changed: 0 additions & 9 deletions
Original file line numberDiff line numberDiff line change
@@ -500,15 +500,6 @@ extension SnapshotTests {
500500
DO NOTHING
501501
RETURNING "reminderID", "tagID"
502502
"""
503-
} results: {
504-
"""
505-
┌──────────────────┐
506-
│ ReminderTag( │
507-
│ reminderID: 1, │
508-
│ tagID: 1 │
509-
│ ) │
510-
└──────────────────┘
511-
"""
512503
}
513504
}
514505

Tests/StructuredQueriesTests/WhereTests.swift

Lines changed: 18 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -42,6 +42,24 @@ extension SnapshotTests {
4242
}
4343
}
4444

45+
@Test(.snapshots(record: .never)) func emptyResults() {
46+
withKnownIssue("This assert should fail") {
47+
assertQuery(
48+
Reminder.where { $0.isCompleted && !$0.isCompleted }
49+
) {
50+
"""
51+
SELECT "reminders"."id", "reminders"."assignedUserID", "reminders"."dueDate", "reminders"."isCompleted", "reminders"."isFlagged", "reminders"."notes", "reminders"."priority", "reminders"."remindersListID", "reminders"."title"
52+
FROM "reminders"
53+
WHERE ("reminders"."isCompleted") AND ("reminders"."isFlagged")
54+
"""
55+
} results: {
56+
"""
57+
Results
58+
"""
59+
}
60+
}
61+
}
62+
4563
@Test func or() {
4664
assertQuery(
4765
Reminder.where(\.isCompleted).or(Reminder.where(\.isFlagged))

0 commit comments

Comments
 (0)