Skip to content

Commit b0cf420

Browse files
committed
Generic fudge for jvm NPEs
1 parent befe2ef commit b0cf420

File tree

4 files changed

+96
-2
lines changed

4 files changed

+96
-2
lines changed

S02-types/bag.t

Lines changed: 33 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -12,6 +12,7 @@ sub showkv($x) {
1212
{
1313
my $b = bag <a foo a a a a b foo>;
1414
isa-ok $b, Bag, '&bag produces a Bag';
15+
#?rakudo.jvm skip 'NPE'
1516
is showkv($b), 'a:5 b:1 foo:2', '...with the right elements';
1617

1718
is $b.default, 0, "Defaults to 0";
@@ -31,6 +32,7 @@ sub showkv($x) {
3132
lives-ok { $hash = $b.hash },
3233
".hash doesn't die";
3334
isa-ok $hash, Hash, "...and it returned a Hash";
35+
#?rakudo.jvm skip 'NPE'
3436
is showkv($hash), 'a:5 b:1 foo:2', '...with the right elements';
3537

3638
throws-like { $b<a> = 5 },
@@ -70,18 +72,25 @@ sub showkv($x) {
7072

7173
{
7274
isa-ok "a".Bag, Bag, "Str.Bag makes a Bag";
75+
#?rakudo.jvm skip 'NPE'
7376
is showkv("a".Bag), 'a:1', "'a'.Bag is bag a";
7477

7578
isa-ok (a => 100000).Bag, Bag, "Pair.Bag makes a Bag";
79+
#?rakudo.jvm skip 'NPE'
7680
is showkv((a => 100000).Bag), 'a:100000', "(a => 100000).Bag is bag a:100000";
81+
#?rakudo.jvm skip 'NPE'
7782
is showkv((a => 0).Bag), '', "(a => 0).Bag is the empty bag";
7883

7984
isa-ok <a b c>.Bag, Bag, "<a b c>.Bag makes a Bag";
85+
#?rakudo.jvm skip 'NPE'
8086
is showkv(<a b c a>.Bag), 'a:2 b:1 c:1', "<a b c a>.Bag makes the bag a:2 b:1 c:1";
87+
#?rakudo.jvm skip 'NPE'
8188
is showkv(["a", "b", "c", "a"].Bag), 'a:2 b:1 c:1', "[a b c a].Bag makes the bag a:2 b:1 c:1";
89+
#?rakudo.jvm skip 'NPE'
8290
is showkv([a => 3, b => 0, 'c', 'a'].Bag), 'a:4 c:1', "[a => 3, b => 0, 'c', 'a'].Bag makes the bag a:4 c:1";
8391

8492
isa-ok {a => 2, b => 4, c => 0}.Bag, Bag, "{a => 2, b => 4, c => 0}.Bag makes a Bag";
93+
#?rakudo.jvm skip 'NPE'
8594
is showkv({a => 2, b => 4, c => 0}.Bag), 'a:2 b:4', "{a => 2, b => 4, c => 0}.Bag makes the bag a:2 b:4";
8695
}
8796

@@ -114,12 +123,14 @@ sub showkv($x) {
114123
{
115124
my %h := bag <a b o p a p o o>;
116125
ok %h ~~ Bag, 'A hash to which a Bag has been bound becomes a Bag';
126+
#?rakudo.jvm skip 'NPE'
117127
is showkv(%h), 'a:2 b:1 o:3 p:2', '...with the right elements';
118128
}
119129

120130
{
121131
my $b = bag <a b o p a p o o>;
122132
isa-ok $b, Bag, '&Bag.new given an array of strings produces a Bag';
133+
#?rakudo.jvm skip 'NPE'
123134
is showkv($b), 'a:2 b:1 o:3 p:2', '...with the right elements';
124135
}
125136

@@ -155,6 +166,7 @@ sub showkv($x) {
155166
is +$b, 1, "... with one element";
156167
}
157168

169+
#?rakudo.jvm skip 'NPE'
158170
{
159171
my $b = bag set <foo bar foo bar baz foo>;
160172
isa-ok $b, Bag, '&Bag.new given a Set produces a Bag';
@@ -169,12 +181,14 @@ sub showkv($x) {
169181
}
170182

171183
#?niecza skip 'BagHash'
184+
#?rakudo.jvm skip 'NPE'
172185
{
173186
my $b = bag BagHash.new(<foo bar foo bar baz foo>);
174187
isa-ok $b, Bag, '&Bag.new given a BagHash produces a Bag';
175188
is +$b, 1, "... with one element";
176189
}
177190

191+
#?rakudo.jvm skip 'NPE'
178192
{
179193
my $b = bag set <foo bar foo bar baz foo>;
180194
isa-ok $b, Bag, '&bag given a Set produces a Bag';
@@ -186,6 +200,7 @@ sub showkv($x) {
186200
{
187201
my %b := bag <a b c b>;
188202
isa-ok %b, Bag, 'A Bag bound to a %var is a Bag';
203+
#?rakudo.jvm skip 'NPE'
189204
is showkv(%b), 'a:1 b:2 c:1', '...with the right elements';
190205

191206
is %b<b>, 2, 'Single-key subscript (existing element)';
@@ -228,6 +243,7 @@ sub showkv($x) {
228243
lives-ok { $c = EVAL $s },
229244
".perl.EVAL lives";
230245
isa-ok $c, Bag, "... and produces a Bag";
246+
#?rakudo.jvm skip 'NPE'
231247
is showkv($c), showkv($b), "... and it has the correct values";
232248
}
233249

@@ -237,6 +253,7 @@ sub showkv($x) {
237253
lives-ok { $s = $b.Str },
238254
".Str lives";
239255
isa-ok $s, Str, "... and produces a string";
256+
#?rakudo.jvm skip 'NPE'
240257
is $s.split(" ").sort.join(" "), "bar(3) baz foo(2)", "... which only contains bar baz and foo with the proper counts and separated by spaces";
241258
}
242259

@@ -257,6 +274,7 @@ sub showkv($x) {
257274
{
258275
my %b := bag "a", "b", "c", "b";
259276
isa-ok %b, Bag, 'A Bag bound to a %var is a Bag';
277+
#?rakudo.jvm skip 'NPE'
260278
is showkv(%b), 'a:1 b:2 c:1', '...with the right elements';
261279

262280
is %b<b>, 2, 'Single-key subscript (existing element)';
@@ -375,6 +393,7 @@ sub showkv($x) {
375393
'cannot call .grabpairs on a Bag';
376394
}
377395

396+
#?rakudo.jvm skip 'NPE'
378397
{
379398
my $b1 = Bag.new( (bag <a b c>) , <c c c d d d d>);
380399
is +$b1, 2, "Two elements";
@@ -400,16 +419,21 @@ sub showkv($x) {
400419

401420
{
402421
isa-ok 42.Bag, Bag, "Method .Bag works on Int-1";
422+
#?rakudo.jvm skip 'NPE'
403423
is showkv(42.Bag), "42:1", "Method .Bag works on Int-2";
404424
isa-ok "blue".Bag, Bag, "Method .Bag works on Str-1";
425+
#?rakudo.jvm skip 'NPE'
405426
is showkv("blue".Bag), "blue:1", "Method .Bag works on Str-2";
406427
my @a = <Now the cross-handed set was the Paradise way>;
407428
isa-ok @a.Bag, Bag, "Method .Bag works on Array-1";
429+
#?rakudo.jvm skip 'NPE'
408430
is showkv(@a.Bag), "Now:1 Paradise:1 cross-handed:1 set:1 the:2 was:1 way:1", "Method .Bag works on Array-2";
409431
my %x = "a" => 1, "b" => 2;
410432
isa-ok %x.Bag, Bag, "Method .Bag works on Hash-1";
433+
#?rakudo.jvm skip 'NPE'
411434
is showkv(%x.Bag), "a:1 b:2", "Method .Bag works on Hash-2";
412435
isa-ok (@a, %x).Bag, Bag, "Method .Bag works on List-1";
436+
#?rakudo.jvm skip 'NPE'
413437
is showkv((@a, %x).Bag), "Now:1 Paradise:1 a:1 b:2 cross-handed:1 set:1 the:2 was:1 way:1",
414438
"Method .Bag works on List-2";
415439
}
@@ -422,6 +446,7 @@ sub showkv($x) {
422446
is $b1.minpairs, [a=>1], '.minpairs works (non-empty 10)';
423447
is $b1.maxpairs, [d=>4], '.maxpairs works (non-empty 10)';
424448
# Bag is unordered according to S02:1476
449+
#?rakudo.jvm 4 skip 'NPE'
425450
is $b1.fmt('foo %s').split("\n").sort, ('foo a', 'foo b', 'foo c', 'foo d'),
426451
'.fmt(%s) works (non-empty 10)';
427452
is $b1.fmt('%s',',').split(',').sort, <a b c d>,
@@ -434,18 +459,21 @@ sub showkv($x) {
434459
my $b2 = <a b c c c d d d>.Bag;
435460
is $b2.total, 8, '.total gives sum of values (non-empty 8)';
436461
is +$b2, 8, '+$bag gives sum of values (non-empty 8)';
462+
#?rakudo.jvm 2 skip 'NPE'
437463
is $b2.minpairs.sort, [a=>1, b=>1], '.minpairs works (non-empty 8)';
438464
is $b2.maxpairs.sort, [c=>3, d=>3], '.maxpairs works (non-empty 8)';
439465

440466
$b2 = <a b c d>.Bag;
441467
is $b2.total, 4, '.total gives sum of values (non-empty 4)';
442468
is +$b2, 4, '+$bag gives sum of values (non-empty 4)';
469+
#?rakudo.jvm 2 skip 'NPE'
443470
is $b2.minpairs.sort,[a=>1,b=>1,c=>1,d=>1], '.minpairs works (non-empty 4)';
444471
is $b2.maxpairs.sort,[a=>1,b=>1,c=>1,d=>1], '.maxpairs works (non-empty 4)';
445472

446473
my $e = ().Bag;
447474
is $e.total, 0, '.total gives sum of values (empty)';
448475
is +$e, 0, '+$bag gives sum of values (empty)';
476+
#?rakudo.jvm 6 skip 'NPE'
449477
is $e.minpairs, (), '.minpairs works (empty)';
450478
is $e.maxpairs, (), '.maxpairs works (empty)';
451479
is $e.fmt('foo %s'), "", '.fmt(%s) works (empty)';
@@ -454,13 +482,15 @@ sub showkv($x) {
454482
is $e.fmt('%s,%s',':'), "", '.fmt(%s%s,sep) works (empty)';
455483
}
456484

457-
#?rakudo todo 'we have not secured .WHICH creation yet RT #124454'
485+
#?rakudo.moar todo 'we have not secured .WHICH creation yet RT #124454'
486+
#?rakudo.jvm skip 'NPE'
458487
{
459488
isnt 'a(1) Str|b(1) Str|c'.Bag.WHICH, <a b c>.Bag.WHICH,
460489
'Faulty .WHICH creation';
461490
}
462491

463492
# RT #117915
493+
#?rakudo.jvm skip 'NPE'
464494
{
465495
my @pairings;
466496
my Bag $bag .= new: <foo foo bar>;
@@ -478,6 +508,7 @@ sub showkv($x) {
478508
my class MyBag is Bag { }
479509
my $b = MyBag.new(|<a foo a a a a b foo>);
480510
isa-ok $b, MyBag, 'MyBag.new produces a MyBag';
511+
#?rakudo.jvm skip 'NPE'
481512
is showkv($b), 'a:5 b:1 foo:2', '...with the right elements';
482513
}
483514

@@ -500,6 +531,7 @@ sub showkv($x) {
500531
'Make sure we cannot assign on a .kv alias';
501532
}
502533

534+
#?rakudo.jvm skip 'NPE'
503535
{
504536
my $b = <a b b c c c d d d d>.Bag;
505537
my @a1;

0 commit comments

Comments
 (0)