Skip to content

Commit

Permalink
Browse files Browse the repository at this point in the history
add more test to say.t, update note.t to use Fake IO
  • Loading branch information
zhuomingliang committed Aug 28, 2015
1 parent 60232eb commit fd0153c
Show file tree
Hide file tree
Showing 2 changed files with 19 additions and 30 deletions.
46 changes: 17 additions & 29 deletions S16-io/note.t
Expand Up @@ -2,41 +2,29 @@ use v6;

# L<S32::IO/IO/=item note>

# doesn't use Test.pm and plan() intentionally
use Test;

say "1..7";
plan 5;

# We can't write TAP output to STDERR
$*ERR = $*OUT;

# Tests for note
{
note "ok 1 - basic form of note";
}

{
note "o", "k 2 - note with multiple parame", "ters (1)";

my @array = ("o", "k 3 - say with multiple parameters (2)");
note @array;
class FakeIO {
has $.Str = '';
method print(\arg) { $!Str ~= arg };
}

{
my $arrayref = <<'ok 4 - ' note stringifies its args>>;
note $arrayref;
class InterestingGist {
has $.x;
multi method gist(InterestingGist:D:) { "[$.x]" };
}

{
"ok 5 - method form of note".note;
}


"ok 6 - Mu.note\n".note;

grammar A {
token TOP { .+ };
sub cap(&code) {
my $*ERR = FakeIO.new;
code();
$*ERR.Str;
}

A.parse("ok 7 - Match.note\n").Str.note;
is cap({ note 42 }), "42\n", 'note(an integer)';
is cap({ note InterestingGist.new(x => "abc") }), "[abc]\n", "note() calls .gist method of a single argument";
is cap({ note InterestingGist.new(x => 1), "foo"}), "[1]foo\n", "note() joins multiple args with whitespace";

# vim: ft=perl6
is cap({ "flurb".note }), "flurb\n", ".note as a method on Str (for example)";
is cap({ note Int}), "(Int)\n", "note Class name is ok";
3 changes: 2 additions & 1 deletion S16-io/say.t
Expand Up @@ -4,7 +4,7 @@ use v6;

use Test;

plan 4;
plan 5;

class FakeIO {
has $.Str = '';
Expand All @@ -27,3 +27,4 @@ is cap({ say InterestingGist.new(x => "abc") }), "[abc]\n", "say() calls .gist m
is cap({ say InterestingGist.new(x => 1), "foo"}), "[1]foo\n", "say() joins multiple args with whitespace";

is cap({ "flurb".say }), "flurb\n", ".say as a method on Str (for example)";
is cap({ say Int}), "(Int)\n", "say Class name is ok";

0 comments on commit fd0153c

Please sign in to comment.