forked from wttw/pgmime
-
Notifications
You must be signed in to change notification settings - Fork 0
/
test.sql
53 lines (43 loc) · 2.17 KB
/
test.sql
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
-- -*-sql-*-
\unset ECHO
\set QUIET 1
\pset format unaligned
\pset tuples_only true
\pset pager off
\set ON_ERROR_ROLLBACK 1
\set ON_ERROR_STOP true
begin;
\i pgtap.sql
select plan(25);
-- Test vectors stolen from https://golang.org/src/mime/encodedword_test.go
create or replace function _is(text, text) returns text as $$select is($1, $2, 'decode: ' || $2)$$ language sql;
select _is(decode_rfc_2047(E'=?UTF-8?Q?=C2=A1Hola,_se=C3=B1or!?='), '¡Hola, señor!');
select _is(decode_rfc_2047(E'=?UTF-8?Q?Fran=C3=A7ois-J=C3=A9r=C3=B4me?='), 'François-Jérôme');
select _is(decode_rfc_2047(E'=?UTF-8?q?ascii?='), 'ascii');
select _is(decode_rfc_2047(E'=?utf-8?B?QW5kcsOp?='), 'André');
select _is(decode_rfc_2047(E'=?_ISO-8859-1?Q?Rapha=EBl_Dupont?='), 'Raphaël Dupont');
select _is(decode_rfc_2047(E'Jean'), 'Jean');
select _is(decode_rfc_2047(E'=?utf-8?b?IkFudG9uaW8gSm9zw6kiIDxqb3NlQGV4YW1wbGUub3JnPg==?='), '"Antonio José" <[email protected]>');
select _is(decode_rfc_2047(E'=?UTF-8?A?Test?='), '=?UTF-8?A?Test?=');
select _is(decode_rfc_2047(E'=?UTF-8?Q?A=B?='), '=?UTF-8?Q?A=B?=');
select _is(decode_rfc_2047(E'=?UTF-8?Q?=A?='), '=?UTF-8?Q?=A?=');
select _is(decode_rfc_2047(E'=?UTF-8?A?A?='), '=?UTF-8?A?A?=');
-- Incomplete words
select _is(decode_rfc_2047(E'=?'), '=?');
select _is(decode_rfc_2047(E'=?UTF-8?'), '=?UTF-8?');
select _is(decode_rfc_2047(E'=?UTF-8?='), '=?UTF-8?=');
select _is(decode_rfc_2047(E'=?UTF-8?Q'), '=?UTF-8?Q');
select _is(decode_rfc_2047(E'=?UTF-8?Q?'), '=?UTF-8?Q?');
select _is(decode_rfc_2047(E'=?UTF-8?Q?='), '=?UTF-8?Q?=');
select _is(decode_rfc_2047(E'=?UTF-8?Q?A'), '=?UTF-8?Q?A');
select _is(decode_rfc_2047(E'=?UTF-8?Q?A?'), '=?UTF-8?Q?A?');
-- Tests from RFC 2047
select _is(decode_rfc_2047(E'=?_ISO-8859-1?Q?a?='), 'a');
select _is(decode_rfc_2047(E'=?_ISO-8859-1?Q?a?= b'), 'a b');
select _is(decode_rfc_2047(E'=?_ISO-8859-1?Q?a?= =?_ISO-8859-1?Q?b?='), 'ab');
select _is(decode_rfc_2047(E'=?_ISO-8859-1?Q?a?= =?_ISO-8859-1?Q?b?='), 'ab');
select _is(decode_rfc_2047(E'=?_ISO-8859-1?Q?a?= \r\n\t =?_ISO-8859-1?Q?b?='), 'ab');
select _is(decode_rfc_2047(E'=?_ISO-8859-1?Q?a_b?='), 'a b');
drop function if exists _is(text, text);
select * from finish();
rollback;