Ecosyste.ms: Awesome
An open API service indexing awesome lists of open source software.
https://github.com/kentnl/test-deep-filter
Perform a filter on a matched element before doing sub-matching
https://github.com/kentnl/test-deep-filter
Last synced: 4 days ago
JSON representation
Perform a filter on a matched element before doing sub-matching
- Host: GitHub
- URL: https://github.com/kentnl/test-deep-filter
- Owner: kentnl
- License: other
- Created: 2015-08-14T09:29:47.000Z (over 9 years ago)
- Default Branch: master
- Last Pushed: 2017-03-07T10:58:51.000Z (over 7 years ago)
- Last Synced: 2023-08-20T22:49:27.718Z (about 1 year ago)
- Language: Perl
- Size: 55.7 KB
- Stars: 0
- Watchers: 2
- Forks: 0
- Open Issues: 0
-
Metadata Files:
- Readme: README.mkdn
- Changelog: Changes
- Contributing: CONTRIBUTING.pod
- License: LICENSE
Awesome Lists containing this project
README
# NAME
Test::Deep::Filter - Perform a filter on a matched element before doing sub-matching
# VERSION
version 0.001002
# DESCRIPTION
This module exists so that one can apply some kind of transform of the content
of some node, before applying a deep testing structure against it.This is especially the kind of domain Test::Deep::YAML and Test::Deep::JSON are
targeted at, but implemented in a more generic way.cmp_deeply( $got, { payload => filter(\&decode_json, { x => 1 }) } )
This would perform matching against a `Perl` data structure called `$got`,
and find its key called `payload`, and, if existing, filter the key via
`&decode_json`, and then compare the resulting structure with
`{ x => 1 }`.This would in theory be equivalent to:
cmp_deeply( $got, { payload => json({ x => 1 }) } )
Except may be tailored for what ever local decoding scheme you may require,
e.g.:cmp_deeply( $got, {
payload => filter(sub {
my ( $got ) = @_;
return parse_ini( $got );
}, { x => 1 })
});# FUNCTIONS
## `filter`
my $object = filter( \&filter_function, $expected );
cmp_deeply( $got, filter( \&filter_function, $expected ));
A `filter` can take any value into `&filter_function`, and return any value
and the `Test::Deep` infrastructure will handle the rest.If the value cannot be parsed, or is of a type you cannot handle, or the
internal logic returns an invalid value ( including any failures in internal
logic that fail to parse, etc) then you must cause the function to throw an
exception with "die", and the nested `$expected` will be assumed to be false.The "die" message will be used as a diagnostic for why the match failed.
# AUTHOR
Kent Fredric
# COPYRIGHT AND LICENSE
This software is copyright (c) 2017 by Kent Fredric .
This is free software; you can redistribute it and/or modify it under
the same terms as the Perl 5 programming language system itself.