1 | import { InspectionFailure, PropertyMatcher } from './have-resource';
|
2 |
|
3 |
|
4 |
|
5 |
|
6 |
|
7 |
|
8 | export declare function objectLike<A extends object>(pattern: A): PropertyMatcher;
|
9 |
|
10 |
|
11 |
|
12 |
|
13 |
|
14 | export declare function deepObjectLike<A extends object>(pattern: A): PropertyMatcher;
|
15 |
|
16 |
|
17 |
|
18 |
|
19 |
|
20 |
|
21 | export declare function exactValue(expected: any): PropertyMatcher;
|
22 |
|
23 |
|
24 |
|
25 | export declare function arrayWith(...elements: any[]): PropertyMatcher;
|
26 |
|
27 |
|
28 |
|
29 |
|
30 |
|
31 |
|
32 | export declare function failMatcher(inspection: InspectionFailure, error: string): boolean;
|
33 |
|
34 |
|
35 |
|
36 |
|
37 |
|
38 |
|
39 | export declare function match(value: any, matcher: any, inspection: InspectionFailure): boolean;
|
40 |
|
41 |
|
42 |
|
43 | export declare function stringLike(pattern: string): PropertyMatcher;
|
44 |
|
45 |
|
46 |
|
47 | export declare function anything(): PropertyMatcher;
|
48 |
|
49 |
|
50 |
|
51 | export declare function notMatching(matcher: any): PropertyMatcher;
|
52 | export declare type TypeValidator<T> = (x: any) => x is T;
|
53 |
|
54 |
|
55 |
|
56 |
|
57 |
|
58 |
|
59 |
|
60 |
|
61 |
|
62 |
|
63 |
|
64 |
|
65 | export declare class Capture<T = any> {
|
66 | private readonly typeValidator?;
|
67 | |
68 |
|
69 |
|
70 | static anyType(): Capture<any>;
|
71 | |
72 |
|
73 |
|
74 | static aString(): Capture<string>;
|
75 | |
76 |
|
77 |
|
78 | static a<T>(validator: TypeValidator<T>): Capture<T>;
|
79 | private _value?;
|
80 | private _didCapture;
|
81 | private _wasInvoked;
|
82 | protected constructor(typeValidator?: TypeValidator<T> | undefined);
|
83 | /**
|
84 | * Capture the value if the inner matcher successfully matches it
|
85 | *
|
86 | * If no matcher is given, `anything()` is assumed.
|
87 | *
|
88 | * And exception will be thrown if the inner matcher returns `true` and
|
89 | * the value turns out to be of a different type than the `Capture` object
|
90 | * is expecting.
|
91 | */
|
92 | capture(matcher?: any): PropertyMatcher;
|
93 | /**
|
94 | * Whether a value was successfully captured
|
95 | */
|
96 | get didCapture(): boolean;
|
97 | /**
|
98 | * Return the value that was captured
|
99 | *
|
100 | * Throws an exception if now value was captured
|
101 | */
|
102 | get capturedValue(): T;
|
103 | }
|
104 | /**
|
105 | * Match on the innards of a JSON string, instead of the complete string
|
106 | */
|
107 | export declare function encodedJson(matcher: any): PropertyMatcher;
|
108 | /**
|
109 | * Make a matcher out of the given argument if it's not a matcher already
|
110 | *
|
111 | * If it's not a matcher, it will be treated as a literal.
|
112 | */
|
113 | export declare function matcherFrom(matcher: any): PropertyMatcher;
|
114 | /**
|
115 | * Annotate a matcher with toJSON
|
116 | *
|
117 | * We will JSON.stringify() values if we have a match failure, but for matchers this
|
118 | * would show (in traditional JS fashion) something like '[function Function]', or more
|
119 | * accurately nothing at all since functions cannot be JSONified.
|
120 | *
|
121 | * We override to JSON() in order to produce a readadable version of the matcher.
|
122 | */
|
123 | export declare function annotateMatcher<A extends object>(how: A, matcher: PropertyMatcher): PropertyMatcher;
|