UNPKG

@case-contract-testing/case

Version:

Next-generation contract testing suite

62 lines (61 loc) 1.88 kB
"use strict"; Object.defineProperty(exports, "__esModule", { value: true }); exports.anyNull = exports.anyBoolean = exports.anyString = exports.anyInteger = exports.anyNumber = void 0; const entities_1 = require("../../../entities"); const types_1 = require("../../../entities/types"); const meta_1 = require("./meta"); /** * Matches any number. * * When in a JSON match context, this will be following [RFC 8259 JSON](https://www.rfc-editor.org/rfc/rfc8259) - ie, not NaN or Infinity * * @param example - An example number */ const anyNumber = (example = 1.1) => ({ ...(0, entities_1.coreNumberMatcher)(example), 'case:context:matchBy': 'type', }); exports.anyNumber = anyNumber; /** * Matches any integer. * * @param example - An example integer */ const anyInteger = (example = 1) => (0, meta_1.and)((0, entities_1.coreIntegerMatcher)(example), (0, exports.anyNumber)(example)); exports.anyInteger = anyInteger; /** * Matches any string. * * @param example - An example string */ const anyString = (example = 'someString') => ({ ...(0, entities_1.coreStringMatcher)(example), 'case:context:matchBy': 'type', }); exports.anyString = anyString; /** * Matches any Boolean. * * @param example - An example boolean */ const anyBoolean = (example = true) => ({ 'case:matcher:type': types_1.BOOLEAN_MATCHER_TYPE, 'case:matcher:example': example, 'case:context:matchBy': 'type', 'case:matcher:resolvesTo': 'boolean', }); exports.anyBoolean = anyBoolean; /** * Matches any null. * * You don't actually need this matcher, you can just use the literal `null` * * @param example - An example null */ const anyNull = (example = null) => ({ 'case:matcher:type': types_1.NULL_MATCHER_TYPE, 'case:matcher:example': example, 'case:context:matchBy': 'type', 'case:matcher:resolvesTo': 'null', }); exports.anyNull = anyNull;