File: 01equ-stringy.t

package info (click to toggle)
libsyntax-operator-equ-perl 0.10-1
  • links: PTS, VCS
  • area: main
  • in suites: forky, sid, trixie
  • size: 172 kB
  • sloc: perl: 352; pascal: 34; makefile: 3
file content (47 lines) | stat: -rw-r--r-- 981 bytes parent folder | download
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
#!/usr/bin/perl

use v5.14;
use warnings;

use Test2::V0;

use Syntax::Operator::Equ;
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" equ "abc", 'identical strings');
ok(!("abc" equ "def"), 'different strings');
ok(  undef equ undef, 'undef is undef');
ok(!("abc" equ undef), 'undef is not a string');
ok(!(""    equ undef), 'undef is not empty string');

# overloaded 'eq' operator
{
   my $equal;
   package Greedy {
      use overload 'eq' => sub { $equal };
   }

   my $greedy = bless [], "Greedy";

   $equal = 1;
   ok(  $greedy equ "abc",  'Greedy is abc when set' );

   $equal = 0;
   ok(!($greedy equ "abc"), 'Greedy is not abc when unset' );
}

# unimport
{
   no Syntax::Operator::Equ;

   sub equ { return "normal function" }

   is( equ, "normal function", 'equ() parses as a normal function call' );
}

ok(!$warnings, 'no warnings');

done_testing;