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

begin;

select plan(18);

set search_path to numerus, public;

select has_domain('bic');
select domain_type_is('bic', 'text');

select lives_ok($$ select 'BBVAESMM'::bic $$, 'Should be able to cast strings without department to bic');
select lives_ok($$ select 'LOYDCHGGZCH'::bic $$, 'Should be able to cast strings with department to bic');

select throws_ok(
	$$ SELECT 'loydchggzch'::bic $$,
	23514, null,
	'Should reject BIC with lowercase'
);

select throws_ok(
	$$ SELECT ' LOYDCHGGZCH'::bic $$,
	23514, null,
	'Should reject BIC with heading spaces'
);

select throws_ok(
	$$ SELECT 'LOYDCHGGZCH '::bic $$,
	23514, null,
	'Should reject BIC with trailing spaces'
);

select throws_ok(
	$$ SELECT 'LOYD CH GG ZCH'::bic $$,
	23514, null,
	'Should reject BIC with middle spaces'
);

select throws_ok(
	$$ SELECT '1OYDCHGGZCH'::bic $$,
	23514, null,
	'Should reject BIC with numbers at first position'
);

select throws_ok(
	$$ SELECT 'L2YDCHGGZCH'::bic $$,
	23514, null,
	'Should reject BIC with numbers at second position'
);

select throws_ok(
	$$ SELECT 'LO3DCHGGZCH'::bic $$,
	23514, null,
	'Should reject BIC with numbers at third position'
);

select throws_ok(
	$$ SELECT 'LOY4CHGGZCH'::bic $$,
	23514, null,
	'Should reject BIC with numbers at fourth position'
);

select throws_ok(
	$$ SELECT 'LOYD5HGGZCH'::bic $$,
	23514, null,
	'Should reject BIC with numbers at fifth position'
);

select throws_ok(
	$$ SELECT 'LOYDC6GGZCH'::bic $$,
	23514, null,
	'Should reject BIC with numbers at sixth position'
);

select throws_ok(
	$$ SELECT 'LOYDCHG'::bic $$,
	23514, null,
	'Should reject BIC with 7 characters'
);

select throws_ok(
	$$ SELECT 'LOYDCHGGZ'::bic $$,
	23514, null,
	'Should reject BIC with 9 characters'
);

select throws_ok(
	$$ SELECT 'LOYDCHGGZC'::bic $$,
	23514, null,
	'Should reject BIC with 10 characters'
);

select throws_ok(
	$$ SELECT 'LOYDCHGGZCHH'::bic $$,
	23514, null,
	'Should reject BIC with 12 characters'
);


select *
from finish();

rollback;
