-- Test to_price
set client_min_messages to warning;
create extension if not exists pgtap;
reset client_min_messages;

begin;

select plan(29);

set search_path to camper, public;

select has_function('camper', 'to_price', array ['integer', 'integer']);
select function_lang_is('camper', 'to_price', array ['integer', 'integer'], 'plpgsql');
select function_returns('camper', 'to_price', array ['integer', 'integer'], 'text');
select isnt_definer('camper', 'to_price', array ['integer', 'integer']);
select volatility_is('camper', 'to_price', array ['integer', 'integer'], 'immutable');
select function_privs_are('camper', 'to_price', array ['integer', 'integer'], 'guest', array ['EXECUTE']);
select function_privs_are('camper', 'to_price', array ['integer', 'integer'], 'employee', array ['EXECUTE']);
select function_privs_are('camper', 'to_price', array ['integer', 'integer'], 'admin', array ['EXECUTE']);
select function_privs_are('camper', 'to_price', array ['integer', 'integer'], 'authenticator', array []::text[]);

select is( to_price(0, 2), '0.00' );
select is( to_price(0, 3), '0.000' );
select is( to_price(1, 2), '0.01' );
select is( to_price(1, 3), '0.001' );
select is( to_price(-1, 2), '-0.01' );
select is( to_price(-1, 3), '-0.001' );
select is( to_price(10, 2), '0.10' );
select is( to_price(10, 3), '0.010' );
select is( to_price(100, 2), '1.00' );
select is( to_price(100, 3), '0.100' );
select is( to_price(110, 2), '1.10' );
select is( to_price(1100, 3), '1.100' );
select is( to_price(12345678, 2), '123456.78' );
select is( to_price(12345678, 3), '12345.678' );
select is( to_price(12345678, 4), '1234.5678' );
select is( to_price(12345678, 5), '123.45678' );
select is( to_price(-12345678, 2), '-123456.78' );
select is( to_price(-12345678, 3), '-12345.678' );
select is( to_price(-12345678, 4), '-1234.5678' );
select is( to_price(-12345678, 5), '-123.45678' );

select *
from finish();

rollback;
