Capture Class
Capture values while matching templates.
Using an instance of this class within a Matcher will capture the matching value. The as*() APIs on the instance can be used to get the captured value.
Example
// Given a template -
// {
// "Resources": {
// "MyBar": {
// "Type": "Foo::Bar",
// "Properties": {
// "Fred": "Flob",
// }
// },
// "MyBaz": {
// "Type": "Foo::Bar",
// "Properties": {
// "Fred": "Quib",
// }
// }
// }
// }
const fredCapture = new Capture();
template.hasResourceProperties('Foo::Bar', {
Fred: fredCapture,
});
fredCapture.asString(); // returns "Flob"
fredCapture.next(); // returns true
fredCapture.asString(); // returns "Quib"
# Given a template -
# {
# "Resources": {
# "MyBar": {
# "Type": "Foo::Bar",
# "Properties": {
# "Fred": "Flob",
# }
# },
# "MyBaz": {
# "Type": "Foo::Bar",
# "Properties": {
# "Fred": "Quib",
# }
# }
# }
# }
fred_capture = Capture()
template.has_resource_properties("Foo::Bar", {
"Fred": fred_capture
})
fred_capture.as_string() # returns "Flob"
fred_capture.next() # returns true
fred_capture.as_string()
// Given a template -
// {
// "Resources": {
// "MyBar": {
// "Type": "Foo::Bar",
// "Properties": {
// "Fred": "Flob",
// }
// },
// "MyBaz": {
// "Type": "Foo::Bar",
// "Properties": {
// "Fred": "Quib",
// }
// }
// }
// }
Capture fredCapture = new Capture();
template.hasResourceProperties("Foo::Bar", Map.of(
"Fred", fredCapture));
fredCapture.asString(); // returns "Flob"
fredCapture.next(); // returns true
fredCapture.asString();
// Install: dotnet add package Amazon.CDK.Lib
// Given a template -
// {
// "Resources": {
// "MyBar": {
// "Type": "Foo::Bar",
// "Properties": {
// "Fred": "Flob",
// }
// },
// "MyBaz": {
// "Type": "Foo::Bar",
// "Properties": {
// "Fred": "Quib",
// }
// }
// }
// }
var fredCapture = new Capture();
template.HasResourceProperties("Foo::Bar", new Dictionary<string, Capture> {
{ "Fred", fredCapture }
});
fredCapture.AsString(); // returns "Flob"
fredCapture.Next(); // returns true
fredCapture.AsString();
// Install: go get github.com/aws/aws-cdk-go/awscdk/v2
// Given a template -
// {
// "Resources": {
// "MyBar": {
// "Type": "Foo::Bar",
// "Properties": {
// "Fred": "Flob",
// }
// },
// "MyBaz": {
// "Type": "Foo::Bar",
// "Properties": {
// "Fred": "Quib",
// }
// }
// }
// }
fredCapture := awscdk.NewCapture()
template.HasResourceProperties(jsii.String("Foo::Bar"), map[string]Capture{
"Fred": fredCapture,
})
fredCapture.AsString() // returns "Flob"
fredCapture.Next() // returns true
fredCapture.AsString()
Initializer
new Capture(pattern?: any)
Capture(pattern: typing.Optional[Any] = None)
new Capture(Object pattern)
new Capture(object? pattern = null)
NewCapture(Pattern interface{})
Properties
This is collected as part of the result and may be presented to the user.
Methods
asArray(): any[]def as_array(self, ) -> typing.List[Any]public List<Object> asArray()public object[] AsArray()func AsArray() *[]interface{}#An error is generated if no value is captured or if the value is not an array.
asBoolean(): booleandef as_boolean(self, ) -> boolpublic Boolean asBoolean()public bool AsBoolean()func AsBoolean() *bool#An error is generated if no value is captured or if the value is not a boolean.
asNumber(): numberdef as_number(self, ) -> int | floatpublic Number asNumber()public double AsNumber()func AsNumber() *float64#An error is generated if no value is captured or if the value is not a number.
asObject(): { [key: string]: any }def as_object(self, ) -> typing.Mapping[str, Any]public Map<String, Object> asObject()public IDictionary<string, object> AsObject()func AsObject() *map[string]interface{}#An error is generated if no value is captured or if the value is not an object.
asString(): stringdef as_string(self, ) -> strpublic String asString()public string AsString()func AsString() *string#An error is generated if no value is captured or if the value is not a string.
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#returns
Returns: true if another capture is present, false otherwise
test(actual: any): MatchResultdef test(self, actual: Any) -> MatchResultpublic MatchResult test(Object actual)public MatchResult Test(object actual)func Test(Actual interface{}) MatchResult#Every Matcher must implement this method. This method will be invoked by the assertions framework. Do not call this method directly.