Permalink
Browse files

[gsoc_spectest] new test for closure parameters. (added 9 tests)

git-svn-id: http://svn.pugscode.org/pugs@21918 c213334d-75ef-0310-aa23-eaa082d1ae64
  • Loading branch information...
1 parent 553d616 commit 86188d0717da414e8d4673d94bca76ee8e3672c3 Auzon committed Aug 17, 2008
Showing with 41 additions and 0 deletions.
  1. +41 −0 S06-signature/closure-parameters.t
@@ -0,0 +1,41 @@
+use v6;
+use Test;
+
+plan 9;
+
+# L<S06/Closure parameters>
+
+{
+ my sub testit (&testcode) {testcode()}
+
+ ok(testit({return 1}), 'code executes as testsub({...})');
+
+ my $code = {return 1};
+ ok(testit($code), 'code executes as testsub($closure)');
+
+ my sub returntrue {return 1}
+ ok(testit(&returntrue), 'code executes as testsub(&subroutine)');
+}
+
+# with a signature for the closure
+{
+ my sub testit (&testcode:(Int)) {testcode(12)}
+ my sub testint(Int $foo) {return 1}
+ my sub teststr(Str $foo) {return 'foo'}
+
+ ok(testit(&testint), 'code runs with proper signature (1)');
+ eval_dies_ok('testit(&teststr)', 'code dies with invalid signature (1)');
+}
+
+{
+ my sub testit (&testcode:(Int --> Bool)) {testcode()}
+ my Bool sub testintbool(Int $foo) {return Bool::True}
+ my Bool sub teststrbool(Str $foo) {return Bool::False}
+ my Int sub testintint (Int $foo) {return 1}
+ my Int sub teststrint (Str $foo) {return 0}
+
+ ok(testit(&testintbool), 'code runs with proper signature (2)');
+ eval_dies_ok('testit(&testintint)', 'code dies with invalid signature (2)');
+ eval_dies_ok('testit(&teststrbool)', 'code dies with invalid signature (3)');
+ eval_dies_ok('testit(&teststrint)', 'code dies with invalid signature (4)');
+}

0 comments on commit 86188d0

Please sign in to comment.