Skip to content

HTTPS clone URL

Subversion checkout URL

You can clone with HTTPS or Subversion.

Download ZIP
Fetching contributors…

Cannot retrieve contributors at this time

224 lines (204 sloc) 6.384 kb
BEGIN;
SELECT plan(121);
--SELECT * FROM no_plan();
-- Test the label data type.
SELECT has_type('label');
SELECT is( 'foo'::label, 'FOO'::label, 'labels should be case-insensitive' );
SELECT is( NULL::label, NULL, 'labels should be NULLable' );
SELECT lives_ok( 'SELECT ''foo''::label', '"foo" is a valid label' );
SELECT lives_ok( 'SELECT ''bar''::label', '"bar" is a valid label' );
SELECT lives_ok( 'SELECT ''FOO''::label', '"FOO" is a valid label' );
SELECT lives_ok( 'SELECT ''b1''::label', '"b1" is a valid label' );
SELECT lives_ok( 'SELECT ''b-a''::label', '"b-a" is a valid label' );
SELECT lives_ok( 'SELECT ''ba''::label', '"ba" is a valid label' );
SELECT lives_ok( 'SELECT ''a''::label', '"a" is a valid label' );
SELECT lives_ok( 'SELECT ''b-1a''::label', '"b-1a" is a valid label' );
SELECT lives_ok( 'SELECT ''b----a''::label', '"b----a" is a valid label' );
SELECT throws_ok(
'SELECT ''2''::label',
'23514',
'value for domain label violates check constraint "label_check"',
'"2" is not a valid label'
);
SELECT throws_ok(
'SELECT ''b-''::label',
'23514',
'value for domain label violates check constraint "label_check"',
'"b-" is not a valid label'
);
SELECT throws_ok(
'SELECT ''-''::label',
'23514',
'value for domain label violates check constraint "label_check"',
'"-" is not a valid label'
);
SELECT throws_ok(
'SELECT ''f.b''::label',
'23514',
'value for domain label violates check constraint "label_check"',
'"f.b" is not a valid label'
);
SELECT throws_ok(
'SELECT ''f,b''::label',
'23514',
'value for domain label violates check constraint "label_check"',
'"f,b" is not a valid label'
);
SELECT throws_ok(
'SELECT ''Bjørn''::label',
'23514',
'value for domain label violates check constraint "label_check"',
'Non-ASCII characters invalid in labels'
);
-- Test the timezone data type.
SELECT is( NULL::timezone, NULL, 'time zones should be NULLable' );
SELECT lives_ok(
'SELECT ''' || name || '''::timezone',
name || ' should be a valid time zone'
)
FROM (SELECT name FROM pg_timezone_names ORDER BY RANDOM() LIMIT 50) AS tz(name);
SELECT is(
'Zulu'::timezone,
'ZULU'::timezone,
'TZs should be case-insensitive'
);
SELECT throws_ok(
'SELECT ''FOO''::timezone',
'23514',
'value for domain timezone violates check constraint "timezone_check"',
'Should die for invalid TZ "FOO"'
);
SELECT throws_ok(
'SELECT ''BAR''::timezone',
'23514',
'value for domain timezone violates check constraint "timezone_check"',
'Should die for invalid TZ "BAR"'
);
SELECT throws_ok(
'SELECT ''America/Los_Angelos''::timezone',
'23514',
'value for domain timezone violates check constraint "timezone_check"',
'Should die for invalid TZ "America/Los_Angelos"'
);
-- Test the email data type.
SELECT is( NULL::email, NULL, 'emails should be NULLable' );
SELECT lives_ok(
'SELECT ''foo@bar.com''::email',
'"foo@bar.com" should be a valid email'
);
SELECT lives_ok(
'SELECT ''foo@bar.info''::email',
'"foo@bar.info" should be a valid email'
);
SELECT throws_ok(
'SELECT ''foo.info''::email',
'23514',
'value for domain email violates check constraint "email_check"',
'"foo.info" should not be a valid email'
);
SELECT is(
'foo@bar.com'::email,
'FOO@BAR.COM'::email,
'Emails should be case-insensitive'
);
-- Test the uri data type.
SELECT is( NULL::uri, NULL, 'URIs should be NULLable' );
SELECT lives_ok(
'SELECT ''http://foo.com''::uri',
'foo.com should be a valid HTTP URI'
);
SELECT lives_ok(
'SELECT ''https://foo.com''::uri',
'foo.com should be a valid HTTPS URI'
);
SELECT lives_ok(
'SELECT ''http://foo.com/?id=1''::uri',
'foo.com?id=1 should be a valid URI'
);
SELECT lives_ok(
'SELECT ''http://w3.org/path%20with%20spaces.html''::uri',
'URI with encoded spaces should be valid'
);
SELECT lives_ok(
'SELECT ''http://192.168.0.1/''::uri',
'An IP address URL is a valid URI'
);
SELECT lives_ok(
'SELECT ''mailto:pgxn@kineticode.com''::uri',
'A mailto: URL is a valid URI'
);
SELECT lives_ok(
'SELECT ''''::uri',
'An empty string should be allowed as a URI'
);
SELECT throws_ok(
'SELECT ''hey me://foo.com''::uri',
'23514',
'value for domain uri violates check constraint "uri_check"',
'A URI witn an invalid scheme should not be valid'
);
SELECT throws_ok(
'SELECT ''http://w3.org/path with spaces.html''::uri',
'23514',
'value for domain uri violates check constraint "uri_check"',
'URI with unencoded spaces should not be valid'
);
-- Test the term data type.
SELECT has_type('term');
SELECT is( 'foo'::term, 'FOO'::term, 'terms should be case-insensitive' );
SELECT is( NULL::term, NULL, 'terms should be NULLable' );
SELECT throws_like(
'SELECT ' || quote_literal(bad) || '::term',
'%"term_check"%',
'Should get invalid term exception for "' || bad || '"'
) FROM unnest(ARRAY[
'foo/bar', -- slash
'foo\bar', -- backslash
'foo bar', -- tab
'f', -- length
E'foo\nbar', -- newline
E'foo\rbar', -- return
E'foo\fbar', -- feed
E'foo\x0abar' -- unprintable
]) AS bad;
SELECT lives_ok(
'SELECT ' || quote_literal(good) || '::term',
'"' || good || '" should be a valid term'
) FROM unnest(ARRAY[
'foo',
'foo,bar',
'foo9bar',
'foo**^%#Wbar',
E'“fooabar”'
]) AS good;
-- Test the tag data type.
SELECT has_type('tag');
SELECT is( 'foo'::tag, 'FOO'::tag, 'tags should be case-insensitive' );
SELECT is( NULL::tag, NULL, 'tags should be NULLable' );
SELECT throws_like(
'SELECT ' || quote_literal(bad) || '::tag',
'%"tag_check"%',
'Should get invalid tag exception for "' || bad || '"'
) FROM unnest(ARRAY[
'foo/bar', -- slash
'foo\bar', -- backslash
'foo bar', -- tab
E'foo\nbar', -- newline
E'foo\rbar', -- return
E'foo\fbar', -- feed
E'foo\x0abar', -- unprintable
repeat('x', 257) -- too long
]) AS bad;
SELECT lives_ok(
'SELECT ' || quote_literal(good) || '::tag',
'"' || good || '" should be a valid tag'
) FROM unnest(ARRAY[
'foo',
'foo bar',
'foo,bar',
'foo9bar',
'foo**^%#Wbar',
E'“fooabar”'
]) AS good;
SELECT * FROM finish();
ROLLBACK;
Jump to Line
Something went wrong with that request. Please try again.