1'use strict'; 2 3var Iconv = require('../lib/iconv-loader'); 4var encoding = require('../lib/encoding'); 5 6exports['General tests'] = { 7 8 'Iconv is available': function (test) { 9 test.ok(Iconv); 10 test.done(); 11 }, 12 13 'From UTF-8 to Latin_1 with Iconv': function (test) { 14 var input = 'ÕÄÖÜ', 15 expected = new Buffer([0xd5, 0xc4, 0xd6, 0xdc]); 16 test.deepEqual(encoding.convert(input, 'latin1'), expected); 17 test.done(); 18 }, 19 20 'From Latin_1 to UTF-8 with Iconv': function (test) { 21 var input = new Buffer([0xd5, 0xc4, 0xd6, 0xdc]), 22 expected = 'ÕÄÖÜ'; 23 test.deepEqual(encoding.convert(input, 'utf-8', 'latin1').toString(), expected); 24 test.done(); 25 }, 26 27 'From UTF-8 to UTF-8 with Iconv': function (test) { 28 var input = 'ÕÄÖÜ', 29 expected = new Buffer('ÕÄÖÜ'); 30 test.deepEqual(encoding.convert(input, 'utf-8', 'utf-8'), expected); 31 test.done(); 32 }, 33 34 'From Latin_13 to Latin_15 with Iconv': function (test) { 35 var input = new Buffer([0xd5, 0xc4, 0xd6, 0xdc, 0xd0]), 36 expected = new Buffer([0xd5, 0xc4, 0xd6, 0xdc, 0xA6]); 37 test.deepEqual(encoding.convert(input, 'latin_15', 'latin13'), expected); 38 test.done(); 39 }, 40 41 'From ISO-2022-JP to UTF-8 with Iconv': function (test) { 42 var input = new Buffer('GyRCM1g5OzU7PVEwdzgmPSQ4IUYkMnFKczlwGyhC', 'base64'), 43 expected = new Buffer('5a2m5qCh5oqA6KGT5ZOh56CU5L+u5qSc6KiO5Lya5aCx5ZGK', 'base64'); 44 test.deepEqual(encoding.convert(input, 'utf-8', 'ISO-2022-JP'), expected); 45 test.done(); 46 }, 47 48 'From UTF-8 to Latin_1 with iconv-lite': function (test) { 49 var input = 'ÕÄÖÜ', 50 expected = new Buffer([0xd5, 0xc4, 0xd6, 0xdc]); 51 test.deepEqual(encoding.convert(input, 'latin1', false, true), expected); 52 test.done(); 53 }, 54 55 'From Latin_1 to UTF-8 with iconv-lite': function (test) { 56 var input = new Buffer([0xd5, 0xc4, 0xd6, 0xdc]), 57 expected = 'ÕÄÖÜ'; 58 test.deepEqual(encoding.convert(input, 'utf-8', 'latin1', true).toString(), expected); 59 test.done(); 60 }, 61 62 'From UTF-8 to UTF-8 with iconv-lite': function (test) { 63 var input = 'ÕÄÖÜ', 64 expected = new Buffer('ÕÄÖÜ'); 65 test.deepEqual(encoding.convert(input, 'utf-8', 'utf-8', true), expected); 66 test.done(); 67 }, 68 69 'From Latin_13 to Latin_15 with iconv-lite': function (test) { 70 var input = new Buffer([0xd5, 0xc4, 0xd6, 0xdc, 0xd0]), 71 expected = new Buffer([0xd5, 0xc4, 0xd6, 0xdc, 0xA6]); 72 test.deepEqual(encoding.convert(input, 'latin_15', 'latin13', true), expected); 73 test.done(); 74 } 75}; 76