MCPcopy
hub / github.com/mongodb/node-mongodb-native / specialCheck

Function specialCheck

test/tools/unified-spec-runner/match.ts:332–419  ·  test/tools/unified-spec-runner/match.ts::specialCheck
(
  actual: Document,
  expected: SpecialOperator,
  entities: EntitiesMap,
  path: string[] = [],
  checkExtraKeys: boolean
)

Source from the content-addressed store, hash-verified

330}
331
332export function specialCheck(
333 actual: Document,
334 expected: SpecialOperator,
335 entities: EntitiesMap,
336 path: string[] = [],
337 checkExtraKeys: boolean
338): void {
339 if (isUnsetOrMatchesOperator(expected)) {
340 if (actual === null || actual === undefined) return;
341
342 resultCheck(actual, expected.$$unsetOrMatches as any, entities, path, checkExtraKeys);
343 } else if (isMatchesEntityOperator(expected)) {
344 class="cm">// $$matchesEntity
345 const entity = entities.get(expected.$$matchesEntity);
346 if (
347 typeof actual === class="st">'object' && class="cm">// an object
348 actual && class="cm">// that isn't null
349 class="st">'equals' in actual && class="cm">// with an equals
350 typeof actual.equals === class="st">'function' class="cm">// method
351 ) {
352 expect(actual.equals(entity)).to.be.true;
353 } else {
354 expect(actual).to.equal(entity);
355 }
356 } else if (isMatchesHexBytesOperator(expected)) {
357 class="cm">// $$matchesHexBytes
358 const expectedBuffer = Buffer.from(expected.$$matchesHexBytes, class="st">'hex');
359 expect(expectedBuffer.every((byte, index) => byte === actual[index])).to.be.true;
360 } else if (isSessionLsidOperator(expected)) {
361 class="cm">// $$sessionLsid
362 const session = entities.getEntity(class="st">'session', expected.$$sessionLsid, false);
363 expect(session, `Session ${expected.$$sessionLsid} does not exist in entities`).to.exist;
364 const entitySessionHex = session.id!.id.toString(class="st">'hex').toUpperCase();
365 const actualSessionHex = actual.id!.toString(class="st">'hex').toUpperCase();
366
367 expect(
368 entitySessionHex,
369 `Session entity ${expected.$$sessionLsid} does not match lsid`
370 ).to.equal(actualSessionHex);
371 } else if (isTypeOperator(expected)) {
372 class="cm">// $$type
373 let ok = false;
374 const types = Array.isArray(expected.$$type) ? expected.$$type : [expected.$$type];
375 for (const type of types) {
376 ok ||= TYPE_MAP.get(type)(actual);
377 }
378 expect(ok, `Expected ${path.join(class="st">'.')} [${actual}] to be one of [${types}]`).to.be.true;
379 } else if (isExistsOperator(expected)) {
380 class="cm">// $$exists
381 const actualExists = actual !== undefined && actual !== null;
382
383 if (expected.$$exists) {
384 expect(
385 actualExists,
386 ejson`expected value at path ${path.join(class="st">'')} to exist, but received ${actual}`
387 ).to.be.true;
388 } else {
389 expect(

Callers 1

resultCheckFunction · 0.85

Calls 15

ejsonFunction · 0.90
isUnsetOrMatchesOperatorFunction · 0.85
resultCheckFunction · 0.85
isMatchesEntityOperatorFunction · 0.85
isSessionLsidOperatorFunction · 0.85
isTypeOperatorFunction · 0.85
isExistsOperatorFunction · 0.85
isMatchAsRootOperatorFunction · 0.85
isLteOperatorFunction · 0.85
getEntityMethod · 0.80

Tested by

no test coverage detected