major style changes - tests

This commit is contained in:
Dmitry Shirokov 2013-11-22 15:40:19 +11:00
parent 1a7da87ec4
commit 17aebe7b28
6 changed files with 196 additions and 201 deletions

View File

@ -1,30 +1,30 @@
var assert = require('assert'), var assert = require('assert'),
chardet = require('../'), chardet = require('../'),
fs = require('fs'); fs = require('fs');
describe('chardet', function() { describe('chardet', function() {
var path = __dirname + '/data/encodings/utf8'; var path = __dirname + '/data/encodings/utf8';
describe('#detect', function() { describe('#detect', function() {
it('should detect encoding', function() { it('should detect encoding', function() {
assert.equal(chardet.detect(fs.readFileSync(path)), 'UTF-8'); assert.equal(chardet.detect(fs.readFileSync(path)), 'UTF-8');
});
}); });
});
describe('#detectFile', function() { describe('#detectFile', function() {
it('should detect encoding', function(done) { it('should detect encoding', function(done) {
chardet.detectFile(path, function(err, res) { chardet.detectFile(path, function(err, res) {
assert.equal(err, null); assert.equal(err, null);
assert.equal(res, 'UTF-8'); assert.equal(res, 'UTF-8');
done(); done();
}); });
});
}); });
});
describe('#detectFileSync', function() { describe('#detectFileSync', function() {
it('should detect encoding', function() { it('should detect encoding', function() {
assert.equal(chardet.detectFileSync(path), 'UTF-8'); assert.equal(chardet.detectFileSync(path), 'UTF-8');
});
}); });
}); });
});

View File

@ -1,29 +1,28 @@
var assert = require('assert'), var assert = require('assert'),
chardet = require('../../'); chardet = require('../../');
describe('ISO-2022', function() { describe('ISO-2022', function() {
var base = __dirname + '/../data/encodings'; var base = __dirname + '/../data/encodings';
it('should return ISO-2022-JP', function() { it('should return ISO-2022-JP', function() {
assert.equal( assert.equal(
chardet.detectFileSync(base + '/iso2022jp'), chardet.detectFileSync(base + '/iso2022jp'),
'ISO-2022-JP' 'ISO-2022-JP'
); );
}); });
it('should return ISO-2022-KR', function() { it('should return ISO-2022-KR', function() {
assert.equal( assert.equal(
chardet.detectFileSync(base + '/iso2022kr'), chardet.detectFileSync(base + '/iso2022kr'),
'ISO-2022-KR' 'ISO-2022-KR'
); );
}); });
it('should return ISO-2022-CN', function() { it('should return ISO-2022-CN', function() {
assert.equal( assert.equal(
chardet.detectFileSync(base + '/iso2022cn'), chardet.detectFileSync(base + '/iso2022cn'),
'ISO-2022-CN' 'ISO-2022-CN'
); );
}); });
}); });

View File

@ -1,44 +1,43 @@
var assert = require('assert'), var assert = require('assert'),
chardet = require('../../'); chardet = require('../../');
describe('Multybyte Character Sets', function() { describe('Multybyte Character Sets', function() {
var base = __dirname + '/../data/encodings'; var base = __dirname + '/../data/encodings';
it('should return SHIFT-JIS', function() { it('should return SHIFT-JIS', function() {
assert.equal( assert.equal(
chardet.detectFileSync(base + '/shiftjis'), chardet.detectFileSync(base + '/shiftjis'),
'Shift-JIS' 'Shift-JIS'
); );
}); });
it('should return GB18030', function() { it('should return GB18030', function() {
assert.equal( assert.equal(
chardet.detectFileSync(base + '/gb18030'), chardet.detectFileSync(base + '/gb18030'),
'GB18030' 'GB18030'
); );
}); });
it('should return Big5', function() { it('should return Big5', function() {
assert.equal( assert.equal(
chardet.detectFileSync(base + '/big5'), chardet.detectFileSync(base + '/big5'),
'Big5' 'Big5'
); );
}); });
it('should return EUC-JP', function() { it('should return EUC-JP', function() {
assert.equal( assert.equal(
chardet.detectFileSync(base + '/euc_jp'), chardet.detectFileSync(base + '/euc_jp'),
'EUC-JP' 'EUC-JP'
); );
}); });
it('should return EUC-KR', function() { it('should return EUC-KR', function() {
assert.equal( assert.equal(
chardet.detectFileSync(base + '/euc_kr'), chardet.detectFileSync(base + '/euc_kr'),
'EUC-KR' 'EUC-KR'
); );
}); });
}); });

View File

@ -1,112 +1,111 @@
var assert = require('assert'), var assert = require('assert'),
chardet = require('../../'); chardet = require('../../');
describe('Singlebyte Character Sets', function() { describe('Singlebyte Character Sets', function() {
var base = __dirname + '/../data/encodings'; var base = __dirname + '/../data/encodings';
it('should return ISO-8859-1 (English)', function() { it('should return ISO-8859-1 (English)', function() {
assert.equal( assert.equal(
chardet.detectFileSync(base + '/iso88591_en'), 'ISO-8859-1' chardet.detectFileSync(base + '/iso88591_en'), 'ISO-8859-1'
); );
}); });
it('should return ISO-8859-2 (Czech)', function() { it('should return ISO-8859-2 (Czech)', function() {
assert.equal( assert.equal(
chardet.detectFileSync(base + '/iso88592_cs'), 'ISO-8859-2' chardet.detectFileSync(base + '/iso88592_cs'), 'ISO-8859-2'
); );
}); });
it('should return ISO-8859-3'); it('should return ISO-8859-3');
it('should return ISO-8859-4'); it('should return ISO-8859-4');
it('should return ISO-8859-5 (Russian)', function() { it('should return ISO-8859-5 (Russian)', function() {
assert.equal( assert.equal(
chardet.detectFileSync(base + '/iso88595_ru'), 'ISO-8859-5' chardet.detectFileSync(base + '/iso88595_ru'), 'ISO-8859-5'
); );
}); });
it('should return ISO-8859-6 (Arabic)', function() { it('should return ISO-8859-6 (Arabic)', function() {
assert.equal( assert.equal(
chardet.detectFileSync(base + '/iso88596_ar'), 'ISO-8859-6' chardet.detectFileSync(base + '/iso88596_ar'), 'ISO-8859-6'
); );
}); });
it('should return ISO-8859-7 (Greek)', function() { it('should return ISO-8859-7 (Greek)', function() {
assert.equal( assert.equal(
chardet.detectFileSync(base + '/iso88597_el'), 'ISO-8859-7' chardet.detectFileSync(base + '/iso88597_el'), 'ISO-8859-7'
); );
}); });
it('should return ISO-8859-8 (Hebrew)', function() { it('should return ISO-8859-8 (Hebrew)', function() {
assert.equal( assert.equal(
chardet.detectFileSync(base + '/iso88598_he'), 'ISO-8859-8' chardet.detectFileSync(base + '/iso88598_he'), 'ISO-8859-8'
); );
}); });
it('should return ISO-8859-9 (Turkish)', function() { it('should return ISO-8859-9 (Turkish)', function() {
assert.equal( assert.equal(
chardet.detectFileSync(base + '/iso88599_tr'), 'ISO-8859-9' chardet.detectFileSync(base + '/iso88599_tr'), 'ISO-8859-9'
); );
}); });
it('should return ISO-8859-10'); it('should return ISO-8859-10');
it('should return ISO-8859-11'); it('should return ISO-8859-11');
// iso-8859-12 is abandoned // iso-8859-12 is abandoned
it('should return ISO-8859-13'); it('should return ISO-8859-13');
it('should return ISO-8859-14'); it('should return ISO-8859-14');
it('should return ISO-8859-15'); it('should return ISO-8859-15');
it('should return ISO-8859-16'); it('should return ISO-8859-16');
it('should return windows-1250 (Czech)', function() { it('should return windows-1250 (Czech)', function() {
assert.equal( assert.equal(
chardet.detectFileSync(base + '/windows_1250'), 'windows-1250' chardet.detectFileSync(base + '/windows_1250'), 'windows-1250'
); );
}); });
it('should return windows-1251 (Russian)', function() { it('should return windows-1251 (Russian)', function() {
assert.equal( assert.equal(
chardet.detectFileSync(base + '/windows_1251'), 'windows-1251' chardet.detectFileSync(base + '/windows_1251'), 'windows-1251'
); );
}); });
it('should return windows-1252 (English)', function() { it('should return windows-1252 (English)', function() {
assert.equal( assert.equal(
chardet.detectFileSync(base + '/windows_1252'), 'windows-1252' chardet.detectFileSync(base + '/windows_1252'), 'windows-1252'
); );
}); });
it('should return windows-1253 (Greek)', function() { it('should return windows-1253 (Greek)', function() {
assert.equal( assert.equal(
chardet.detectFileSync(base + '/windows_1253'), 'windows-1253' chardet.detectFileSync(base + '/windows_1253'), 'windows-1253'
); );
}); });
it('should return windows-1254 (Turkish)', function() { it('should return windows-1254 (Turkish)', function() {
assert.equal( assert.equal(
chardet.detectFileSync(base + '/windows_1254'), 'windows-1254' chardet.detectFileSync(base + '/windows_1254'), 'windows-1254'
); );
}); });
it('should return windows-1255 (Hebrew)', function() { it('should return windows-1255 (Hebrew)', function() {
assert.equal( assert.equal(
chardet.detectFileSync(base + '/windows_1255'), 'windows-1255' chardet.detectFileSync(base + '/windows_1255'), 'windows-1255'
); );
}); });
it('should return windows-1256 (Arabic)', function() { it('should return windows-1256 (Arabic)', function() {
assert.equal( assert.equal(
chardet.detectFileSync(base + '/windows_1256'), 'windows-1256' chardet.detectFileSync(base + '/windows_1256'), 'windows-1256'
); );
}); });
it('should return KOI8-R (Russian)', function() { it('should return KOI8-R (Russian)', function() {
assert.equal( assert.equal(
chardet.detectFileSync(base + '/koi8r'), 'KOI8-R' chardet.detectFileSync(base + '/koi8r'), 'KOI8-R'
); );
}); });
}); });

View File

@ -1,36 +1,35 @@
var assert = require('assert'), var assert = require('assert'),
chardet = require('../../'); chardet = require('../../');
describe('Unicode', function() { describe('Unicode', function() {
var base = __dirname + '/../data/encodings'; var base = __dirname + '/../data/encodings';
it('should return UTF-16LE', function() { it('should return UTF-16LE', function() {
assert.equal( assert.equal(
chardet.detectFileSync(base + '/utf16le'), chardet.detectFileSync(base + '/utf16le'),
'UTF-16LE' 'UTF-16LE'
); );
}); });
it('should return UTF-16BE', function() { it('should return UTF-16BE', function() {
assert.equal( assert.equal(
chardet.detectFileSync(base + '/utf16be'), chardet.detectFileSync(base + '/utf16be'),
'UTF-16BE' 'UTF-16BE'
); );
}); });
it('should return UTF-32LE', function() { it('should return UTF-32LE', function() {
assert.equal( assert.equal(
chardet.detectFileSync(base + '/utf32le'), chardet.detectFileSync(base + '/utf32le'),
'UTF-32LE' 'UTF-32LE'
); );
}); });
it('should return UTF-32BE', function() { it('should return UTF-32BE', function() {
assert.equal( assert.equal(
chardet.detectFileSync(base + '/utf32be'), chardet.detectFileSync(base + '/utf32be'),
'UTF-32BE' 'UTF-32BE'
); );
}); });
}); });

View File

@ -1,12 +1,11 @@
var assert = require('assert'), var assert = require('assert'),
chardet = require('../../'); chardet = require('../../');
describe('UTF-8', function() { describe('UTF-8', function() {
it('should return UTF-8', function() { it('should return UTF-8', function() {
assert.equal( assert.equal(
chardet.detectFileSync(__dirname + '/../data/encodings/utf8'), chardet.detectFileSync(__dirname + '/../data/encodings/utf8'),
'UTF-8' 'UTF-8'
); );
}); });
}); });