Skip to content

Commit

Permalink
Add some PL/PIR tests for conditionally concatenating input strings
Browse files Browse the repository at this point in the history
  • Loading branch information
leto committed Aug 19, 2010
1 parent 01b4a27 commit ae12d06
Showing 1 changed file with 21 additions and 1 deletion.
22 changes: 21 additions & 1 deletion t/sql/test.sql
Expand Up @@ -16,7 +16,7 @@ BEGIN;
\i plparrot.sql

-- Plan the tests.
SELECT plan(34);
SELECT plan(37);

CREATE OR REPLACE FUNCTION test_void() RETURNS void AS $$
.return()
Expand Down Expand Up @@ -113,6 +113,20 @@ CREATE OR REPLACE FUNCTION test_concat_input(text,text) RETURNS varchar AS $$
.return($S1)
$$ LANGUAGE plparrot;

CREATE OR REPLACE FUNCTION test_concat_conditional(text,text,float)
RETURNS varchar LANGUAGE plparrot AS $$
.param string s1
.param string s2
.param num x
if x < 0 goto backward
$S1 = s1 . s2
goto done
backward:
$S1 = s2 . s1
done:
.return($S1)
$$;

CREATE OR REPLACE FUNCTION test_char_in(char) RETURNS char AS $$
.param string s
.return(s)
Expand Down Expand Up @@ -227,6 +241,12 @@ select is(test_varchar_out_concat('stuff'), 'redfish', 'We can concat and return

select is(test_concat_input('red','fish'), 'redfish', 'We can concat input args');

select is(test_concat_conditional('red','fish', 1), 'redfish', 'We can concat input args conditionally');

select is(test_concat_conditional('red','fish', 0), 'redfish', 'We can concat input args conditionally');

select is(test_concat_conditional('red','fish', -1), 'fishred', 'We can concat input args conditionally');

select is(test_int_float(42,6.9), 1, 'We can pass an int and float as arguments');

select is(test_char_in('c'), 'c', 'We can pass a char in');
Expand Down

0 comments on commit ae12d06

Please sign in to comment.