1 2 3 4 5 6 7 8 9 10 11 12 13 14 15 16 17 18 19 20 21 22 23 24 25 26 27 28 29 30 31 32 33 34 35 36 37 38 39 40 41 42 43 44 45 46 47 48 49 50 51 52 53 54 55
|
#!/usr/bin/perl
use v5.14;
use warnings;
use Test2::V0;
use Syntax::Operator::Eqr;
BEGIN { plan skip_all => "No PL_infix_plugin" unless XS::Parse::Infix::HAVE_PL_INFIX_PLUGIN; }
my $warnings = 0;
$SIG{__WARN__} = sub { $warnings++ };
ok( "abc" eqr "abc", 'identical strings');
ok(!("abc" eqr "def"), 'different strings');
ok( undef eqr undef, 'undef is undef');
ok(!("abc" eqr undef), 'undef is not a string');
ok(!("" eqr undef), 'undef is not empty string');
ok( "ghi" eqr qr/h/, 'string pattern match');
ok(!("ghi" eqr qr/H/), 'string pattern non-match');
ok(!("x" eqr qr/abc/), 'string pattern non-match minimum length');
my $pat = qr/i/;
ok( "ghi" eqr $pat, 'string pattern match from variable');
# overloaded 'eq' operator
{
my $equal;
package Greedy {
use overload 'eq' => sub { $equal };
}
my $greedy = bless [], "Greedy";
$equal = 1;
ok( $greedy eqr "abc", 'Greedy is abc when set' );
$equal = 0;
ok(!($greedy eqr "abc"), 'Greedy is not abc when unset' );
}
# unimport
{
no Syntax::Operator::Eqr;
sub eqr { return "normal function" }
is( eqr, "normal function", 'eqr() parses as a normal function call' );
}
ok(!$warnings, 'no warnings');
done_testing;
|