Skip to content
v2.275.0

Matcher Class ​

Represents a matcher that can perform special data matching capabilities between a given pattern and a target.

Example ​

ts
// Given a template -
// {
//   "Resources": {
//     "MyBar": {
//       "Type": "Foo::Bar",
//       "Properties": {
//         "Fred": {
//           "Wobble": ["Flob", "Flib"],
//         }
//       }
//     }
//   }
// }

// The following will NOT throw an assertion error
template.hasResourceProperties('Foo::Bar', {
  Fred: {
    Wobble: [ Match.anyValue(), Match.anyValue() ],
  },
});

// The following will throw an assertion error
template.hasResourceProperties('Foo::Bar', {
  Fred: {
    Wimble: Match.anyValue(),
  },
});

Initializer ​

ts
new Matcher()
python
Matcher()
java
new Matcher()
csharp
new Matcher()
go
NewMatcher()

Properties ​

namestringnamestrnameStringNamestringName*string#
A name for the matcher.

This is collected as part of the result and may be presented to the user.

Methods ​

isMatcher(x: any): boolean@staticmethod def is_matcher(x: Any) -> boolpublic static Boolean isMatcher(Object x)public static bool IsMatcher(object x)func IsMatcher(X interface{}) *boolstatic#
Check whether the provided object is a subtype of the `IMatcher`.
test(actual: any): MatchResultdef test(self, actual: Any) -> MatchResultpublic MatchResult test(Object actual)public MatchResult Test(object actual)func Test(Actual interface{}) MatchResult#
Test whether a target matches the provided pattern.

Every Matcher must implement this method. This method will be invoked by the assertions framework. Do not call this method directly.

1 parameter · returns

Parameters

  • actualactualactualactualActual — the target to match.

Returns: the list of match failures. An empty array denotes a successful match.