Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
Browse files
Browse the repository at this point in the history
[io grant] Add &prompt tests
- Loading branch information
1 parent
ea41dcd
commit 125fe18
Showing
1 changed file
with
57 additions
and
0 deletions.
There are no files selected for viewing
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
| Original file line number | Diff line number | Diff line change |
|---|---|---|
| @@ -0,0 +1,57 @@ | ||
| use v6; | ||
| use lib 't/spec/packages'; | ||
| use Test; | ||
| use Test::Util; | ||
|
|
||
| # Tests for &prompt | ||
|
|
||
| my @tests = () => "", 'a' => "a", 42 => "42", [<a b c>] => "a b c", | ||
| [<a b>, (42, (3, 5))] => "a b 42 3 5", | ||
| class { method Str { "pass" } }.new => "pass"; | ||
|
|
||
| plan 3*@tests; | ||
|
|
||
| { | ||
| for @tests -> (:key($prompt), :value($out)) { | ||
| subtest "default handle attributes" => { | ||
| plan 2; | ||
| my $file-in = make-temp-file :content("foobar\nbarbar\nberbar"); | ||
| my $file-out = make-temp-file; | ||
| temp $*OUT = $file-out.open: :w; | ||
| temp $*IN = $file-in.open; | ||
| is-deeply prompt($prompt<>), 'foobar', 'return value'; | ||
| $*OUT.close; $*IN.close; | ||
| is-deeply $file-out.slurp, $out, 'printed content'; | ||
| } | ||
|
|
||
| subtest "changed handle attributes" => { | ||
| plan 2; | ||
| my $file-in = make-temp-file :content("foobar\nbarbar\nberbar"); | ||
| my $file-out = make-temp-file; | ||
| temp $*OUT = $file-out.open: :w, :nl-out<MEOW>; | ||
| temp $*IN = $file-in.open: :!chomp, :nl-in<oba>; | ||
| is-deeply prompt($prompt<>), 'fooba', 'return value'; | ||
| $*OUT.close; $*IN.close; | ||
| is-deeply $file-out.slurp, $out, 'printed content'; | ||
| } | ||
|
|
||
| subtest "no-arg prompt" => { | ||
| plan 1; | ||
| temp $*OUT = class :: is IO::Handle { | ||
| method opened { True } | ||
| method print { die "Method must not be called" } | ||
| method print-nl { die "Method must not be called" } | ||
| method say { die "Method must not be called" } | ||
| method put { die "Method must not be called" } | ||
| method printf { die "Method must not be called" } | ||
| }.new; | ||
|
|
||
| my $file-in = make-temp-file :content("foobar\nbarbar\nberbar"); | ||
| temp $*IN = $file-in.open: :nl-in<oba>; | ||
| is-deeply prompt(), 'fo', 'return value'; | ||
| $*IN.close; | ||
| } | ||
| } | ||
| } | ||
|
|
||
| # vim: ft=perl6 |