File: any.t

package info (click to toggle)
libperl6-junction-perl 1.60000-3
  • links: PTS, VCS
  • area: main
  • in suites: bookworm, forky, sid, trixie
  • size: 148 kB
  • sloc: perl: 593; makefile: 2
file content (100 lines) | stat: -rw-r--r-- 3,581 bytes parent folder | download | duplicates (4)
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
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
use strict;
use Test::More tests => 75;

use Perl6::Junction 'any';

ok( any( 2, 3.0 ) == 2, '==' );
ok( any( 2, 3.0 ) == 3, '==' );
ok( not( any( 2, 3.0 ) == 4 ), '== negated' );

ok( any( 3, 4.0 ) != 4, '!=' );
ok( any( 4, 5.0 ) != 4, '!=' );
ok( not( any( 3, 3.0 ) != 3 ), '!= negated' );

ok( any( 3, 4, 5 ) >= 5, '>=' );
ok( any( 3, 4, 5 ) >= 2, '>=' );
ok( not( any( 3, 4, 5 ) >= 6 ), '>= negated' );
ok( 6 >= any( 3, 4, 5 ), '>= switched' );
ok( 3 >= any( 3, 4, 5 ), '>= switched' );
ok( not( 2 >= any( 3, 4, 5 ) ), '>= negated switched' );

ok( any( 3, 4, 5 ) > 2, '>' );
ok( any( 3, 4, 5 ) > 3, '>' );
ok( not( any( 3, 4, 5 ) > 6 ), '> negated' );
ok( 6 > any( 3, 4, 5 ), '> switched' );
ok( 4 > any( 3, 4, 5 ), '> switched' );
ok( not( 2 > any( 3, 4, 5 ) ), '> negated switched' );

ok( any( 3, 4, 5 ) <= 5, '<=' );
ok( any( 3, 4, 5 ) <= 6, '<=' );
ok( not( any( 3, 4, 5 ) <= 2 ), '<= negated' );
ok( 5 <= any( 3, 4, 5 ), '<= switched' );
ok( 2 <= any( 3, 4, 5 ), '<= switched' );
ok( not( 6 <= any( 3, 4, 5 ) ), '<= negated switched' );

ok( any( 3, 4, 5 ) < 6, '<' );
ok( any( 5, 4, 3 ) < 4, '<' );
ok( not( any( 3, 4, 5 ) < 2 ), '< negated' );
ok( 2 < any( 3, 4, 5 ), '< switched' );
ok( 4 < any( 3, 4, 5 ), '< switched' );
ok( not( 6 < any( 3, 4, 5 ) ), '< negated switched' );

ok( any( 'g', 'h' ) eq 'g', 'eq' );
ok( any( 'g', 'g' ) eq 'g', 'eq' );
ok( not( any( 'g', 'h' ) eq 'i' ), 'eq negated' );

ok( any( 'g', 'h' ) ne 'g', 'ne' );
ok( not( any( 'i', 'i' ) ne 'i' ), 'ne negated' );

ok( any( 'g', 'h' ) ge 'f', 'ge' );
ok( any( 'g', 'h' ) ge 'g', 'ge' );
ok( not( any( 'g', 'h' ) ge 'i' ), 'ge negated' );
ok( 'i' ge any( 'g', 'h' ), 'ge switched' );
ok( 'g' ge any( 'g', 'f' ), 'ge switched' );
ok( not( 'f' ge any( 'g', 'h' ) ), 'ge negated switched' );

ok( any( 'g', 'h' ) gt 'f', 'gt' );
ok( any( 'g', 'h' ) gt 'g', 'gt' );
ok( not( any( 'g', 'h' ) gt 'i' ), 'gt negated' );
ok( 'i' gt any( 'h', 'g' ), 'gt switched' );
ok( 'h' gt any( 'h', 'g' ), 'gt switched' );
ok( not( 'g' gt any( 'g', 'h' ) ), 'gt negated switched' );
ok( not( 'f' gt any( 'g', 'h' ) ), 'gt negated switched' );

ok( any( 'g', 'h' ) le 'i', 'le' );
ok( any( 'g', 'f' ) le 'g', 'le' );
ok( not( any( 'g', 'h' ) le 'f' ), 'le negated' );
ok( 'f' le any( 'g', 'h' ), 'le switched' );
ok( 'g' le any( 'h', 'g' ), 'le switched' );
ok( not( 'i' le any( 'g', 'h' ) ), 'le negated switched' );

ok( any( 'g', 'h' ) lt 'i', 'lt' );
ok( any( 'h', 'g' ) lt 'h', 'lt' );
ok( not( any( 'g', 'h' ) lt 'f' ), 'lt negated' );
ok( 'f' lt any( 'g', 'h' ), 'lt switched' );
ok( 'g' lt any( 'h', 'g' ), 'lt switched' );
ok( not( 'i' lt any( 'g', 'h' ) ), 'lt negated switched' );

ok( any( 3, 'b' ) == qr/\d+/, '== regex' );
ok( qr/^[ab]$/ == any( 'a', 4 ), '== regex' );
ok( not( any( 'a',            'b', 'c' ) == qr/\d+/ ), '== regex negated' );
ok( not( qr/\d/ == any( 'a',  'b', 'c' ) ),            '== regex negated' );
ok( not( qr/[a-z]/ == any( 3, 4,   5 ) ),              '== regex negated' );

ok( any( 3, 4, 'a' ) != qr/\d/,      '!= regex' );
ok( any( 3, 4, '5.0' ) != qr/^\d+$/, '!= regex' );
ok( not( any( 3, 4, 5 ) != qr/\d/ ), '!= regex negated' );

ok( any( 2,      0 ),   'bool' );
ok( any( '',     'a' ), 'bool' );
ok( !any( undef, 0 ),   '! bool' );

like( any( 1, 2 ), qr/^Perl6::Junction::Any=/, 'stringified to ref' );

my @data = qw(3 4 5 6 7);
my $junction = any(@data);
can_ok $junction, 'values';
my @values = $junction->values;
is_deeply \@values, \@data, 'values() in list context';
my $values = $junction->values;
is_deeply $values, \@data, 'values() in scalar context';