charlistdecompressor_test.js 1.8 KB

12345678910111213141516171819202122232425262728293031323334353637383940414243444546474849505152535455565758
  1. // Copyright 2009 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.CharListDecompressorTest');
  15. goog.setTestOnly('goog.i18n.CharListDecompressorTest');
  16. goog.require('goog.i18n.CharListDecompressor');
  17. goog.require('goog.testing.jsunit');
  18. var decompressor = new goog.i18n.CharListDecompressor();
  19. function testBuildCharMap() {
  20. assertEquals(0, decompressor.charMap_['0']);
  21. assertEquals(10, decompressor.charMap_['A']);
  22. assertEquals(87, decompressor.charMap_['}']);
  23. }
  24. function testGetCodeAt() {
  25. var code = decompressor.getCodeAt_('321', 1, 2);
  26. assertEquals(90, code);
  27. }
  28. function testAddCharsForType0() {
  29. var list = ['a'];
  30. var lastcode = decompressor.addChars_(list, 97, 0, 0);
  31. assertArrayEquals(['a', 'b'], list);
  32. assertEquals(98, lastcode);
  33. }
  34. function testAddCharsForType1() {
  35. var list = ['a'];
  36. var lastcode = decompressor.addChars_(list, 98, 0, 1);
  37. assertArrayEquals(['a', 'a'], list);
  38. assertEquals(97, lastcode);
  39. }
  40. function testAddCharsForType2() {
  41. var list = ['a'];
  42. var lastcode = decompressor.addChars_(list, 97, 1, 2);
  43. assertArrayEquals(['a', 'b', 'c'], list);
  44. assertEquals(99, lastcode);
  45. }
  46. function testToCharList() {
  47. var list = decompressor.toCharList('%812E<E'); // a, x-z, p-r
  48. assertArrayEquals(['a', 'x', 'y', 'z', 'p', 'q', 'r'], list);
  49. }