1use Test::More;
2use strict; use warnings FATAL => 'all';
3
4use List::Objects::WithUtils 'array';
5
6my $arr = array(1 .. 4);
7my $left = $arr->rotate;
8is_deeply
9  [ $left->all ],
10  [ 2, 3, 4, 1 ],
11  'rotate default opts ok';
12is_deeply
13  [ $arr->all ],
14  [ 1, 2, 3, 4 ],
15  'original array intact';
16
17is_deeply
18  [ $arr->rotate(left => 1)->all ],
19  [ 2, 3, 4, 1 ],
20  'rotate leftwards ok';
21is_deeply
22  [ $arr->rotate(right => 1)->all ],
23  [ 4, 1, 2, 3 ],
24  'rotate rightwards ok';
25
26$arr = array(1 .. 2);
27$left = $arr->rotate;
28is_deeply [ $left->all ], [ 2, 1 ],
29  'rotated leftwards once';
30$left = $left->rotate;
31is_deeply [ $left->all ], [ 1, 2 ],
32  'rotated full-circle (left)';
33
34my $right = $arr->rotate(right => 1);
35is_deeply [ $right->all ], [ 2, 1 ],
36  'rotated rightwards once';
37$right = $right->rotate;
38is_deeply [ $right->all ], [ 1, 2 ],
39  'rotated full-circle (right)';
40
41ok array->rotate(left => 1)->is_empty,  'empty array rotate left ok';
42ok array->rotate(right => 1)->is_empty, 'empty array rotate right ok';
43
44eval {; $arr->rotate(left => 1, right => 1) };
45like $@, qr/direction/, 'bad opts die ok';
46
47done_testing
48