CREATE LANGUAGE plperl;
CREATE SCHEMA tools;
\set ECHO none
\i tools.sql
\set ECHO all

select tools.session__set('one', 'a');
select tools.session__get('one');
-- fail, 'a' is not a hash reference --
select tools.session__set('one', 'a', 'b');
-- clear the hash --
select tools.session__set('one', NULL);
-- fail, no such value in a hash
select tools.session__get('one');
select tools.session__set('one', 'I', 'a');
-- fail, the value is a hash reference --
select tools.session__get('one');
select tools.session__get('one', 'I');
select tools.session__set('one', 'I', 'b');
select tools.session__set('one', 'II', 'c');
select tools.session__get('one', 'I');
select tools.session__get('one', 'II');
-- fail, no such key --
select tools.session__get('one', 'III');
-- clear the 'one/I' element --
select tools.session__set('one', 'I', NULL);
-- fail, no such key --
select tools.session__get('one', 'I');
-- clear the 'one' hash --
select tools.session__set('one', NULL);
-- fail, no such key --
select tools.session__get('one', 'II');
-- populate the hash --
select tools.session__set('one', 'I', 'a');
select tools.session__set('one', 'II', 'b');
select tools.session__set('two', 'II');
select tools.session__set('three', 'III');
select tools.session__set('four', 'IV');
select tools.session__set('five', 'V');
select tools.session__set('six', 'VI');
select tools.session__set('seven', 'VII', 'a');
select tools.session__set('seven', 'VIII', 'b');

-- clear --
select tools.session__clean('delete', 'one, two, three');
select tools.session__list();
select tools.session__clean('keep', 'six, seven');
select tools.session__list();

select tools.session__set('first', 'second', 'third', 'forth');
select tools.session__get('first', 'second', 'third');
-- fail, the value is a hash reference
select tools.session__set('first', 'second', '5');
-- fail, the value is a hash reference
select tools.session__get('first');
-- fail, the value is a hash reference
select tools.session__get('first', 'second');
select tools.session__set('first', 'fifth', 'sixth', 'seventh');
select tools.session__get('first', 'fifth', 'sixth');
select tools.session__list();
select tools.session__set('first', 'fifth', 'sixth', NULL);
select tools.session__list();
select tools.session__set('first', 'fifth', 'sixth', 'eighth');
select tools.session__list();
select tools.session__clean('delete', 'first');
select tools.session__list();

-- remove all keys form the hash --
select tools.session__reset();
-- make sure it's empty --
select tools.session__list();

DROP SCHEMA tools CASCADE;
DROP LANGUAGE plperl CASCADE;

