cachedTypesTest.js (1731B)
1 describe("Zotero.CachedTypes", function() { 2 describe("Zotero.CharacterSets", function() { 3 describe("#toCanonical()", function() { 4 let toCanon = Zotero.CharacterSets.toCanonical.bind(Zotero.CharacterSets); 5 it("should return charset name given a normalized charset name", function() { 6 assert.equal(toCanon('utf-8'), 'utf-8'); 7 assert.equal(toCanon('windows-1252'), 'windows-1252'); 8 assert.equal(toCanon('utf-16be'), 'utf-16be') 9 }); 10 it("should return charset name given a label", function() { 11 assert.equal(toCanon('unicode-1-1-utf-8'), 'utf-8'); 12 assert.equal(toCanon('ISO-8859-16'), 'iso-8859-16', 'converts compatibility label to name'); 13 assert.equal(toCanon('Chinese'), 'gbk', 'not case sensitive'); 14 assert.equal(toCanon('\ncp1252 '), 'windows-1252', 'ignores leading/trailing whitespace'); 15 }); 16 it("should return big5-hkscs for big5-hkscs", function() { 17 assert.equal(toCanon('big5-hkscs'), 'big5-hkscs'); 18 }); 19 it("should return false for invalid charset", function() { 20 assert.isFalse(toCanon('foo')); 21 }); 22 }); 23 describe("#toLabel()", function() { 24 let toLabel = Zotero.CharacterSets.toLabel.bind(Zotero.CharacterSets); 25 it("should return a compatibility label given a charset name", function() { 26 assert.equal(toLabel('utf-8'), 'UTF-8'); 27 assert.equal(toLabel('gbk'), 'GBK', 'returns GBK in non-mozCompat mode'); 28 assert.equal(toLabel('macintosh'), 'macintosh', 'unspecified compatibility mappings are unchanged'); 29 }); 30 it("should return gbk in mozCompat mode", function() { 31 assert.equal(toLabel('gbk', true), 'gbk'); 32 }); 33 it("should return false for invalid charset", function() { 34 assert.isFalse(toLabel('foo')); 35 }); 36 }); 37 }); 38 });