|
| 1 | +local SHORTHAND_MATCHER_PREFIX = '$$shorthand_matcher$$'; |
| 2 | + |
| 3 | + |
| 4 | +local any_matcher() = |
| 5 | + { |
| 6 | + '$$matcher_type$$': 'any', |
| 7 | + }; |
| 8 | + |
| 9 | +local string_matcher(string, case_sensitive=true) = |
| 10 | + { |
| 11 | + '$$matcher_type$$': 'string', |
| 12 | + '$$matcher_params$$': { |
| 13 | + value: string, |
| 14 | + case_sensitive: case_sensitive, |
| 15 | + }, |
| 16 | + }; |
| 17 | + |
| 18 | +local regex_matcher(regex) = |
| 19 | + { |
| 20 | + '$$matcher_type$$': 'regex', |
| 21 | + '$$matcher_params$$': regex, |
| 22 | + }; |
| 23 | + |
| 24 | +local int_matcher(int) = |
| 25 | + { |
| 26 | + '$$matcher_type$$': 'int', |
| 27 | + '$$matcher_params$$': int, |
| 28 | + }; |
| 29 | + |
| 30 | +local float_matcher(float) = |
| 31 | + { |
| 32 | + '$$matcher_type$$': 'float', |
| 33 | + '$$matcher_params$$': float, |
| 34 | + }; |
| 35 | + |
| 36 | +local json_matcher(json, subset=false) = |
| 37 | + { |
| 38 | + '$$matcher_type$$': 'json', |
| 39 | + '$$matcher_params$$': { |
| 40 | + value: json, |
| 41 | + subset: subset, |
| 42 | + }, |
| 43 | + }; |
| 44 | + |
| 45 | +local array_matcher(array, subset=false) = |
| 46 | + { |
| 47 | + '$$matcher_type$$': 'array', |
| 48 | + '$$matcher_params$$': { |
| 49 | + value: array, |
| 50 | + subset: subset, |
| 51 | + }, |
| 52 | + }; |
| 53 | + |
| 54 | +local len_matcher(len) = |
| 55 | + { |
| 56 | + '$$matcher_type$$': 'len', |
| 57 | + '$$matcher_params$$': len, |
| 58 | + }; |
| 59 | + |
| 60 | +local and_matcher(matchers) = |
| 61 | + { |
| 62 | + '$$matcher_type$$': 'and', |
| 63 | + '$$matcher_params$$': matchers, |
| 64 | + }; |
| 65 | + |
| 66 | +local or_matcher(matchers) = |
| 67 | + { |
| 68 | + '$$matcher_type$$': 'or', |
| 69 | + '$$matcher_params$$': matchers, |
| 70 | + }; |
| 71 | + |
| 72 | +local range_matcher(from, to) = |
| 73 | + { |
| 74 | + '$$matcher_type$$': 'range', |
| 75 | + '$$matcher_params$$': { |
| 76 | + from: from, |
| 77 | + to: to, |
| 78 | + }, |
| 79 | + }; |
| 80 | + |
| 81 | +local type_matcher(type) = |
| 82 | + { |
| 83 | + '$$matcher_type$$': 'type::%s' % type, |
| 84 | + '$$matcher_params$$': null, |
| 85 | + }; |
| 86 | + |
1 | 87 | { |
2 | 88 | spec(steps):: std.manifestJson( |
3 | 89 | { |
4 | 90 | steps: steps, |
5 | 91 | }, |
6 | 92 | ), |
| 93 | + |
| 94 | + type: { |
| 95 | + int():: type_matcher('int'), |
| 96 | + float():: type_matcher('float'), |
| 97 | + string():: type_matcher('string'), |
| 98 | + object():: type_matcher('object'), |
| 99 | + array():: type_matcher('array'), |
| 100 | + }, |
| 101 | + |
| 102 | + key(matcher):: '%s%s' % [SHORTHAND_MATCHER_PREFIX, std.manifestJsonEx(matcher, '')], |
| 103 | + any():: any_matcher(), |
| 104 | + regex(regex):: regex_matcher(regex), |
| 105 | + string(string, case_sensitive=true):: string_matcher(string, case_sensitive), |
| 106 | + int(int):: int_matcher(int), |
| 107 | + float(float):: float_matcher(float), |
| 108 | + json(json, subset=false):: json_matcher(json, subset), |
| 109 | + array(array, subset=false):: array_matcher(array, subset), |
| 110 | + len(len):: len_matcher(len), |
| 111 | + and(matchers):: and_matcher(matchers), |
| 112 | + or(matchers):: or_matcher(matchers), |
| 113 | + range(from, to):: range_matcher(from, to), |
7 | 114 | } |
0 commit comments