Skip to content

Commit

Permalink
[gsoc_spectest] Moved elems.t to spec area, added smartlink. Added 25…
Browse files Browse the repository at this point in the history
… sprintf tests.

git-svn-id: http://svn.pugscode.org/pugs@20654 c213334d-75ef-0310-aa23-eaa082d1ae64
  • Loading branch information
Auzon authored and Auzon committed Jun 4, 2008
1 parent ba6adfc commit 56f8736
Show file tree
Hide file tree
Showing 2 changed files with 108 additions and 2 deletions.
73 changes: 73 additions & 0 deletions S29-array/elems.t
@@ -0,0 +1,73 @@
use v6;

use Test;

# L<A02/"RFC 212: Make C<length(@array)> Work">
# L<S29/"Array"/"elems">
plan 12;

{
my @a;
is @a.elems, 0, ".elems works on uninitialized arrays";
}

{
my @a = ();
is @a.elems, 0, ".elems works on empty arrays";
}

{
my @a = <a b c>;
is @a.elems, 3, ".elems works on initialized arrays";
}

{
my $a;
dies_ok { $a.elems }, ".elems does not work on arbitrary scalars (1)";
}

{
# (ryporter 2007-09-22): This test fails because a VInt is
# being converted into an array in the final defintion of doArray
# in AST/Internals.hs ("doArray val f"). When I tried replacing
# "val" with "(VList x)", to accept fewer inputs, this test passed,
# but many others failed.
#
# Also relevant is the "(rw!Array)" declaration for List::elems
# in Prim.hs. Changing it to "(Array)", combined with the above
# change, caused both this and the preceding test to succeed.
#
my $a = 42;
dies_ok { $a.elems }, ".elems does not work on arbitrary scalars (2)";
}

{
my $a = [];
is $a.elems, 0, ".elems works on empty arrayrefs";
}

{
my $a = [<a b c>];
is $a.elems, 3, ".elems works on initialized arrayrefs (1)";
}

{
my $a = <a b c>;
is $a.elems, 3, ".elems works on initialized arrayrefs (2)";
}

{
dies_ok { elems(1,2,3,4) }, "elems(1,2,3,4) should not work";
}

{
is (elems (1,2,3,4)), 4, "elems (1,2,3,4) should work";
}

{
is (elems [1,2,3,4]), 4, "elems [1,2,3,4] should work";
}

{
is (elems ([1,2,3,4],)), 1, "elems ([1,2,3,4],) should return 1";
}
37 changes: 35 additions & 2 deletions S29-str/sprintf.t
Expand Up @@ -2,12 +2,13 @@ use v6;

use Test;

plan 12;
plan 37;

# L<S29/Str/"identical to" "C library sprintf">

#?rakudo: 12 skip 'not yet implemented'
#?rakudo: 37 skip 'not yet implemented'
is sprintf("Hi"), "Hi", "sprintf() works with zero args";
is sprintf("%%"), "%", "sprintf() escapes % correctly";
is sprintf("%03d", 3), "003", "sprintf() works with one arg";
is sprintf("%03d %02d", 3, 1), "003 01", "sprintf() works with two args";
is sprintf("%d %d %d", 3,1,4), "3 1 4", "sprintf() works with three args";
Expand All @@ -21,3 +22,35 @@ is sprintf("%b",30), '11110', 'longer string, no padding';
is sprintf("%2b",30), '11110', 'padding specified, not needed';
is sprintf("%03b",7), '111', '0 padding, longer string';
is sprintf("%b %b",3,3), '11 11', 'two args %b';

is sprintf('%c', 97), 'a', '%c test';
is sprintf('%s', 'string'), 'string', '%s test';

is sprintf('%d', 12), '12', 'simple %d';
is sprintf('%d', -22), '-22', 'negative %d';
is sprintf('%04d', 32), '0032', '0-padded %d';
is sprintf('%04d', -42), '-042', '0-padded negative %d';
is sprintf('%i', -22), '-22', 'negative %i';
is sprintf('%04i', -42), '-042', '0-padded negative %i';

is sprintf('%u', 12), '12', 'simple %u';
is sprintf('%u', 22.01), '22', 'decimal %u';
is sprintf('%04u', 32), '0032', '0-padded %u';
is sprintf('%04u', 42.6), '0042', '0-padded decimal %u';

is sprintf('%o', 12), '14', 'simple %o';
is sprintf('%o', 22.01), '26', 'decimal %o';
is sprintf('%03o', 32), '040', '0-padded %o';
is sprintf('%03o', 42.6), '052', '0-padded decimal %o';

is sprintf('%x', 12), 'c', 'simple %x';
is sprintf('%x', 22.01), '16', 'decimal %x';
is sprintf('%03x', 32), '020', '0-padded %x';
is sprintf('%03x', 42.6), '02a', '0-padded decimal %x';
# tests for %X
is sprintf('%x', 12), 'C', 'simple %X';
is sprintf('%03X', 42.6), '02A', '0-padded decimal %X';

# L<S29/"Str"/"Perl 5 compatibility:">
dies_ok(sub {my $x = sprintf('%n', 1234)}, '%n dies (Perl 5 compatibility)');
dies_ok(sub {my $x = sprintf('%p', 1234)}, '%p dies (Perl 5 compatibility)');

0 comments on commit 56f8736

Please sign in to comment.