mime_test.js 1.7 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445
  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. goog.provide('goog.i18n.mime.encodeTest');
  15. goog.setTestOnly('goog.i18n.mime.encodeTest');
  16. goog.require('goog.i18n.mime.encode');
  17. goog.require('goog.testing.jsunit');
  18. function testEncodeAllAscii() {
  19. // A string holding all the characters that should be encoded unchanged.
  20. // Double-quote is doubled to avoid annoying syntax highlighting in emacs,
  21. // which doesn't recognize the double-quote as being in a string constant.
  22. var identity = '!""#$%&\'()*+,-./0123456789:;<>@ABCDEFGHIJKLMNOPQRSTUVWXYZ' +
  23. '[\\]^`abcdefghijklmnopqrstuvwxyz{|}~';
  24. assertEquals(identity, goog.i18n.mime.encode(identity));
  25. }
  26. function testEncodeSpecials() {
  27. assertEquals('=?UTF-8?Q?=3f=5f=3d_?=', goog.i18n.mime.encode('?_= '));
  28. assertEquals(
  29. '=?UTF-8?Q?=3f=5f=3d_=22=22?=', goog.i18n.mime.encode('?_= ""', true));
  30. }
  31. function testEncodeUnicode() {
  32. // Two-byte UTF-8, plus a special
  33. assertEquals(
  34. '=?UTF-8?Q?=c2=82=de=a0_dude?=',
  35. goog.i18n.mime.encode('\u0082\u07a0 dude'));
  36. // Three-byte UTF-8, plus a special
  37. assertEquals(
  38. '=?UTF-8?Q?=e0=a0=80=ef=bf=bf=3d?=',
  39. goog.i18n.mime.encode('\u0800\uffff='));
  40. }