Skip to content

Commit dad24db

Browse files
committed
Part 1 of .exists eradication from tests
1 parent 8e56a29 commit dad24db

File tree

8 files changed

+30
-30
lines changed

8 files changed

+30
-30
lines changed

S01-perl-5-integration/array.t

Lines changed: 4 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -59,8 +59,8 @@ my $p5array = $p5ar(VAR @array);
5959
my $retarray = $p5array.array;
6060

6161
is($p5array.my_elems, @array.elems, 'elems');
62-
is($p5array.my_exists(1), @array.exists(1), 'exists');
63-
is($p5array.my_exists(10), @array.exists(10), 'nonexists fail');
62+
is($p5array.my_exists(1), @array[1]:exists, 'exists');
63+
is($p5array.my_exists(10), @array[10]:exists, 'nonexists fail');
6464
is($p5array.fetch(3)+0, @array[3], 'fetch');
6565

6666
my $match = 0;
@@ -70,8 +70,8 @@ lives_ok {
7070
ok $match, 'retro fetch';
7171

7272
is(eval(q{$retarray.elems}), @array.elems, 'retro elems');
73-
is($retarray.exists(1), @array.exists(1), 'retro exists');
74-
is($retarray.exists(10), @array.exists(10), 'retro nonexists' );
73+
is($retarray[1]:exists, @array[1]:exists, 'retro exists');
74+
is($retarray[10]:exists, @array[10]:exists, 'retro nonexists' );
7575

7676
ok(($p5array.push(9)), 'can push');
7777

S01-perl-5-integration/hash.t

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -69,8 +69,8 @@ ok($p5hash.store(9, 'e'), 'can store');
6969
is(%hash{9}, 'e', 'store result');
7070

7171
is($p5hash.fetch(5), 'a', 'fetch result');
72-
is($p5hash.my_exists(5), %hash.exists(5), 'exists');
72+
is($p5hash.my_exists(5), %hash<5>:exists, 'exists');
7373
#?pugs todo 'bug'
74-
is($p5hash.my_exists(12), %hash.exists(12), 'nonexists fail');
74+
is($p5hash.my_exists(12), %hash<12>:exists, 'nonexists fail');
7575

7676
# vim: ft=perl6

S02-magicals/UsedEnv.pm6

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -1,7 +1,7 @@
11
module UsedEnv {
22
use Test;
33
plan 1;
4-
ok %*ENV.exists('PATH'), "env exists in use (RT #78258)";
4+
ok %*ENV<PATH>:exists, "env exists in use (RT #78258)";
55
done;
66
}
77

S02-magicals/env.t

Lines changed: 3 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -55,9 +55,9 @@ my $expected = 'Hello from subprocess';
5555
is %*ENV<PUGS_ROCKS>, $expected,'%*ENV is rw';
5656

5757
%*ENV.delete('PUGS_ROCKS');
58-
ok(!%*ENV.exists('PUGS_ROCKS'), 'We can remove keys from %*ENV');
58+
ok(!%*ENV<PUGS_ROCKS>:exists, 'We can remove keys from %*ENV');
5959

60-
ok !%*ENV.exists("does_not_exist"), "exists() returns false on a not defined env var";
60+
ok !%*ENV<does_not_exist>:exists, "exists() returns false on a not defined env var";
6161

6262
# %ENV must not be imported by default
6363
#?pugs todo 'bug'
@@ -83,7 +83,7 @@ eval_dies_ok("%ENV", '%ENV not visible by default');
8383
# RT #78256
8484
{
8585
nok %*ENV<NOSUCHENVVAR>.defined, 'non-existing vars are undefined';
86-
nok %*ENV.exists('NOSUCHENVVAR'), 'non-existing vars do not exist';
86+
nok %*ENV<NOSUCHENVVAR>:exists, 'non-existing vars do not exist';
8787

8888
}
8989

S02-types/array_extending.t

Lines changed: 8 additions & 8 deletions
Original file line numberDiff line numberDiff line change
@@ -30,10 +30,10 @@ plan 21;
3030
# @array should be ("a", "b", "c", "d", Mu, Mu, ..., 42).
3131
is +@array, 21,
3232
"creating an array element should automatically extend the array (1)";
33-
# And, of course, @array.exists(20) has to be true -- we've just assigned
33+
# And, of course, @array[20]:exists has to be true -- we've just assigned
3434
# @array[20].
3535
#?niecza skip 'Unable to resolve method exists in class Array'
36-
ok @array.exists(20),
36+
ok @array[20]:exists,
3737
"creating an array element should automatically extend the array (2)";
3838
}
3939

@@ -62,23 +62,23 @@ plan 21;
6262
#?niecza skip 'Unable to resolve method exists in class Array'
6363
{
6464
my @array = <a b c d>;
65-
my $exists = @array.exists(100);
65+
my $exists = @array[100]:exists;
6666

6767
ok !$exists,
68-
'@array.exists($index_out_of_bounds) should be false';
68+
'@array[$index_out_of_bounds]:exists should be false';
6969
is +@array, 4,
70-
'@array.exists($index_out_of_bounds) should not have altered @array';
70+
'@array[$index_out_of_bounds]:exists should not have altered @array';
7171
}
7272

7373
#?niecza skip 'Unable to resolve method exists in class Array'
7474
{
7575
my @array = <a b c d>;
76-
my $exists = @array.exists(-5);
76+
my $exists = @array[-5]:exists;
7777

7878
ok !$exists,
79-
'@array.exists($negative_index_out_of_bounds) should be false';
79+
'@array[$negative_index_out_of_bounds]:exists should be false';
8080
is +@array, 4,
81-
'@array.exists($negative_index_out_of_bounds) should not have altered @array';
81+
'@array[$negative_index_out_of_bounds]:exists should not have altered @array';
8282
}
8383

8484
{

S02-types/bag.t

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -19,8 +19,8 @@ sub showkv($x) {
1919
isa_ok $b<a>, Int, 'Single-key subscript yields an Int';
2020
is $b<santa>, 0, 'Single-key subscript (nonexistent element)';
2121
isa_ok $b<santa>, Int, 'Single-key subscript yields an Int (nonexistent element)';
22-
ok $b.exists('a'), '.exists with existing element';
23-
nok $b.exists('santa'), '.exists with nonexistent element';
22+
ok $b<a>:exists, 'exists with existing element';
23+
nok $b<santa>:exists, 'exists with nonexistent element';
2424

2525
is $b.values.elems, 3, "Values returns the correct number of values";
2626
is ([+] $b.values), 8, "Values returns the correct sum";

S02-types/keybag.t

Lines changed: 9 additions & 9 deletions
Original file line numberDiff line numberDiff line change
@@ -24,8 +24,8 @@ sub showkv($x) {
2424
isa_ok $b<a>, Int, 'Single-key subscript yields an Int';
2525
is $b<santa>, 0, 'Single-key subscript (nonexistent element)';
2626
isa_ok $b<santa>, Int, 'Single-key subscript yields an Int (nonexistent element)';
27-
ok $b.exists('a'), '.exists with existing element';
28-
nok $b.exists('santa'), '.exists with nonexistent element';
27+
ok $b<a>:exists, 'exists with existing element';
28+
nok $b<santa>:exists, 'exists with nonexistent element';
2929

3030
is $b.values.elems, 3, "Values returns the correct number of values";
3131
is ([+] $b.values), 8, "Values returns the correct sum";
@@ -51,9 +51,9 @@ sub showkv($x) {
5151
lives_ok { $b<brady> = 12 }, "Can assign to a new element";
5252
is $b<brady>, 12, "... and assignment takes effect";
5353
lives_ok { $b<spiderman> = 0 }, "Can assign zero to a nonexistent element";
54-
nok $b.exists("spiderman"), "... and that didn't create the element";
54+
nok $b<spiderman>:exists, "... and that didn't create the element";
5555
lives_ok { $b<brady> = 0 }, "Can assign zero to a existing element";
56-
nok $b.exists("brady"), "... and it goes away";
56+
nok $b<brady>:exists, "... and it goes away";
5757

5858
lives_ok { $b<a>++ }, "Can ++ an existing element";
5959
is $b<a>, 43, "... and the increment happens";
@@ -62,10 +62,10 @@ sub showkv($x) {
6262
lives_ok { $b<a>-- }, "Can -- an existing element";
6363
is $b<a>, 42, "... and the decrement happens";
6464
lives_ok { $b<carter>-- }, "Can -- an element with value 1";
65-
nok $b.exists("carter"), "... and it goes away";
65+
nok $b<carter>:exists, "... and it goes away";
6666
#?niecza todo
6767
dies_ok { $b<farve>-- }, "Cannot -- an element that doesn't exist";
68-
nok $b.exists("farve"), "... and everything is still okay";
68+
nok $b<farve>:exists, "... and everything is still okay";
6969
}
7070

7171
{
@@ -314,7 +314,7 @@ sub showkv($x) {
314314
{
315315
my %h is KeyBag = a => 1, b => 0, c => 2;
316316
#?rakudo todo 'todo'
317-
nok %h.exists( 'b' ), '"b", initialized to zero, does not exist';
317+
nok %h<b>:exists, '"b", initialized to zero, does not exist';
318318
#?rakudo todo 'todo'
319319
is +%h.keys, 2, 'Inititalization worked';
320320
is %h.elems, 3, '.elems works';
@@ -331,7 +331,7 @@ sub showkv($x) {
331331

332332
lives_ok { %h<c> = 0 }, 'can set an item to 0';
333333
#?rakudo todo 'todo'
334-
nok %h.exists( 'c' ), '"c", set to zero, does not exist';
334+
nok %h<c>:exists, '"c", set to zero, does not exist';
335335
#?rakudo todo 'todo'
336336
is %h.elems, 1, 'one item left';
337337
#?rakudo todo 'todo'
@@ -355,7 +355,7 @@ sub showkv($x) {
355355
#?rakudo todo 'todo'
356356
is %h.keys, ('c'), 'decrement (--) removes items';
357357
#?rakudo todo 'todo'
358-
nok %h.exists( 'a' ), 'item is gone according to .exists too';
358+
nok %h<a>:exists, 'item is gone according to exists too';
359359
is %h<a>, 0, 'removed item is zero';
360360

361361
lives_ok { %h<a>-- }, 'remove a missing item lives';

packages/Test/Util.pm

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -36,7 +36,7 @@ multi sub is_run( Str $code, Str $input, %expected, Str $name, *%o ) {
3636
# We check each of the attributes and pass the test only if all are good.
3737
for <status out err> -> $attr {
3838
# Attributes not specified are not tested.
39-
next if ! %expected.exists( $attr );
39+
next if !(%expected{$attr}:exists);
4040

4141
my $attr_good = %got{$attr} ~~ %expected{$attr};
4242

0 commit comments

Comments
 (0)