Debian Codegraph @

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

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