Skip to content

Commit

Permalink
Browse files Browse the repository at this point in the history
Part 1 of .exists eradication from tests
  • Loading branch information
lizmat committed Sep 28, 2013
1 parent 8e56a29 commit dad24db
Show file tree
Hide file tree
Showing 8 changed files with 30 additions and 30 deletions.
8 changes: 4 additions & 4 deletions S01-perl-5-integration/array.t
Expand Up @@ -59,8 +59,8 @@ my $p5array = $p5ar(VAR @array);
my $retarray = $p5array.array;

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

my $match = 0;
Expand All @@ -70,8 +70,8 @@ lives_ok {
ok $match, 'retro fetch';

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

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

Expand Down
4 changes: 2 additions & 2 deletions S01-perl-5-integration/hash.t
Expand Up @@ -69,8 +69,8 @@ ok($p5hash.store(9, 'e'), 'can store');
is(%hash{9}, 'e', 'store result');

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

# vim: ft=perl6
2 changes: 1 addition & 1 deletion S02-magicals/UsedEnv.pm6
@@ -1,7 +1,7 @@
module UsedEnv {
use Test;
plan 1;
ok %*ENV.exists('PATH'), "env exists in use (RT #78258)";
ok %*ENV<PATH>:exists, "env exists in use (RT #78258)";
done;
}

6 changes: 3 additions & 3 deletions S02-magicals/env.t
Expand Up @@ -55,9 +55,9 @@ my $expected = 'Hello from subprocess';
is %*ENV<PUGS_ROCKS>, $expected,'%*ENV is rw';

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

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

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

}

Expand Down
16 changes: 8 additions & 8 deletions S02-types/array_extending.t
Expand Up @@ -30,10 +30,10 @@ plan 21;
# @array should be ("a", "b", "c", "d", Mu, Mu, ..., 42).
is +@array, 21,
"creating an array element should automatically extend the array (1)";
# And, of course, @array.exists(20) has to be true -- we've just assigned
# And, of course, @array[20]:exists has to be true -- we've just assigned
# @array[20].
#?niecza skip 'Unable to resolve method exists in class Array'
ok @array.exists(20),
ok @array[20]:exists,
"creating an array element should automatically extend the array (2)";
}

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

ok !$exists,
'@array.exists($index_out_of_bounds) should be false';
'@array[$index_out_of_bounds]:exists should be false';
is +@array, 4,
'@array.exists($index_out_of_bounds) should not have altered @array';
'@array[$index_out_of_bounds]:exists should not have altered @array';
}

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

ok !$exists,
'@array.exists($negative_index_out_of_bounds) should be false';
'@array[$negative_index_out_of_bounds]:exists should be false';
is +@array, 4,
'@array.exists($negative_index_out_of_bounds) should not have altered @array';
'@array[$negative_index_out_of_bounds]:exists should not have altered @array';
}

{
Expand Down
4 changes: 2 additions & 2 deletions S02-types/bag.t
Expand Up @@ -19,8 +19,8 @@ sub showkv($x) {
isa_ok $b<a>, Int, 'Single-key subscript yields an Int';
is $b<santa>, 0, 'Single-key subscript (nonexistent element)';
isa_ok $b<santa>, Int, 'Single-key subscript yields an Int (nonexistent element)';
ok $b.exists('a'), '.exists with existing element';
nok $b.exists('santa'), '.exists with nonexistent element';
ok $b<a>:exists, 'exists with existing element';
nok $b<santa>:exists, 'exists with nonexistent element';

is $b.values.elems, 3, "Values returns the correct number of values";
is ([+] $b.values), 8, "Values returns the correct sum";
Expand Down
18 changes: 9 additions & 9 deletions S02-types/keybag.t
Expand Up @@ -24,8 +24,8 @@ sub showkv($x) {
isa_ok $b<a>, Int, 'Single-key subscript yields an Int';
is $b<santa>, 0, 'Single-key subscript (nonexistent element)';
isa_ok $b<santa>, Int, 'Single-key subscript yields an Int (nonexistent element)';
ok $b.exists('a'), '.exists with existing element';
nok $b.exists('santa'), '.exists with nonexistent element';
ok $b<a>:exists, 'exists with existing element';
nok $b<santa>:exists, 'exists with nonexistent element';

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

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

{
Expand Down Expand Up @@ -314,7 +314,7 @@ sub showkv($x) {
{
my %h is KeyBag = a => 1, b => 0, c => 2;
#?rakudo todo 'todo'
nok %h.exists( 'b' ), '"b", initialized to zero, does not exist';
nok %h<b>:exists, '"b", initialized to zero, does not exist';
#?rakudo todo 'todo'
is +%h.keys, 2, 'Inititalization worked';
is %h.elems, 3, '.elems works';
Expand All @@ -331,7 +331,7 @@ sub showkv($x) {

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

lives_ok { %h<a>-- }, 'remove a missing item lives';
Expand Down
2 changes: 1 addition & 1 deletion packages/Test/Util.pm
Expand Up @@ -36,7 +36,7 @@ multi sub is_run( Str $code, Str $input, %expected, Str $name, *%o ) {
# We check each of the attributes and pass the test only if all are good.
for <status out err> -> $attr {
# Attributes not specified are not tested.
next if ! %expected.exists( $attr );
next if !(%expected{$attr}:exists);

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

Expand Down

0 comments on commit dad24db

Please sign in to comment.