Skip to content
Browse files

Add some PL/PIR tests for conditionally concatenating input strings

  • Loading branch information...
1 parent 01b4a27 commit ae12d064324d3be2ef727f624b1ba1f88c4a6701 @leto committed
Showing with 21 additions and 1 deletion.
  1. +21 −1 t/sql/test.sql
View
22 t/sql/test.sql
@@ -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()
@@ -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)
@@ -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');

0 comments on commit ae12d06

Please sign in to comment.
Something went wrong with that request. Please try again.