Skip to content

Commit

Permalink
[t/spec]
Browse files Browse the repository at this point in the history
 * tests for RT #63956
 * state variables in subset types
 * subsets of subset types
 * sub form of split with limits
 * Str.split('', $limit) tests


git-svn-id: http://svn.pugscode.org/pugs@25963 c213334d-75ef-0310-aa23-eaa082d1ae64
  • Loading branch information
moritz committed Mar 22, 2009
1 parent 310944a commit 21f6acc
Show file tree
Hide file tree
Showing 8 changed files with 102 additions and 11 deletions.
17 changes: 16 additions & 1 deletion S04-declarations/state.t
Original file line number Diff line number Diff line change
Expand Up @@ -2,7 +2,7 @@ use v6;

use Test;

plan 30;
plan 34;

# L<S04/The Relationship of Blocks and Declarations/There is a new state declarator that introduces>

Expand Down Expand Up @@ -242,3 +242,18 @@ plan 30;
is fib(10), 55, "fib 2 works";
is $seensize, 11, "[list] assignment state in fib memoizes";
}


{
# now we're just being plain evil:
subset A of Int where { $_ < state $x++ };
my A $y = -4;
# the compiler could have done some checks somehwere, so
# pick a reasonably high number
dies_ok { $y = 900000 }, 'growing subset types rejects too high values';
lives_ok { $y = 1 }, 'the state variable in subset types works (1)';
lives_ok { $y = 2 }, 'the state variable in subset types works (2)';
lives_ok { $y = 3 }, 'the state variable in subset types works (3)';
}

# vim: ft=perl6
18 changes: 18 additions & 0 deletions S11-modules/nested.t
Original file line number Diff line number Diff line change
@@ -0,0 +1,18 @@
use v6;
use Test;
plan 3;

# test that classes and roles declared in modules get into the correct
# namespace

# Used to be a Rakudo bug, RT #63956

BEGIN { @*INC.push('t/spec/packages/') };

eval_lives_ok 'use A::A', 'Can load classes from nested modules';
eval_lives_ok 'use A::A; A::B::D ~~ A::B::B or die()',
'... and the composition worked';
eval_lives_ok 'use A::A; A::B::D.new()',
'... and instantiation works';

# vim: ft=perl6
14 changes: 13 additions & 1 deletion S12-enums/basic.t
Original file line number Diff line number Diff line change
@@ -1,6 +1,6 @@
use v6;
use Test;
plan 16;
plan 20;

# Very basic enum tests

Expand All @@ -24,6 +24,18 @@ enum Day <Sun Mon Tue Wed Thu Fri Sat>;
ok $x ~~ Day::Mon, 'Can Smartmatch for enum value';
}

{
# usually we don't test explicit value for .perl, but here
# it's specced, so we make an excpetion
#?rakudo 2 todo '.perl on Enums'
is Day::Mon.perl, 'Day::Mon', '.perl on long form of Enum value';
is Mon.perl, 'Day::Mon', '.perl on short form of Enum value';

#?rakudo 2 skip '.name on Enums'
is Day::Mon.name, 'Mon', '.name on long form of Enum value';
is Mon.name, 'Mon', '.name on short form of Enum value';
}

enum JustOne <Thing>;
{
is JustOne::Thing, 0, 'Enum of one element works.';
Expand Down
14 changes: 13 additions & 1 deletion S12-subset/subtypes.t
Original file line number Diff line number Diff line change
Expand Up @@ -2,7 +2,7 @@ use v6;

use Test;

plan 37;
plan 40;

=begin description
Expand Down Expand Up @@ -127,4 +127,16 @@ ok eval('is_num_odd(3)'), "Int accepted by Num::Odd";
is $x, 2, 'and the value was preserved';
}

{
# chained subset types
subset Positive of Int where { $_ > 0 };
subset NotTooLarge of Positive where { $_ < 10 };

my NotTooLarge $x;

lives_ok { $x = 5 }, 'can satisfy both conditions on chained subset types';
dies_ok { $x = -2 }, 'violating first condition barfs';
dies_ok { $x = 22 }, 'violating second condition barfs';
}

# vim: ft=perl6
3 changes: 2 additions & 1 deletion S16-filehandles/io.t
Original file line number Diff line number Diff line change
Expand Up @@ -12,7 +12,7 @@ I/O tests
=end pod

plan 57;
plan 58;

#?pugs emit if $*OS eq "browser" {
#?pugs emit skip_rest "Programs running in browsers don't have access to regular IO.";
Expand Down Expand Up @@ -156,3 +156,4 @@ ok($fh9.close, 'file closed okay (9)');

#?pugs todo 'buggy on Win32'
ok(unlink($filename), 'file has been removed');
ok $filename !~~ :e, '... and the tempfile is gone, really';
30 changes: 23 additions & 7 deletions S32-str/split-simple.t
Original file line number Diff line number Diff line change
Expand Up @@ -2,7 +2,7 @@ use v6;
use Test;

# L<S29/Str/"=item split">
plan 32;
plan 42;

=begin description
Expand All @@ -14,17 +14,22 @@ here is a start from scratch that should be easier to run.
#?DOES 2
sub split_test(@splitted, @expected, Str $desc) {
ok @splitted.elems == @expected.elems,
"split created the correct value amount for: $desc";
"split created the correct number of elements for: $desc";
is @splitted.join('|-|'), @expected.join('|-|'),
"values matched for: $desc"
}

split_test 'a1b24f'.split(/\d+/), <a b f>, 'Str.split(/regex/) works';
split_test split(/\d+/, 'a1b24f'), <a b f>, 'split(/regex/, Str) works';
split_test 'a1b'.split(1), <a b>, 'Str.split(Any) works (with Str semantics';
split_test 'a1b24f'.split(/\d+/), <a b f>, 'Str.split(/regex/)';
split_test split(/\d+/, 'a1b24f'), <a b f>, 'split(/regex/, Str)';
split_test 'a1b'.split(1), <a b>, 'Str.split(Any) (with Str semantics';

split_test 'a1b24f'.split(/\d+/, *), <a b f>, 'Str.split(/regex/) (with * limit)';
split_test split(/\d+/, 'a1b24f', *), <a b f>, 'split(/regex/, Str) (with * limit)';
split_test 'a1b'.split(1, *), <a b>, 'Str.split(Any) (with Str semantics (with * limit)';

{
split_test 123.split(2), <1 3>, 'Int.split(Int) works';
split_test split(2, 123), <1 3>, 'split(Int, Int) works';
split_test 123.split(2), <1 3>, 'Int.split(Int)';
split_test split(2, 123), <1 3>, 'split(Int, Int)';
}

split_test '1234'.split(/X/), @(<1234>), 'Non-matching regex returns whole string';
Expand All @@ -50,6 +55,17 @@ split_test(
'Limit larger than number of split values doesn\'t return extranuous elements'
);

split_test
'abcdefg'.split('', 3),
<a b cdefg>,
'split into characters respects limit (1)';

# catch possible off-by-one errors
split_test
'abc'.split('', 3),
<a b c>,
'split into characters respects limit (2)';

# zero-width assertions shouldn't loop
# with additional spaces
# a b 3 4 d 5 z split on <before \d>
Expand Down
9 changes: 9 additions & 0 deletions packages/A/A.pm
Original file line number Diff line number Diff line change
@@ -0,0 +1,9 @@
# used in t/spec/S11-modules/nested.t

BEGIN { @*INC.push('t/spec/packages') };

module A::A {
use A::B;
}

# vim: ft=perl6
8 changes: 8 additions & 0 deletions packages/A/B.pm
Original file line number Diff line number Diff line change
@@ -0,0 +1,8 @@
# used in t/spec/S11-modules/nested.t

module A::B;
role B { };
class D does A::B::B { };



0 comments on commit 21f6acc

Please sign in to comment.