Permalink
Browse files

Add a test for placeholder variables in PL/Perl6 and make them work

  • Loading branch information...
1 parent 061ed2a commit 7532acb8290da930004b926d2d61e22ea7f863ad @leto committed Aug 17, 2010
Showing with 13 additions and 8 deletions.
  1. +1 −2 plperl6.pir
  2. +12 −6 t/sql/plperl6.sql
View
@@ -23,7 +23,7 @@
nullargs = isnull perl6_args
if nullargs goto call_with_empty_args
say "calling with args"
- $P3 = output(perl6_args)
+ $P3 = output(perl6_args :flat)
$I0 = isa $P3, "Block"
unless $I0 goto done
# the output of running the function returned a Block,
@@ -58,6 +58,5 @@
error:
die "Could not turn Parrot array into a Perl 6 Parcel!"
empty:
- say "EMTPY!"
.return()
.end
View
@@ -15,10 +15,10 @@ BEGIN;
\i plparrot.sql
-- Plan the tests.
-SELECT plan(13);
+SELECT plan(14);
CREATE OR REPLACE FUNCTION test_void_plperl6() RETURNS void LANGUAGE plperl6 AS $$
-() { Nil }
+{ Nil }
$$;
CREATE OR REPLACE FUNCTION test_int_plperl6() RETURNS int LANGUAGE plperl6 AS $$
@@ -42,18 +42,23 @@ CREATE OR REPLACE FUNCTION test_2arguments_plperl6(integer,integer) RETURNS int
$$;
CREATE OR REPLACE FUNCTION test_fibonacci_plperl6(integer) RETURNS int LANGUAGE plperl6 AS $$
-(@_) {
+(*@_) {
my $limit = @_[0];
[+] (1, 1, *+* ... $limit)
}
$$;
-CREATE OR REPLACE FUNCTION test_pointy_fibonacci_plperl6(integer) RETURNS int LANGUAGE plperl6 AS $$
+CREATE OR REPLACE FUNCTION test_named_fibonacci_plperl6(integer) RETURNS int LANGUAGE plperl6 AS $$
($limit) {
[+] (1, 1, *+* ... $limit)
}
$$;
+CREATE OR REPLACE FUNCTION test_input_2_placeholders(integer, integer) RETURNS int LANGUAGE plperl6 AS $$
+{
+ return $^a * $^b - $^b;
+}
+$$;
CREATE OR REPLACE FUNCTION test_named_pointy(integer, integer, integer) RETURNS int LANGUAGE plperl6 AS $$
{
@@ -78,16 +83,17 @@ select is(test_void_plperl6()::text,''::text,'Return nothing from PL/Perl6');
select is(test_float_plperl6(), 5.0::float,'Return a float from PL/Perl6');
select is(test_string_plperl6(), 'rakudo','Return a varchar from PL/Perl6');
select is(test_singlequote_plperl6(), 'rakudo*','Use a single quote in a PL/Perl6 procedure');
+select is(test_input_2_placeholders(5,4), 16, 'Can take 2 integer input arguments');
-select is(test_fibonacci_plperl6(100),232,'Calculate the sum of all Fibonacci numbers <= 100');
-select is(test_pointy_fibonacci_plperl6(100),232,'Calculate the sum of all Fibonacci numbers <= 100 (pointy block)');
select is(test_arguments_plperl6(5),5,'We can return an argument unchanged');
select is(test_defined_plperl6(100),1,'@_[0] is defined when an argument is passed in');
select is(test_defined_plperl6(),0,'@_[0] is not defined when an argument is not passed in');
select is(test_2arguments_plperl6(4,9),2,'PL/Perl sees multiple arguments');
select is(test_named_pointy(10,20,30), 6000, 'Pointy blocks with named parameters work');
+select is(test_named_fibonacci_plperl6(100),232,'Calculate the sum of all Fibonacci numbers <= 100 (named variable in signature)');
+select is(test_fibonacci_plperl6(100),232,'Calculate the sum of all Fibonacci numbers <= 100');
SELECT language_is_trusted( 'plperl6', 'PL/Perl6 should be trusted' );

0 comments on commit 7532acb

Please sign in to comment.