1use strict;
2use Test::More tests => 91;
3
4use Syntax::Keyword::Junction 'all';
5
6ok( all( 3, 3.0 ) == 3, '==' );
7ok( all( 3, 3 ) == 3,   '==' );
8ok( all( 3, 3.0, 3 ) == 3, '==' );
9ok( not( all( 2, 3.0 ) == 3 ), '== negated' );
10ok( not( all( 2, 2.0, 3 ) == 3 ),   '== negated' );
11ok( not( all( 2, 3,   3.0 ) == 3 ), '== negated' );
12
13ok( all( 3, 4, 5 ) != 2,   '!=' );
14ok( all( 3, 3, 5 ) != 2,   '!=' );
15ok( all( 3, 3, 3.0 ) != 2, '!=' );
16ok( not( all( 3, 4, 5 ) != 3 ), '!= negated' );
17ok( not( all( 3, 3.0 ) != 3 ), '!= negated' );
18
19ok( all( 3, 4, 5 ) >= 2, '>=' );
20ok( all( 3, 4, 5 ) >= 3, '>=' );
21ok( not( all( 3, 4, 5 ) >= 4 ), '>= negated' );
22ok( not( all( 3, 4, 5 ) >= 5 ), '>= negated' );
23ok( not( all( 3, 5, 6 ) >= 4 ), '>= negated' );
24ok( 6 >= all( 3, 4, 5 ), '>= switched' );
25ok( 5 >= all( 3, 4, 5 ), '>= switched' );
26ok( not( 2 >= all( 3, 4, 5 ) ), '>= negated switched' );
27ok( not( 3 >= all( 3, 4, 5 ) ), '>= negated switched' );
28ok( not( 4 >= all( 3, 4, 5 ) ), '>= negated switched' );
29ok( not( 4 >= all( 3, 5, 6 ) ), '>= negated switched' );
30
31ok( all( 3, 4, 5 ) > 2, '>' );
32ok( not( all( 3, 4, 5 ) > 4 ), '> negated' );
33ok( not( all( 3, 4, 5 ) > 5 ), '> negated' );
34ok( not( all( 3, 4, 5 ) > 6 ), '> negated' );
35ok( 6 > all( 3, 4, 5 ), '> switched' );
36ok( not( 5 > all( 3, 4, 5 ) ), '> negated switched' );
37ok( not( 4 > all( 3, 4, 5 ) ), '> negated switched' );
38ok( not( 3 > all( 3, 4, 5 ) ), '> negated switched' );
39ok( not( 2 > all( 3, 4, 5 ) ), '> negated switched' );
40
41ok( all( 3, 4, 5 ) <= 5, '<=' );
42ok( all( 3, 4, 5 ) <= 6, '<=' );
43ok( not( all( 3, 4, 5 ) <= 2 ), '<= negated' );
44ok( 2 <= all( 3, 4, 5 ), '<= switched' );
45ok( 3 <= all( 3, 4, 5 ), '<= switched' );
46ok( not( 6 <= all( 3, 4, 5 ) ), '<= negated switched' );
47
48ok( all( 3, 4, 5 ) < 6, '<' );
49ok( not( all( 3, 4, 5 ) < 5 ), '< negated' );
50ok( not( all( 3, 4, 5 ) < 2 ), '< negated' );
51ok( 2 < all( 3, 4, 5 ), '< switched' );
52ok( not( 5 < all( 3, 4, 5 ) ), '< negated switched' );
53ok( not( 6 < all( 3, 4, 5 ) ), '< negated switched' );
54
55ok( all( 'g', 'g' ) eq 'g', 'eq' );
56ok( not( all( 'g', 'h' ) eq 'g' ), 'eq negated' );
57
58ok( all( 'h', 'i' ) ne 'g', 'ne' );
59ok( not( all( 'h', 'i' ) ne 'i' ), 'ne negated' );
60
61ok( all( 'g', 'h' ) ge 'g', 'ge' );
62ok( all( 'g', 'h' ) ge 'f', 'ge' );
63ok( not( all( 'g', 'h' ) ge 'i' ), 'ge negated' );
64ok( 'i' ge all( 'g', 'h' ), 'ge switched' );
65ok( 'h' ge all( 'g', 'h' ), 'ge switched' );
66ok( not( 'f' ge all( 'g', 'h' ) ), 'ge negated switched' );
67
68ok( all( 'g', 'h' ) gt 'f', 'gt' );
69ok( not( all( 'a', 'h' ) gt 'e' ), 'gt negated' );
70ok( not( all( 'g', 'h' ) gt 'g' ), 'gt negated' );
71ok( 'i' gt all( 'g', 'h' ), 'gt switched' );
72ok( not( 'f' gt all( 'g', 'h' ) ), 'gt negated switched' );
73ok( not( 'g' gt all( 'g', 'h' ) ), 'gt negated switched' );
74
75ok( all( 'g', 'h' ) le 'i', 'le' );
76ok( all( 'g', 'h' ) le 'h', 'le' );
77ok( not( all( 'g', 'h' ) le 'f' ), 'le negated' );
78ok( 'f' le all( 'g', 'h' ), 'le switched' );
79ok( 'g' le all( 'g', 'h' ), 'le switched' );
80ok( not( 'i' le all( 'g', 'h' ) ), 'le negated switched' );
81
82ok( all( 'g', 'h' ) lt 'i', 'lt' );
83ok( not( all( 'b', 'h' ) lt 'a' ), 'lt negated' );
84ok( not( all( 'g', 'h' ) lt 'f' ), 'lt negated' );
85ok( 'f' lt all( 'g', 'h' ), 'lt switched' );
86ok( not( 'h' lt all( 'g', 'h' ) ), 'lt negated switched' );
87ok( not( 'i' lt all( 'g', 'h' ) ), 'lt negated switched' );
88
89ok( all( 3, 40 ) == qr/\d+/, '== regex' );
90ok( qr/^[ab]$/ == all( 'a', 'b' ), '== regex' );
91ok( not( all( 2,                 3,   'c' ) == qr/\d+/ ), '== regex negated' );
92ok( not( qr/\d/ == all( 2,       3,   'c' ) ),            '== regex negated' );
93ok( not( qr/[a-z]+/ == all( 'a', 'b', 3 ) ),              '== regex negated' );
94
95ok( all( 3,   4,   5 ) != qr/[a-z]/, '!= regex' );
96ok( all( 'a', 'b', 'c' ) != qr/\d/,  '!= regex' );
97ok( not( all( 3, 4, 5 ) != qr/4/ ),       '!= regex negated' );
98ok( not( all( 3, 4, 'a' ) != qr/[a-z]/ ), '!= regex negated' );
99
100ok( all( 3, 3.0 ), 'bool' );
101ok( all( 3, 3 ),   'bool' );
102ok( all( 3, 3.0, 3 ), 'bool' );
103ok( !all( 2,  0 ),   '! bool' );
104ok( !all( '', 'a' ), '! bool' );
105ok( !all( 'a', undef, 'c' ), '! bool' );
106
107like( all( 1, 2 ), qr/^Syntax::Keyword::Junction::All=/, 'stringified to ref' );
108
109my @data = qw(3 4 5 6 7);
110my $junction = all(@data);
111can_ok $junction, 'values';
112my @values = $junction->values;
113is_deeply \@values, \@data, 'values() in list context';
114my $values = $junction->values;
115is_deeply $values, \@data, 'values() in scalar context';
116
117my $plus1 = $junction->map( sub { $_ + 1 } );
118is_deeply( [ $plus1->values ], [ qw( 4 5 6 7 8 ) ], "map method");
119