1 | "use strict";
|
2 | Object.defineProperty(exports, "__esModule", { value: true });
|
3 | const matcher_1 = require("./matcher");
|
4 | var LimitType;
|
5 | (function (LimitType) {
|
6 | LimitType[LimitType["LessThan"] = 0] = "LessThan";
|
7 | LimitType[LimitType["GreaterThan"] = 1] = "GreaterThan";
|
8 | })(LimitType || (LimitType = {}));
|
9 | class NumberMatcher extends matcher_1.Matcher {
|
10 | toBeLessThan(upperLimit) {
|
11 | this._matchAgainstLimit(upperLimit, LimitType.LessThan);
|
12 | }
|
13 | toBeGreaterThan(lowerLimit) {
|
14 | this._matchAgainstLimit(lowerLimit, LimitType.GreaterThan);
|
15 | }
|
16 | _matchAgainstLimit(limit, limitType) {
|
17 | const limitTypeName = LimitType[limitType];
|
18 | this._validateValues(limit, `toBe${LimitType[limitType]}`, `${limitType === LimitType.LessThan ? "upper" : "lower"} limit`);
|
19 | const readableLimitType = limitTypeName.replace(/([a-z])([A-Z])/, "$1 $2").toLowerCase();
|
20 | const exceedsLimit = limitType === LimitType.LessThan ? this.actualValue < limit : this.actualValue > limit;
|
21 | this._registerMatcher(exceedsLimit === this.shouldMatch, `Expected ${this.actualValue} ${!this.shouldMatch ? "not " : ""}to be ${readableLimitType} ${limit}.`, `a number ${!this.shouldMatch ? "not " : ""}${readableLimitType} ${limit}`, {
|
22 | actual: this.actualValue,
|
23 | limit
|
24 | });
|
25 | }
|
26 | _validateValues(limit, functionName, limitType) {
|
27 | if (limit === null || limit === undefined) {
|
28 | throw new TypeError(`${functionName} ${limitType} must not be null or undefined.`);
|
29 | }
|
30 | }
|
31 | }
|
32 | exports.NumberMatcher = NumberMatcher;
|
33 |
|
\ | No newline at end of file |