Skip to content

Commit

Permalink
Browse files Browse the repository at this point in the history
Add tests for the cookbook 01strings examples
  • Loading branch information
Paul Cochrane committed May 6, 2015
1 parent 0c6ea29 commit 2d3a1a1
Showing 1 changed file with 174 additions and 0 deletions.
174 changes: 174 additions & 0 deletions t/categories/cookbook/01strings.t
@@ -0,0 +1,174 @@
use v6;

use Test;

plan 9;

my $skip = True;

subtest {
plan 1;

my $example-name = "01-00introduction.pl";
my $expected-output = q:to/EOD/;
Hello
Hello
Hello
HelloWorld!
Hello World!
This is $string: a scalar holding a String
$string is Str
This is $scalar holding a String
$scalar is Str
1
2 is a number interpreted as a string
7 is a number interpreted as a string
0
2
111
1 + 1
2
1234
$scalar is Int
~$scalar is Str
The quick brown fox jumps over the lazy dog.
dog.
The quick brown fox jumps over the lazy
dog.
The quick brown fox\n\tjumps over the lazy dog\n
The quick brown fox
jumps over the lazy dog
The quick brown fox jumps over the lazy $var1
The quick brown fox jumps over the lazy dog
The quick brown @animal[0] jumps over the lazy @animal[1]
The quick brown fox jumps over the lazy dog
The quick brown %animal{'quick'} jumps over the lazy %animal{'lazy'}.
The quick brown fox jumps over the lazy dog.
@animal.elems() {@animal.elems} &elems(@animal)
2 2 2
EOD

my $output = run-example($example-name);
is($output, $expected-output, $example-name);
}, "01-00introduction.pl";

subtest {
plan 1;

my $example-name = "01-01substrings.pl";
my $expected-output = q:to/EOD/;
gs is
gs is da bomb
Pugilism ain't for wimps
EOD

my $output = run-example($example-name);
is($output, $expected-output, $example-name);
}, "01-01substrings.pl";

subtest {
plan 1;

my $example-name = "01-03exchanging-values.pl";
my $expected-output = q:to/EOD/;
2
3
EOD

my $output = run-example($example-name);
is($output, $expected-output, $example-name);
}, "01-03exchanging-values.pl";

subtest {
plan 1;

my $example-name = "01-04converting-values.pl";
my $expected-output = q:to/EOD/;
97
a
102
EOD

my $output = run-example($example-name);
is($output, $expected-output, $example-name);
}, "01-04converting-values.pl";

subtest {
plan 1;

my $example-name = "01-05namedunicode.pl";
my $expected-output = q:to/EOD/;
®
POUTING CAT FACE
EOD

my $output = run-example($example-name);
is($output, $expected-output, $example-name);
}, "01-05namedunicode.pl";

subtest {
plan 1;

my $example-name = "01-06reversing-strings.pl";
my $expected-output = q:to/EOD/;
egarfissO hsimaeuqS era sdroW cigaM ehT
Ossifrage Squeamish are Words Magic The
EOD

my $output = run-example($example-name);
is($output, $expected-output, $example-name);
}, "01-06reversing-strings.pl";

subtest {
plan 1;

my $example-name = "01-13upper-lower-case.pl";
my $expected-output = q:to/EOD/;
THE CAT SAT ON THE MAT
the cat sat on the mat
The Cat Sat On The Mat
EOD

my $output = run-example($example-name);
is($output, $expected-output, $example-name);
}, "01-13upper-lower-case.pl";

subtest {
plan 1;

my $example-name = "01-19trim-whitespace.pl";
my $expected-output = q:to/EOD/;
:string("the cat sat on the mat")
EOD

my $output = run-example($example-name);
is($output, $expected-output, $example-name);
}, "01-19trim-whitespace.pl";

subtest {
plan 1;

my $example-name = "01-22soundex-matching.pl";
my $expected-output = q:to/EOD/;
S530
S530
B420
EOD

my $output = run-example($example-name);
is($output, $expected-output, $example-name);
}, "01-22soundex-matching.pl";

#| run the given example script
sub run-example($name, :$script-args = Nil) {
my $base-dir = "categories/cookbook/01strings";
my $script-path = $base-dir ~ "/" ~ $name;
my $base-cmd = "perl6 $script-path";
my $output = $script-args ?? qqx{$base-cmd \"$script-args\"}
!! qqx{$base-cmd};

return $output;
}

# vim: expandtab shiftwidth=4 ft=perl6

0 comments on commit 2d3a1a1

Please sign in to comment.