@contract-case/case-core
Version:
Core functionality for the ContractCase contract testing suite
70 lines • 3.02 kB
JavaScript
;
Object.defineProperty(exports, "__esModule", { value: true });
exports.stringifiedJson = exports.encodedStringBase64 = exports.stringSuffix = exports.stringPrefix = exports.stringContaining = void 0;
const case_entities_internal_1 = require("@contract-case/case-entities-internal");
const primitives_1 = require("./primitives");
/**
* Matches any string that contains the given substring.
*
* @param substring - The substring that the matcher must contain
* @param example - An example string that passes this matcher
*/
const stringContaining = (substring, example) => ({
'_case:matcher:type': case_entities_internal_1.STRING_CONTAINS_TYPE,
'_case:matcher:contains': substring,
'_case:matcher:resolvesTo': 'string',
'_case:matcher:example': example,
});
exports.stringContaining = stringContaining;
/**
* Matches any string that begins with the given constant string prefix
*
* @param prefix - The prefix string. Must be a string and not a matcher
* @param suffix - An optional string or matcher to match against the suffix
*/
const stringPrefix = (prefix, suffix = (0, primitives_1.anyString)()) => ({
'_case:matcher:type': case_entities_internal_1.STRING_PREFIX_TYPE,
'_case:matcher:prefix': prefix,
'_case:matcher:suffix': suffix,
'_case:matcher:resolvesTo': 'string',
});
exports.stringPrefix = stringPrefix;
/**
* Matches any string that ends with the given constant string suffix
*
* @param prefix - A string or matcher to match against the prefix. If you don't mind what the prefix is, pass `anyString()`
* @param suffix - The suffix string. Must be a string and not a matcher
*/
const stringSuffix = (prefix, suffix) => ({
'_case:matcher:type': case_entities_internal_1.STRING_SUFFIX_TYPE,
'_case:matcher:prefix': prefix !== undefined ? prefix : (0, primitives_1.anyString)(),
'_case:matcher:suffix': suffix,
'_case:matcher:resolvesTo': 'string',
});
exports.stringSuffix = stringSuffix;
/**
* Matches any string that matches a base64 encoded version of the given string or string matcher
*
* WARNING: Since many strings are accidentally decodable as base64, this matcher is
* best combined with a more restrictive string matcher (eg stringifiedJson()).
*
* @param child - The string or string matcher to match against
*/
const encodedStringBase64 = (child) => ({
'_case:matcher:type': case_entities_internal_1.BASE64_ENCODED_TYPE,
'_case:matcher:child': child,
'_case:matcher:resolvesTo': 'string',
});
exports.encodedStringBase64 = encodedStringBase64;
/**
* Matches any string that matches a JSON.stringify()ed version of the given object (which may itself contain matchers)
*
* @param child - The string or string matcher to match against
*/
const stringifiedJson = (child) => ({
'_case:matcher:type': case_entities_internal_1.JSON_STRINGIFIED_TYPE,
'_case:matcher:child': child,
'_case:matcher:resolvesTo': 'string',
});
exports.stringifiedJson = stringifiedJson;
//# sourceMappingURL=strings.js.map