camper/test/media_type.sql

57 lines
1.6 KiB
PL/PgSQL

-- Test media_type
set client_min_messages to warning;
create extension if not exists pgtap;
reset client_min_messages;
begin;
select plan(14);
set search_path to camper, public;
select has_domain('media_type');
select domain_type_is('media_type', 'text');
select lives_ok($$ select 'text/plain'::media_type $$, 'Should accept valid media types');
select lives_ok($$ select 'application/octet-stream'::media_type $$, 'Should accept media types with dashes');
select lives_ok($$ select 'application/x-abiword'::media_type $$, 'Should accept non-standard media types');
select lives_ok($$ select 'application/vnd.openxmlformats-officedocument.wordprocessingml.document'::media_type $$, 'Should accept idiotic, but valid media types');
select lives_ok($$ select 'application/vnd.mozilla.xul+xml'::media_type $$, 'Should accept XML subtypes');
select lives_ok($$ select 'text/html;charset=utf-8'::media_type $$, 'Should accept media types with unquoted parameters');
select lives_ok($$ select 'text/html; charset="utf-8"'::media_type $$, 'Should accept media types with quoted parameters');
select throws_ok(
$$ SELECT ''::media_type $$,
23514, null,
'Should reject empty strings'
);
select throws_ok(
$$ SELECT 'text plain'::media_type $$,
23514, null,
'Should reject types without separator'
);
select throws_ok(
$$ SELECT 'text/'::media_type $$,
23514, null,
'Should reject types without subtype'
);
select throws_ok(
$$ SELECT '/plain'::media_type $$,
23514, null,
'Should reject types without subtype'
);
select throws_ok(
$$ SELECT 'invalid/type'::media_type $$,
23514, null,
'Should reject imaginary types'
);
select *
from finish();
rollback;