/
array-array.t
130 lines (122 loc) 路 6.13 KB
/
array-array.t
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
101
102
103
104
105
106
107
108
109
110
111
112
113
114
115
116
117
118
119
120
121
122
123
124
125
126
127
128
129
130
use v6;
use Test;
plan 68;
#L<S03/Smart matching/arrays are comparable>
{
ok((("blah", "blah") ~~ ("blah", "blah")), "qw/blah blah/ .eq");
ok(!((1, 2) ~~ (1, 1)), "1 2 !~~ 1 1");
ok(!((1, 2, 3) ~~ (1, 2)), "1 2 3 !~~ 1 2");
ok(!((1, 2) ~~ (1, 2, 3)), "1 2 !~~ 1 2 3");
ok(!([] ~~ [1]), "list smartmatch boundary conditions");
ok(!([1] ~~ []), "list smartmatch boundary conditions");
ok(([] ~~ []), "list smartmatch boundary conditions");
ok(([1] ~~ [1]), "list smartmatch boundary conditions");
#?niecza todo
ok((1,2,3,4) ~~ (1,**), 'list smartmatch dwims ** at end');
#?niecza todo
ok((1,2,3,4) ~~ (1,**,**), 'list smartmatch dwims ** at end (many *s)');
#?niecza todo
ok((1,2,3,4) ~~ (**,4), 'list smartmatch dwims ** at start');
#?niecza todo
ok((1,2,3,4) ~~ (**,**,4), 'list smartmatch dwims ** at start (many **s)');
#?niecza todo
ok((1,2,3,4) ~~ (1,**,3,4), 'list smartmatch dwims ** 1 elem');
#?niecza todo
ok((1,2,3,4) ~~ (1,**,**,3,4), 'list smartmatch dwims ** 1 elem (many **s)');
#?niecza todo
ok((1,2,3,4) ~~ (1,**,4), 'list smartmatch dwims ** many elems');
#?niecza todo
ok((1,2,3,4) ~~ (1,**,**,4), 'list smartmatch dwims ** many elems (many **s)');
#?niecza todo
ok((1,2,3,4) ~~ (**,3,**), 'list smartmatch dwims ** at start and end');
#?niecza todo
ok((1,2,3,4) ~~ (**,**,3,**,**), 'list smartmatch dwims ** at start and end (many **s)');
#?niecza todo
ok((1,2,3,4) ~~ (**,1,2,3,4), 'list smartmatch dwims ** can match nothing at start');
#?niecza todo
ok((1,2,3,4) ~~ (**,**,1,2,3,4), 'list smartmatch dwims ** can match nothing at start (many **s)');
#?niecza todo
ok((1,2,3,4) ~~ (1,2,**,3,4), 'list smartmatch dwims ** can match nothing in middle');
#?niecza todo
ok((1,2,3,4) ~~ (1,2,**,**,3,4), 'list smartmatch dwims ** can match nothing in middle (many **s)');
#?niecza todo
ok((1,2,3,4) ~~ (1,2,3,4,**), 'list smartmatch dwims ** can match nothing at end');
#?niecza todo
ok((1,2,3,4) ~~ (1,2,3,4,**,**), 'list smartmatch dwims ** can match nothing at end (many **s)');
ok(!((1,2,3,4) ~~ (1,**,3)), '** dwimming does not cause craziness');
ok(!((1,2,3,4) ~~ (**,5)), '** dwimming does not cause craziness');
ok(!((1,2,3,4) ~~ (1,3,**)), '** dwimming does not cause craziness');
# now try it with arrays as well
my @a = 1, 2, 3;
my @b = 1, 2, 4;
my @m = (**, 2, **); # m as "magic" ;-)
ok (@a ~~ @a), 'Basic smartmatching on arrays (positive)';
ok (@a !~~ @b), 'Basic smartmatching on arrays (negative)';
ok (@b !~~ @a), 'Basic smartmatching on arrays (negative)';
#?niecza todo
ok (@a ~~ @m), 'Whatever dwimminess in arrays';
ok (@a ~~ (1, 2, 3)), 'smartmatch Array ~~ List';
ok ((1, 2, 3) ~~ @a), 'smartmatch List ~~ Array';
#?niecza todo
ok ((1, 2, 3) ~~ @m), 'smartmatch List ~~ Array with dwim';
## the next test is bogus, since ~~ has a tighter precendence than comma
## with rakudo 2016.08.1-194-g0cf7128 there is no coercion to list
## when using parentheses: 1 ~~ (**,1,**) returns False
## cmp. http://irclog.perlgeek.de/perl6/2016-09-15#i_13217141
## TODO modify test to whatever the answer to "is the LHS coerced" is
ok (1 ~~ **,1,**), 'smartmatch with Array RHS co-erces LHS to list';
ok (1..10 ~~ (**,5,**)), 'smartmatch with List RHS co-erces LHS to list';
# now test that each element does smartmatching
ok(((<blah blah>) ~~ (/^bl/, /ah$/)), "smartmatch regex");
ok(((<blah blah>) ~~ (Str, Cool)), "smartmatch types");
ok((<1 2.3 4.5e6 7+8i> ~~ (Int, Rat, Num, Complex)), "smartmatch numeric types");
ok((<1 2.3 4.5e6 7+8i> ~~ (Str, Str, Str, Str)), "smartmatch allomorphic types");
ok(!((1, 2) ~~ (*, 1)), "1 2 !~~ * 1");
ok(!((1, 2, 3) ~~ (*, *)), "1 2 3 !~~ * *");
ok(!((1, 2) ~~ (*, *, 3)), "1 2 !~~ * * 3");
ok(!([] ~~ [*]), "list smartmatch boundary conditions");
ok(!([1] ~~ [slip]), "list smartmatch boundary conditions");
ok(([] ~~ [slip]), "list smartmatch boundary conditions");
ok(([1] ~~ [*]), "list smartmatch boundary conditions");
#?niecza todo
ok((1,2,3,4) ~~ (*,**), 'list smartmatch dwims ** at end');
#?niecza todo
ok((1,2,3,4) ~~ (*,**,**), 'list smartmatch dwims ** at end (many *s)');
#?niecza todo
ok((1,2,3,4) ~~ (**,*), 'list smartmatch dwims ** at start');
#?niecza todo
ok((1,2,3,4) ~~ (**,**,*), 'list smartmatch dwims ** at start (many **s)');
#?niecza todo
ok((1,2,3,4) ~~ (1,**,3,*), 'list smartmatch dwims ** 1 elem');
#?niecza todo
ok((1,2,3,4) ~~ (1,**,**,3,{ $_ > 3}), 'list smartmatch dwims ** 1 elem (many **s)');
#?niecza todo
ok((1,2,3,4) ~~ (*,**,4), 'list smartmatch dwims ** many elems');
#?niecza todo
ok((1,2,3,4) ~~ (Numeric,**,**,Cool), 'list smartmatch dwims ** many elems (many **s)');
#?niecza todo
ok((1,2,3,4) ~~ (**,* == 3,**), 'list smartmatch dwims ** at start and end');
#?niecza todo
ok((1,2,3,4) ~~ (**,**,/3/,**,**), 'list smartmatch dwims ** at start and end (many **s)');
#?niecza todo
ok((1,2,3,4) ~~ (**,1,|((* > 1) xx 3)), 'list smartmatch dwims ** can match nothing at start');
#?niecza todo
ok((1,2,3,4) ~~ (**,**,*,2,3,4), 'list smartmatch dwims ** can match nothing at start (many **s)');
#?niecza todo
ok((1,2,3,4) ~~ (1,2,**,3,4), 'list smartmatch dwims ** can match nothing in middle');
#?niecza todo
ok((1,2,3,4) ~~ (1,*,**,**,*,4), 'list smartmatch dwims ** can match nothing in middle (many **s)');
#?niecza todo
ok((1,2,3,4) ~~ (1,2,3,*,**), 'list smartmatch dwims ** can match nothing at end');
#?niecza todo
ok((1,2,3,4) ~~ (*,*,*,4,**,**), 'list smartmatch dwims ** can match nothing at end (many **s)');
ok(!((1,2,3,4) ~~ (*,**,3)), '** dwimming does not cause craziness');
ok(!((1,2,3,4) ~~ (**,* == 5)), '** dwimming does not cause craziness');
ok(!((1,2,3,4) ~~ (1,/3/,**)), '** dwimming does not cause craziness');
}
# RT#123144
{
eval-lives-ok '["a","b","c"] ~~ [**, "b", "c"]', "Str and Whatever (1)";
eval-lives-ok '[1,2,3] ~~ [**, "b", "c"]', "Str and Whatever (2)";
}
# vim: ft=perl6