camper/test/parse_price.sql

62 lines
2.8 KiB
PL/PgSQL

-- Test parse_price
set client_min_messages to warning;
create extension if not exists pgtap;
reset client_min_messages;
begin;
select plan(44);
set search_path to auth, camper, public;
select has_function('camper', 'parse_price', array ['text', 'integer']);
select function_lang_is('camper', 'parse_price', array ['text', 'integer'], 'plpgsql');
select function_returns('camper', 'parse_price', array ['text', 'integer'], 'integer');
select isnt_definer('camper', 'parse_price', array ['text', 'integer']);
select volatility_is('camper', 'parse_price', array ['text', 'integer'], 'immutable');
select function_privs_are('camper', 'parse_price', array ['text', 'integer'], 'guest', array ['EXECUTE']);
select function_privs_are('camper', 'parse_price', array ['text', 'integer'], 'employee', array ['EXECUTE']);
select function_privs_are('camper', 'parse_price', array ['text', 'integer'], 'admin', array ['EXECUTE']);
select function_privs_are('camper', 'parse_price', array ['text', 'integer'], 'authenticator', array []::text[]);
select is( parse_price('1.1', 2), 110 );
select is( parse_price('1.1', 3), 1100 );
select is( parse_price('0', 2), 0 );
select is( parse_price('0', 3), 0 );
select is( parse_price('-0', 2), 0 );
select is( parse_price('-0', 3), 0 );
select is( parse_price('0.01', 2), 1 );
select is( parse_price('0.001', 3), 1 );
select is( parse_price('-0.01', 2), -1 );
select is( parse_price('-0.001', 3), -1 );
select is( parse_price('0.1', 2), 10 );
select is( parse_price('0.01', 3), 10 );
select is( parse_price('1', 2), 100 );
select is( parse_price('0.1', 3), 100 );
select is( parse_price('10', 2), 1000 );
select is( parse_price('1', 3), 1000 );
select is( parse_price('23.23', 2), 2323 );
select is( parse_price('23.23', 3), 23230 );
select is( parse_price('-23.23', 2), -2323 );
select is( parse_price('-23.23', 3), -23230 );
select throws_ok( $$ select parse_price('234.234', 2) $$ );
select is( parse_price('234.234', 3), 234234 );
select throws_ok( $$ select parse_price('2345.2345', 2) $$ );
select throws_ok( $$ select parse_price('2345.2345', 3) $$ );
select is( parse_price('00000000000000001.100000000000000000000', 2), 110 );
select is( parse_price('00000000000000001.100000000000000000000', 3), 1100 );
select is( parse_price('00000000000000000.100000000000000000000', 2), 10 );
select is( parse_price('00000000000000000.100000000000000000000', 3), 100 );
select is( parse_price('00000000000123456.780000000000000000000', 2), 12345678 );
select is( parse_price('00000000000123456.789000000000000000000', 3), 123456789 );
select throws_ok( $$ select parse_price('1,1', 2) $$ );
select throws_ok( $$ select parse_price('1.1.1', 2) $$ );
select throws_ok( $$ select parse_price('a.b', 2) $$ );
select throws_ok( $$ select parse_price('', 1) $$);
select throws_ok( $$ select parse_price(' ', 3) $$);
select *
from finish();
rollback;