-
Notifications
You must be signed in to change notification settings - Fork 15
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
- Loading branch information
Stefan O'Rear
committed
Jul 14, 2010
1 parent
be0da90
commit d7f3d96
Showing
3 changed files
with
82 additions
and
2 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
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
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,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"; |