Debian Codegraph @

closure-library/closure/goog/i18n/mime_test.js

raw
1 // Copyright 2010 The Closure Library Authors. All Rights Reserved.
2 //
3 // Licensed under the Apache License, Version 2.0 (the "License");
4 // you may not use this file except in compliance with the License.
5 // You may obtain a copy of the License at
6 //
7 // http://www.apache.org/licenses/LICENSE-2.0
8 //
9 // Unless required by applicable law or agreed to in writing, software
10 // distributed under the License is distributed on an "AS-IS" BASIS,
11 // WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
12 // See the License for the specific language governing permissions and
13 // limitations under the License.
14
15 goog.provide('goog.i18n.mime.encodeTest');
16 goog.setTestOnly('goog.i18n.mime.encodeTest');
17
18 goog.require('goog.i18n.mime.encode');
19 goog.require('goog.testing.jsunit');
20
21 function testEncodeAllAscii() {
22 // A string holding all the characters that should be encoded unchanged.
23 // Double-quote is doubled to avoid annoying syntax highlighting in emacs,
24 // which doesn't recognize the double-quote as being in a string constant.
25 var identity = '!""#$%&\'()*+,-./0123456789:;<>@ABCDEFGHIJKLMNOPQRSTUVWXYZ' +
26 '[\\]^`abcdefghijklmnopqrstuvwxyz{|}~';
27 assertEquals(identity, goog.i18n.mime.encode(identity));
28 }
29
30 function testEncodeSpecials() {
31 assertEquals('=?UTF-8?Q?=3f=5f=3d_?=', goog.i18n.mime.encode('?_= '));
32 assertEquals(
33 '=?UTF-8?Q?=3f=5f=3d_=22=22?=', goog.i18n.mime.encode('?_= ""', true));
34 }
35
36 function testEncodeUnicode() {
37 // Two-byte UTF-8, plus a special
38 assertEquals(
39 '=?UTF-8?Q?=c2=82=de=a0_dude?=',
40 goog.i18n.mime.encode('\u0082\u07a0 dude'));
41 // Three-byte UTF-8, plus a special
42 assertEquals(
43 '=?UTF-8?Q?=e0=a0=80=ef=bf=bf=3d?=',
44 goog.i18n.mime.encode('\u0800\uffff='));
45 }