Skip to content

Commit b43fbc7

Browse files
committed
valid-fail tests for $$matchAsDocument with unexpected JSON values
1 parent 612020c commit b43fbc7

File tree

2 files changed

+88
-5
lines changed

2 files changed

+88
-5
lines changed

source/unified-test-format/tests/valid-fail/operator-matchAsDocument.json

Lines changed: 60 additions & 2 deletions
Some generated files are not rendered by default. Learn more about customizing how changed files appear on GitHub.

source/unified-test-format/tests/valid-fail/operator-matchAsDocument.yml

Lines changed: 28 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -19,7 +19,10 @@ initialData:
1919
databaseName: *database0Name
2020
documents:
2121
- { _id: 1, json: '{ "x": 1, "y": 2 }' }
22-
- { _id: 2, json: '{ "x" }' }
22+
# Documents with non-objects or invalid JSON
23+
- { _id: 2, json: '1' }
24+
- { _id: 3, json: '[ "foo" ]' }
25+
- { _id: 4, json: '{ "x" }' }
2326

2427
tests:
2528
- description: matchAsDocument with non-matching filter
@@ -52,12 +55,34 @@ tests:
5255
expectResult:
5356
- { _id: 1, json: { $$matchAsDocument: { x: 1 } } }
5457
-
55-
description: matchAsDocument fails to decode Extended JSON
58+
description: matchAsDocument expects JSON object but given scalar
5659
operations:
5760
- name: find
5861
object: *collection0
5962
arguments:
6063
filter: { _id : 2 }
6164
limit: 1
6265
expectResult:
63-
- { _id: 2, json: { $$matchAsDocument: { x: 1 } } }
66+
# The following $$matchAsRoot expression would match any document, so
67+
# this ensures the failure is due to the actual value.
68+
- { _id: 2, json: &match_any_document { $$matchAsDocument: { $$matchAsRoot: { } } } }
69+
-
70+
description: matchAsDocument expects JSON object but given array
71+
operations:
72+
- name: find
73+
object: *collection0
74+
arguments:
75+
filter: { _id : 3 }
76+
limit: 1
77+
expectResult:
78+
- { _id: 3, json: *match_any_document }
79+
-
80+
description: matchAsDocument fails to decode Extended JSON
81+
operations:
82+
- name: find
83+
object: *collection0
84+
arguments:
85+
filter: { _id : 4 }
86+
limit: 1
87+
expectResult:
88+
- { _id: 4, json: *match_any_document }

0 commit comments

Comments
 (0)