Skip to content

Commit

Permalink
Add a test suite & prefix:<!>
Browse files Browse the repository at this point in the history
  • Loading branch information
Stefan O'Rear committed Jul 14, 2010
1 parent be0da90 commit d7f3d96
Show file tree
Hide file tree
Showing 3 changed files with 82 additions and 2 deletions.
4 changes: 2 additions & 2 deletions Makefile
Original file line number Diff line number Diff line change
Expand Up @@ -2,9 +2,9 @@ STDBASE=/usr/local/src/pugs/src/perl6
STDENV=PERL5LIB=$(STDBASE) PERL6LIB=$(STDBASE):$(STDBASE)/lib

test: all
perl -MCompilerDriver=:all -e 'header; mainline(q(say "Hello World")); bootstrap' > Program.cs
perl -MFile::Slurp -MCompilerDriver=:all -e 'header; mainline(scalar read_file("test.pl")); bootstrap' > Program.cs
gmcs /r:Setting.dll Program.cs
mono --debug=casts Program.exe
prove -e 'mono --debug=casts' Program.exe

all: Niecza/Grammar.pmc
perl -MCompilerDriver=:all -e 'header; setting' > Setting.cs
Expand Down
2 changes: 2 additions & 0 deletions setting
Original file line number Diff line number Diff line change
Expand Up @@ -310,4 +310,6 @@ sub postfix:<++>($v) { my $old = $v; $v = ($v + 1); $old }
sub prefix:<~>($v) { $v.Str } # should be Stringy
sub prefix:<?>($v) { $v.Bool }

sub prefix:<!>($v) { if $v { ?0 } else { ?1 } }

YOU_ARE_HERE;
78 changes: 78 additions & 0 deletions test.pl
Original file line number Diff line number Diff line change
@@ -0,0 +1,78 @@
# vim: ft=perl6

my $testnum = 1;
sub ok($bool, $tag) {
my $not = (if $bool { "" } else { "not " });
say ($not ~ ("ok " ~ ($testnum++ ~ (" - " ~ $tag))));
}

sub plan($num) {
say ("1.." ~ $num);
}

plan 18;

ok 1, "one is true";
ok 2, "two is also true";
ok !(0), "zero is false";
ok 2 + 2 == 4, "two and two makes four";
{
my $x = 2 + 2;
ok $x == 4, "two and two can be stored in a variable";
}

ok 2 < 3, "two is less than three";
ok !(3 < 1), "three is not less than one";

ok 42 / 3 == 14, "division comes out in the right order";

{
my $x = 2;
ok (--$x) == 1, "predecrement returns new value";
ok $x == 1, "value clearly decremented";

ok ($x++) == 1, "postincrement returns old";
ok $x == 2, "but value increased";
}

{
my $x = 2;
my $y := $x;

ok $y == 2, "binding shares old value";
$x = 5;
ok $y == 5, "changing old changes new";
$y = 4;
ok $y == 4, "changing new changes old";
}

{
sub fib($n) {
if $n <= 2 {
1
} else {
fib($n - 1) + fib($n - 2);
}
}

ok fib(10) == 55, "recursion works";
}

{
my $n = 9;
my $a = 1;
my $b = 1;
while --$n >= 0 {
my $c = $a + $b;
$a = $b;
$b = $c;
}

ok $a == 55, "looping works";
}

my $x;
PRE-INIT {
$x = 1;
}
ok $x, "changes made in the protolexpad are visible at runtime";

0 comments on commit d7f3d96

Please sign in to comment.