6 use Test::More tests => 55;
9 use_ok('Moose::Autobox');
17 ok(!$s->defined, '... got a undefined value');
20 ok($s->defined, '... got a defined value');
25 ok($f1->defined, '... created function');
27 my $f2 = eval { $f1->curry(1, 2, 3) };
28 ok($f2->defined, '... created curried function');
30 my $f3 = eval { $f1->rcurry(1, 2, 3) };
31 ok($f3->defined, '... created right-curried function');
36 '... got the right return value from the curried function');
41 '... got the right return value from the r-curried function');
43 ok((sub { 1 })->disjoin(sub { 0 })->(), '... disjoins properly');
44 ok((sub { 0 })->disjoin(sub { 1 })->(), '... disjoins properly');
46 ok(!(sub { 1 })->conjoin(sub { 0 })->(), '... conjoins properly');
47 ok(!(sub { 0 })->conjoin(sub { 1 })->(), '... conjoins properly');
49 my $compose = (sub { @_, 1 })->compose(sub { @_, 2 });
54 '... got the right return value for compose');
58 my $a = [ 4, 2, 6, 78, 101, 2, 3 ];
60 is($a->length, 7, '... got the right length');
61 ok($a->defined, '... got the right defined value');
64 $a->map(sub { $_ + 2 }),
65 [ map { $_ + 2 } (4, 2, 6, 78, 101, 2, 3) ],
66 '... got the right return value for map');
68 is_deeply($a, [ 4, 2, 6, 78, 101, 2, 3 ], '... original value is unchanged');
72 [ 3, 2, 101, 78, 6, 2, 4 ],
73 '... got the right return value for reverse');
75 is_deeply($a, [ 4, 2, 6, 78, 101, 2, 3 ], '... original value is unchanged');
78 $a->grep(sub { $_ < 50 }),
79 [ grep { $_ < 50 } (4, 2, 6, 78, 101, 2, 3) ],
80 '... got the right return value grep');
82 is_deeply($a, [ 4, 2, 6, 78, 101, 2, 3 ], '... original value is unchanged');
84 is($a->join(', '), '4, 2, 6, 78, 101, 2, 3', '... got the right joined string');
85 is($a->join, '4267810123', '... got the right joined string');
86 ok($a->exists(0), '... exists works');
87 ok(!$a->exists(10), '... exists works');
89 is($a->pop(), 3, '... got the right pop-ed value');
90 is_deeply($a, [ 4, 2, 6, 78, 101, 2 ], '... original value is now changed');
92 is($a->shift(), 4, '... got the right unshift-ed value');
93 is_deeply($a, [ 2, 6, 78, 101, 2 ], '... original value is now changed');
97 $a->slice([ 1, 2, 4 ]),
99 '... got the right sliced value');
103 [ 10, 2, 6, 78, 101, 2 ],
104 '... got the correct unshifted value');
107 $a->unshift(15, 20, 30),
108 [ 15, 20, 30, 10, 2, 6, 78, 101, 2 ],
109 '... got the correct unshifted value (multiple values)');
113 [ 15, 20, 30, 10, 2, 6, 78, 101, 2, 10 ],
114 '... got the correct pushed value');
117 $a->push(15, 20, 30),
118 [ 15, 20, 30, 10, 2, 6, 78, 101, 2, 10, 15, 20, 30 ],
119 '... got the correct pushed value (multiple values)');
122 $a->sort(sub { $_[0] <=> $_[1] }),
123 [ 2, 2, 6, 10, 10, 15, 15, 20, 20, 30, 30, 78, 101 ],
124 '... got the correct sorted value');
128 [ 15, 20, 30, 10, 2, 6, 78, 101, 2, 10, 15, 20, 30 ],
129 '... the original values are unchanged');
132 []->push(10, 20, 30)->map(sub { ($_, $_ + 5) })->reverse,
133 [ 35, 30, 25, 20, 15, 10 ],
134 '... got the correct chained value');
138 [ 0, 1, 2, 3, 4, 5, 6, 7, 8, 9, 10, 11, 12 ],
143 [ 15, 20, 30, 10, 2, 6, 78, 101, 2, 10, 15, 20, 30 ],
148 [ [0, 15], [1, 20], [2, 30], [3, 10], [4, 2], [5, 6], [6, 78],
149 [7, 101], [8, 2], [9, 10], [10, 15], [11, 20], [12, 30] ],
152 is([1, 2, 3, 4, 5]->reduce(sub { $_[0] + $_[1] }), 15, '... got the right reduction');
155 [1, 2, 3, 4, 5]->zip([ 5, 4, 3, 2, 1 ]),
156 [ [1, 5], [2, 4], [3, 3], [4, 2], [5, 1] ],
157 '... got the right zip');
160 [1, 2, 3, 4, 5]->zip([ 6, 5, 4, 3, 2, 1 ]),
161 [ [1, 6], [2, 5], [3, 4], [4, 3], [5, 2], [undef, 1] ],
162 '... got the right zip');
164 is($a->delete(2), 30, '... got the value deleted');
167 [ 15, 20, undef, 10, 2, 6, 78, 101, 2, 10, 15, 20, 30 ],
168 '... the value is correctly deleted');
174 [ 15, 20, 30, 10, 2, 6, 78, 101, 2, 10, 15, 20, 30 ],
175 '... the value is correctly put');
179 my $h = { one => 1, two => 2, three => 3 };
181 ok($h->defined, '... got the right defined value');
185 [ qw/one three two/ ],
194 $h->kv->sort(sub { $_[0]->[1] <=> $_[1]->[1] }),
195 [ ['one', 1], ['two', 2], ['three', 3] ],
198 ok($h->exists('two'), '... exists works');
199 ok(!$h->exists('five'), '... !exists works');
201 $h->put('four' => 4);
204 { one => 1, two => 2, three => 3, four => 4 },
205 '... got the value added correctly');
207 is($h->at('four'), 4, '... got the value at "four"');
212 { one => 1, two => 2, three => 3 },
213 '... got the value deleted correctly');