diff --git a/source/unified-test-format/tests/valid-fail/operator-matchAsDocument.json b/source/unified-test-format/tests/valid-fail/operator-matchAsDocument.json new file mode 100644 index 0000000000..24f6be9cb8 --- /dev/null +++ b/source/unified-test-format/tests/valid-fail/operator-matchAsDocument.json @@ -0,0 +1,205 @@ +{ + "description": "operator-matchAsDocument", + "schemaVersion": "1.13", + "createEntities": [ + { + "client": { + "id": "client0" + } + }, + { + "database": { + "id": "database0", + "client": "client0", + "databaseName": "test" + } + }, + { + "collection": { + "id": "collection0", + "database": "database0", + "collectionName": "coll0" + } + } + ], + "initialData": [ + { + "collectionName": "coll0", + "databaseName": "test", + "documents": [ + { + "_id": 1, + "json": "{ \"x\": 1, \"y\": 2 }" + }, + { + "_id": 2, + "json": "1" + }, + { + "_id": 3, + "json": "[ \"foo\" ]" + }, + { + "_id": 4, + "json": "{ \"x\" }" + } + ] + } + ], + "tests": [ + { + "description": "matchAsDocument with non-matching filter", + "operations": [ + { + "name": "find", + "object": "collection0", + "arguments": { + "filter": { + "_id": 1 + }, + "limit": 1 + }, + "expectResult": [ + { + "_id": 1, + "json": { + "$$matchAsDocument": { + "x": 1, + "y": "two" + } + } + } + ] + } + ] + }, + { + "description": "matchAsDocument evaluates special operators", + "operations": [ + { + "name": "find", + "object": "collection0", + "arguments": { + "filter": { + "_id": 1 + }, + "limit": 1 + }, + "expectResult": [ + { + "_id": 1, + "json": { + "$$matchAsDocument": { + "x": 1, + "y": { + "$$exists": false + } + } + } + } + ] + } + ] + }, + { + "description": "matchAsDocument does not permit extra fields", + "operations": [ + { + "name": "find", + "object": "collection0", + "arguments": { + "filter": { + "_id": 1 + }, + "limit": 1 + }, + "expectResult": [ + { + "_id": 1, + "json": { + "$$matchAsDocument": { + "x": 1 + } + } + } + ] + } + ] + }, + { + "description": "matchAsDocument expects JSON object but given scalar", + "operations": [ + { + "name": "find", + "object": "collection0", + "arguments": { + "filter": { + "_id": 2 + }, + "limit": 1 + }, + "expectResult": [ + { + "_id": 2, + "json": { + "$$matchAsDocument": { + "$$matchAsRoot": {} + } + } + } + ] + } + ] + }, + { + "description": "matchAsDocument expects JSON object but given array", + "operations": [ + { + "name": "find", + "object": "collection0", + "arguments": { + "filter": { + "_id": 3 + }, + "limit": 1 + }, + "expectResult": [ + { + "_id": 3, + "json": { + "$$matchAsDocument": { + "$$matchAsRoot": {} + } + } + } + ] + } + ] + }, + { + "description": "matchAsDocument fails to decode Extended JSON", + "operations": [ + { + "name": "find", + "object": "collection0", + "arguments": { + "filter": { + "_id": 4 + }, + "limit": 1 + }, + "expectResult": [ + { + "_id": 4, + "json": { + "$$matchAsDocument": { + "$$matchAsRoot": {} + } + } + } + ] + } + ] + } + ] +} diff --git a/source/unified-test-format/tests/valid-fail/operator-matchAsDocument.yml b/source/unified-test-format/tests/valid-fail/operator-matchAsDocument.yml new file mode 100644 index 0000000000..ca5de0056f --- /dev/null +++ b/source/unified-test-format/tests/valid-fail/operator-matchAsDocument.yml @@ -0,0 +1,88 @@ +description: operator-matchAsDocument + +schemaVersion: "1.13" + +createEntities: + - client: + id: &client0 client0 + - database: + id: &database0 database0 + client: *client0 + databaseName: &database0Name test + - collection: + id: &collection0 collection0 + database: *database0 + collectionName: &collection0Name coll0 + +initialData: + - collectionName: *collection0Name + databaseName: *database0Name + documents: + - { _id: 1, json: '{ "x": 1, "y": 2 }' } + # Documents with non-objects or invalid JSON + - { _id: 2, json: '1' } + - { _id: 3, json: '[ "foo" ]' } + - { _id: 4, json: '{ "x" }' } + +tests: + - description: matchAsDocument with non-matching filter + operations: + - name: find + object: *collection0 + arguments: + filter: { _id : 1 } + limit: 1 + expectResult: + - { _id: 1, json: { $$matchAsDocument: { x: 1, y: "two" } } } + - + description: matchAsDocument evaluates special operators + operations: + - name: find + object: *collection0 + arguments: + filter: { _id : 1 } + limit: 1 + expectResult: + - { _id: 1, json: { $$matchAsDocument: { x: 1, y: { $$exists: false } } } } + - + description: matchAsDocument does not permit extra fields + operations: + - name: find + object: *collection0 + arguments: + filter: { _id : 1 } + limit: 1 + expectResult: + - { _id: 1, json: { $$matchAsDocument: { x: 1 } } } + - + description: matchAsDocument expects JSON object but given scalar + operations: + - name: find + object: *collection0 + arguments: + filter: { _id : 2 } + limit: 1 + expectResult: + # The following $$matchAsRoot expression would match any document, so + # this ensures the failure is due to the actual value. + - { _id: 2, json: &match_any_document { $$matchAsDocument: { $$matchAsRoot: { } } } } + - + description: matchAsDocument expects JSON object but given array + operations: + - name: find + object: *collection0 + arguments: + filter: { _id : 3 } + limit: 1 + expectResult: + - { _id: 3, json: *match_any_document } + - + description: matchAsDocument fails to decode Extended JSON + operations: + - name: find + object: *collection0 + arguments: + filter: { _id : 4 } + limit: 1 + expectResult: + - { _id: 4, json: *match_any_document } diff --git a/source/unified-test-format/tests/valid-fail/operator-matchAsRoot.json b/source/unified-test-format/tests/valid-fail/operator-matchAsRoot.json new file mode 100644 index 0000000000..ec6309418c --- /dev/null +++ b/source/unified-test-format/tests/valid-fail/operator-matchAsRoot.json @@ -0,0 +1,67 @@ +{ + "description": "operator-matchAsRoot", + "schemaVersion": "1.13", + "createEntities": [ + { + "client": { + "id": "client0" + } + }, + { + "database": { + "id": "database0", + "client": "client0", + "databaseName": "test" + } + }, + { + "collection": { + "id": "collection0", + "database": "database0", + "collectionName": "coll0" + } + } + ], + "initialData": [ + { + "collectionName": "coll0", + "databaseName": "test", + "documents": [ + { + "_id": 1, + "x": { + "y": 2, + "z": 3 + } + } + ] + } + ], + "tests": [ + { + "description": "matchAsRoot with nested document does not match", + "operations": [ + { + "name": "find", + "object": "collection0", + "arguments": { + "filter": { + "_id": 1 + }, + "limit": 1 + }, + "expectResult": [ + { + "_id": 1, + "x": { + "$$matchAsRoot": { + "y": 3 + } + } + } + ] + } + ] + } + ] +} diff --git a/source/unified-test-format/tests/valid-fail/operator-matchAsRoot.yml b/source/unified-test-format/tests/valid-fail/operator-matchAsRoot.yml new file mode 100644 index 0000000000..77e3ce5790 --- /dev/null +++ b/source/unified-test-format/tests/valid-fail/operator-matchAsRoot.yml @@ -0,0 +1,33 @@ +description: operator-matchAsRoot + +schemaVersion: "1.13" + +createEntities: + - client: + id: &client0 client0 + - database: + id: &database0 database0 + client: *client0 + databaseName: &database0Name test + - collection: + id: &collection0 collection0 + database: *database0 + collectionName: &collection0Name coll0 + +initialData: + - collectionName: *collection0Name + databaseName: *database0Name + documents: + - { _id: 1, x: { y: 2, z: 3 } } + +tests: + - + description: matchAsRoot with nested document does not match + operations: + - name: find + object: *collection0 + arguments: + filter: { _id : 1 } + limit: 1 + expectResult: + - { _id: 1, x: { $$matchAsRoot: { y: 3 } } } diff --git a/source/unified-test-format/tests/valid-pass/matches-lte-operator.json b/source/unified-test-format/tests/valid-pass/operator-lte.json similarity index 97% rename from source/unified-test-format/tests/valid-pass/matches-lte-operator.json rename to source/unified-test-format/tests/valid-pass/operator-lte.json index 4de65c5838..4a13b16d15 100644 --- a/source/unified-test-format/tests/valid-pass/matches-lte-operator.json +++ b/source/unified-test-format/tests/valid-pass/operator-lte.json @@ -1,5 +1,5 @@ { - "description": "matches-lte-operator", + "description": "operator-lte", "schemaVersion": "1.9", "createEntities": [ { diff --git a/source/unified-test-format/tests/valid-pass/matches-lte-operator.yml b/source/unified-test-format/tests/valid-pass/operator-lte.yml similarity index 89% rename from source/unified-test-format/tests/valid-pass/matches-lte-operator.yml rename to source/unified-test-format/tests/valid-pass/operator-lte.yml index 4bec571f02..2db574143b 100644 --- a/source/unified-test-format/tests/valid-pass/matches-lte-operator.yml +++ b/source/unified-test-format/tests/valid-pass/operator-lte.yml @@ -1,6 +1,6 @@ -description: matches-lte-operator +description: operator-lte -# Note: $$lte is not technically in the 1.8 schema but was introduced at the same time. +# Note: $$lte was introduced alongside schema changes for CSOT schemaVersion: "1.9" createEntities: diff --git a/source/unified-test-format/tests/valid-pass/operator-matchAsDocument.json b/source/unified-test-format/tests/valid-pass/operator-matchAsDocument.json new file mode 100644 index 0000000000..fd8b514d4a --- /dev/null +++ b/source/unified-test-format/tests/valid-pass/operator-matchAsDocument.json @@ -0,0 +1,124 @@ +{ + "description": "operator-matchAsDocument", + "schemaVersion": "1.13", + "createEntities": [ + { + "client": { + "id": "client0" + } + }, + { + "database": { + "id": "database0", + "client": "client0", + "databaseName": "test" + } + }, + { + "collection": { + "id": "collection0", + "database": "database0", + "collectionName": "coll0" + } + } + ], + "initialData": [ + { + "collectionName": "coll0", + "databaseName": "test", + "documents": [ + { + "_id": 1, + "json": "{ \"x\": 1, \"y\": 2.0 }" + }, + { + "_id": 2, + "json": "{ \"x\": { \"$oid\": \"57e193d7a9cc81b4027498b5\" } }" + } + ] + } + ], + "tests": [ + { + "description": "matchAsDocument performs flexible numeric comparisons", + "operations": [ + { + "name": "find", + "object": "collection0", + "arguments": { + "filter": { + "_id": 1 + }, + "limit": 1 + }, + "expectResult": [ + { + "_id": 1, + "json": { + "$$matchAsDocument": { + "x": 1, + "y": 2 + } + } + } + ] + } + ] + }, + { + "description": "matchAsDocument evaluates special operators", + "operations": [ + { + "name": "find", + "object": "collection0", + "arguments": { + "filter": { + "_id": 1 + }, + "limit": 1 + }, + "expectResult": [ + { + "_id": 1, + "json": { + "$$matchAsDocument": { + "x": 1, + "y": { + "$$exists": true + } + } + } + } + ] + } + ] + }, + { + "description": "matchAsDocument decodes Extended JSON", + "operations": [ + { + "name": "find", + "object": "collection0", + "arguments": { + "filter": { + "_id": 2 + }, + "limit": 1 + }, + "expectResult": [ + { + "_id": 2, + "json": { + "$$matchAsDocument": { + "x": { + "$$type": "objectId" + } + } + } + } + ] + } + ] + } + ] +} diff --git a/source/unified-test-format/tests/valid-pass/operator-matchAsDocument.yml b/source/unified-test-format/tests/valid-pass/operator-matchAsDocument.yml new file mode 100644 index 0000000000..9a811faaa9 --- /dev/null +++ b/source/unified-test-format/tests/valid-pass/operator-matchAsDocument.yml @@ -0,0 +1,54 @@ +description: operator-matchAsDocument + +schemaVersion: "1.13" + +createEntities: + - client: + id: &client0 client0 + - database: + id: &database0 database0 + client: *client0 + databaseName: &database0Name test + - collection: + id: &collection0 collection0 + database: *database0 + collectionName: &collection0Name coll0 + +initialData: + - collectionName: *collection0Name + databaseName: *database0Name + documents: + - { _id: 1, json: '{ "x": 1, "y": 2.0 }' } + - { _id: 2, json: '{ "x": { "$oid": "57e193d7a9cc81b4027498b5" } }' } + +tests: + - + description: matchAsDocument performs flexible numeric comparisons + operations: + - name: find + object: *collection0 + arguments: + filter: { _id : 1 } + limit: 1 + expectResult: + - { _id: 1, json: { $$matchAsDocument: { x: 1.0, y: 2 } } } + - + description: matchAsDocument evaluates special operators + operations: + - name: find + object: *collection0 + arguments: + filter: { _id : 1 } + limit: 1 + expectResult: + - { _id: 1, json: { $$matchAsDocument: { x: 1, y: { $$exists: true } } } } + - + description: matchAsDocument decodes Extended JSON + operations: + - name: find + object: *collection0 + arguments: + filter: { _id : 2 } + limit: 1 + expectResult: + - { _id: 2, json: { $$matchAsDocument: { x: { $$type: "objectId" } } } } diff --git a/source/unified-test-format/tests/valid-pass/operator-matchAsRoot.json b/source/unified-test-format/tests/valid-pass/operator-matchAsRoot.json new file mode 100644 index 0000000000..1966e3b377 --- /dev/null +++ b/source/unified-test-format/tests/valid-pass/operator-matchAsRoot.json @@ -0,0 +1,151 @@ +{ + "description": "operator-matchAsRoot", + "schemaVersion": "1.13", + "createEntities": [ + { + "client": { + "id": "client0" + } + }, + { + "database": { + "id": "database0", + "client": "client0", + "databaseName": "test" + } + }, + { + "collection": { + "id": "collection0", + "database": "database0", + "collectionName": "coll0" + } + } + ], + "initialData": [ + { + "collectionName": "coll0", + "databaseName": "test", + "documents": [ + { + "_id": 1, + "x": { + "y": 2, + "z": 3 + } + }, + { + "_id": 2, + "json": "{ \"x\": 1, \"y\": 2 }" + } + ] + } + ], + "tests": [ + { + "description": "matchAsRoot with nested document", + "operations": [ + { + "name": "find", + "object": "collection0", + "arguments": { + "filter": { + "_id": 1 + }, + "limit": 1 + }, + "expectResult": [ + { + "_id": 1, + "x": { + "$$matchAsRoot": { + "y": 2 + } + } + } + ] + } + ] + }, + { + "description": "matchAsRoot performs flexible numeric comparisons", + "operations": [ + { + "name": "find", + "object": "collection0", + "arguments": { + "filter": { + "_id": 1 + }, + "limit": 1 + }, + "expectResult": [ + { + "_id": 1, + "x": { + "$$matchAsRoot": { + "y": 2 + } + } + } + ] + } + ] + }, + { + "description": "matchAsRoot evaluates special operators", + "operations": [ + { + "name": "find", + "object": "collection0", + "arguments": { + "filter": { + "_id": 1 + }, + "limit": 1 + }, + "expectResult": [ + { + "_id": 1, + "x": { + "$$matchAsRoot": { + "y": 2, + "z": { + "$$exists": true + } + } + } + } + ] + } + ] + }, + { + "description": "matchAsRoot with matchAsDocument", + "operations": [ + { + "name": "find", + "object": "collection0", + "arguments": { + "filter": { + "_id": 2 + }, + "limit": 1 + }, + "expectResult": [ + { + "_id": 2, + "json": { + "$$matchAsDocument": { + "$$matchAsRoot": { + "x": 1 + } + } + } + } + ] + } + ] + } + ] +} diff --git a/source/unified-test-format/tests/valid-pass/operator-matchAsRoot.yml b/source/unified-test-format/tests/valid-pass/operator-matchAsRoot.yml new file mode 100644 index 0000000000..bbf738f04a --- /dev/null +++ b/source/unified-test-format/tests/valid-pass/operator-matchAsRoot.yml @@ -0,0 +1,64 @@ +description: operator-matchAsRoot + +schemaVersion: "1.13" + +createEntities: + - client: + id: &client0 client0 + - database: + id: &database0 database0 + client: *client0 + databaseName: &database0Name test + - collection: + id: &collection0 collection0 + database: *database0 + collectionName: &collection0Name coll0 + +initialData: + - collectionName: *collection0Name + databaseName: *database0Name + documents: + - { _id: 1, x: { y: 2, z: 3 } } + - { _id: 2, json: '{ "x": 1, "y": 2 }' } + +tests: + - + description: matchAsRoot with nested document + operations: + - name: find + object: *collection0 + arguments: + filter: { _id : 1 } + limit: 1 + expectResult: + - { _id: 1, x: { $$matchAsRoot: { y: 2 } } } + - + description: matchAsRoot performs flexible numeric comparisons + operations: + - name: find + object: *collection0 + arguments: + filter: { _id : 1 } + limit: 1 + expectResult: + - { _id: 1, x: { $$matchAsRoot: { y: 2.0 } } } + - + description: matchAsRoot evaluates special operators + operations: + - name: find + object: *collection0 + arguments: + filter: { _id : 1 } + limit: 1 + expectResult: + - { _id: 1, x: { $$matchAsRoot: { y: 2, z: { $$exists: true } } } } + - + description: matchAsRoot with matchAsDocument + operations: + - name: find + object: *collection0 + arguments: + filter: { _id : 2 } + limit: 1 + expectResult: + - { _id: 2, json: { $$matchAsDocument: { $$matchAsRoot: { x: 1 } } } }