From 56f87368ea92a0efad179d923f0029f3bf38bf86 Mon Sep 17 00:00:00 2001 From: Auzon Date: Wed, 4 Jun 2008 18:07:51 +0000 Subject: [PATCH] [gsoc_spectest] Moved elems.t to spec area, added smartlink. Added 25 sprintf tests. git-svn-id: http://svn.pugscode.org/pugs@20654 c213334d-75ef-0310-aa23-eaa082d1ae64 --- S29-array/elems.t | 73 +++++++++++++++++++++++++++++++++++++++++++++++ S29-str/sprintf.t | 37 ++++++++++++++++++++++-- 2 files changed, 108 insertions(+), 2 deletions(-) create mode 100644 S29-array/elems.t diff --git a/S29-array/elems.t b/S29-array/elems.t new file mode 100644 index 0000000000..85c943b83e --- /dev/null +++ b/S29-array/elems.t @@ -0,0 +1,73 @@ +use v6; + +use Test; + +# L Work"> +# L +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 = ; + 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 = []; + is $a.elems, 3, ".elems works on initialized arrayrefs (1)"; +} + +{ + my $a = ; + 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"; +} diff --git a/S29-str/sprintf.t b/S29-str/sprintf.t index 68568ee4be..0d85092f8f 100644 --- a/S29-str/sprintf.t +++ b/S29-str/sprintf.t @@ -2,12 +2,13 @@ use v6; use Test; -plan 12; +plan 37; # L -#?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"; @@ -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 +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)');