1Test::Unit::Assertion::URseegrexCpo(n3t)ributed Perl DocTuemsetn:t:aUtniiotn::Assertion::Regexp(3)
2
3
4

NAME

6       Test::Unit::Assertion::Regexp - Assertion with regex matching
7

SYNOPSIS

9           require Test::Unit::Assertion::Regexp;
10
11           my $assert_re =
12             Test::Unit::Assertion::Regexp->new(qr/a_pattern/);
13
14           $assert_re->do_assertion('a_string');
15
16       This is rather more detail than the average user will need.
17       Test::Unit::Assertion::Regexp objects are generated automagically by
18       Test::Unit::Assert::assert when it is passed a regular expression as
19       its first parameter.
20
21           sub test_foo {
22             ...
23             $self->assert(qr/some_pattern/, $result);
24           }
25
26       If the assertion fails then the object throws an exception with details
27       of the pattern and the string it failed to match against.
28
29       Note that if you need to do a 'string does not match this pattern' type
30       of assertion then you can do:
31
32          $self->assert(qr/(?!some_pattern)/, $some_string)
33
34       ie. Make use of the negative lookahead assertion.
35

IMPLEMENTS

37       Test::Unit::Assertion::Regexp implements the Test::Unit::Assertion
38       interface, which means it can be plugged into the Test::Unit::TestCase
39       and friends' "assert" method with no ill effects.
40

DESCRIPTION

42       The class is used by the framework to provide sensible 'automatic'
43       reports when a match fails. The old:
44
45           $self->assert(scalar($foo =~ /pattern/), "$foo didn't match /.../");
46
47       seems rather clumsy compared to this. If the regexp assertion fails,
48       then the user is given a sensible error message, with the pattern and
49       the string that failed to match it...
50

AUTHOR

52       Copyright (c) 2001 Piers Cawley <pdcawley@iterative-software.com>.
53
54       All rights reserved. This program is free software; you can
55       redistribute it and/or modify it under the same terms as Perl itself.
56

SEE ALSO

58       ·   Test::Unit::TestCase
59
60       ·   Test::Unit::Assertion
61
62
63
64perl v5.32.0                      2020-07-28  Test::Unit::Assertion::Regexp(3)
Impressum