[Pkg-javascript-commits] [node-iconv-lite] 57/83: add big5 tests and table;
matthew pideil
mpideil-guest at moszumanska.debian.org
Tue Apr 1 19:56:51 UTC 2014
This is an automated email from the git hooks/post-receive script.
mpideil-guest pushed a commit to branch master
in repository node-iconv-lite.
commit 7c77df1bc64acaa862dd538a248b55b05f95ad70
Author: David Kuo <s50407s at gmail.com>
Date: Sat Mar 16 16:08:58 2013 +0800
add big5 tests and table;
---
encodings/big5.js | 9 +++++++++
encodings/table/big5.js | 1 +
generation/generate-big5-table.js | 25 +++++++++++++++++++++++++
index.js | 1 +
test/big5-test.js | 39 +++++++++++++++++++++++++++++++++++++++
test/big5File.txt | 13 +++++++++++++
6 files changed, 88 insertions(+)
diff --git a/encodings/big5.js b/encodings/big5.js
new file mode 100644
index 0000000..0423d63
--- /dev/null
+++ b/encodings/big5.js
@@ -0,0 +1,9 @@
+var big5Table = require('./table/big5.js');
+module.exports = {
+ 'windows950': 'big5',
+ 'cp950': 'big5',
+ 'big5': {
+ type: 'table',
+ table: big5Table
+ }
+}
diff --git a/encodings/table/big5.js b/encodings/table/big5.js
new file mode 100644
index 0000000..605c72d
--- /dev/null
+++ b/encodings/table/big5.js
@@ -0,0 +1 @@
+module.exports={"33088":19991,"33089":20002,"33090":20012,"33091":20053,"33092":20066,"33093":20106,"33094":20144,"33095":20203,"33096":20205,"33097":20220,"33098":20252,"33099":20362,"33100":20479,"33101":20546,"33102":20560,"33103":20600,"33104":20696,"33105":20702,"33106":20724,"33107":20758,"33108":20810,"33109":20817,"33110":20836,"33111":20842,"33112":20869,"33113":20880,"33114":20893,"33115":20902,"33116":20904,"33117":20905,"33118":20935,"33119":20950,"33120":20955,"33121":20972, [...]
\ No newline at end of file
diff --git a/generation/generate-big5-table.js b/generation/generate-big5-table.js
new file mode 100644
index 0000000..909e433
--- /dev/null
+++ b/generation/generate-big5-table.js
@@ -0,0 +1,25 @@
+var http = require('http');
+var fs = require('fs');
+// BIG5
+var cp950_b2u = {host:'moztw.org',path:'/docs/big5/table/cp950-b2u.txt'},
+ cp950_u2b = {host:'moztw.org',path:'/docs/big5/table/cp950-u2b.txt'},
+ cp950_moz18_b2u = {host:'moztw.org',path:'/docs/big5/table/moz18-b2u.txt'};
+
+http.get(cp950_moz18_b2u, function(res) {
+ var data = '';
+ res.on('data', function(chunk) {
+ data += chunk;
+ });
+ res.on('end', function() {
+ var table = {};
+ data = data.split('\n').slice(1);
+ data.forEach(function(line, idx) {
+ var pair = line.split(' ');
+ var key = parseInt(pair[0]);
+ var val = parseInt(pair[1]);
+ table[key] = val;
+ });
+ fs.createWriteSync('encodings/table/big5.js',
+ 'module.exports = ' + JSON.stringify(table) + ';');
+ });
+});
diff --git a/index.js b/index.js
index 8f60b74..adec5dd 100644
--- a/index.js
+++ b/index.js
@@ -194,6 +194,7 @@ function applyEncodings(encodings) {
applyEncodings(require('./encodings/singlebyte'));
applyEncodings(require('./encodings/gbk'));
+applyEncodings(require('./encodings/big5'));
// Utilities
diff --git a/test/big5-test.js b/test/big5-test.js
new file mode 100644
index 0000000..b3949e6
--- /dev/null
+++ b/test/big5-test.js
@@ -0,0 +1,39 @@
+var vows = require('vows'),
+ fs = require('fs'),
+ assert = require('assert'),
+ iconv = require(__dirname + '/../');
+
+var testString = "中文abc", //unicode contains Big5-code and ascii
+ testStringBig5Buffer = new Buffer([0xa4,0xa4,0xa4,0xe5,0x61,0x62,0x63]);
+
+vows.describe("Big5 tests").addBatch({
+ "Vows is working": function() {},
+ "Return values are of correct types": function() {
+ assert.ok(iconv.toEncoding(testString, "utf8") instanceof Buffer);
+ var s = iconv.fromEncoding(new Buffer(testString), "utf8");
+ assert.strictEqual(Object.prototype.toString.call(s), "[object String]");
+ },
+ "Big5 correctly encoded/decoded": function() {
+ assert.strictEqual(iconv.toEncoding(testString, "big5").toString('binary'), testStringBig5Buffer.toString('binary'));
+ assert.strictEqual(iconv.fromEncoding(testStringBig5Buffer, "big5"), testString);
+ },
+ "cp950 correctly encoded/decoded": function() {
+ assert.strictEqual(iconv.toEncoding(testString, "cp950").toString('binary'), testStringBig5Buffer.toString('binary'));
+ assert.strictEqual(iconv.fromEncoding(testStringBig5Buffer, "cp950"), testString);
+ },
+ "Big5 file read decoded,compare with iconv result": function() {
+ var contentBuffer = fs.readFileSync(__dirname+"/big5File.txt");
+ var str = iconv.fromEncoding(contentBuffer, "big5");
+ var iconvc = new (require('iconv').Iconv)('big5','utf8');
+ assert.strictEqual(iconvc.convert(contentBuffer).toString(), str);
+ },
+ "Big5 correctly decodes and encodes characters · and ×": function() {
+ // Also make a test in Big5 (cp950).
+ // https://github.com/ashtuchkin/iconv-lite/issues/13
+ // Reference: http://www.unicode.org/Public/MAPPINGS/VENDORS/MICSFT/WINDOWS/CP950.TXT
+ var chars = "·×";
+ var gbkChars = new Buffer([0xA1, 0x50, 0xA1, 0xD1]);
+ assert.strictEqual(iconv.toEncoding(chars, "big5").toString('binary'), gbkChars.toString('binary'));
+ assert.strictEqual(iconv.fromEncoding(gbkChars, "big5"), chars)
+ },
+}).export(module)
diff --git a/test/big5File.txt b/test/big5File.txt
new file mode 100644
index 0000000..9c13042
--- /dev/null
+++ b/test/big5File.txt
@@ -0,0 +1,13 @@
+<HTML>
+<HEAD>
+ <TITLE> meta ���Ҫ��ϥΡG����� </TITLE>
+ <meta HTTP-EQUIV="Content-Type" CONTENT="text/html; charset=big5">
+</HEAD>
+<BODY>
+
+�o�O�@���c�餤����I<br>
+(This page uses big5 character set.)<br>
+charset=big5
+
+</BODY>
+</HTML>
\ No newline at end of file
--
Alioth's /usr/local/bin/git-commit-notice on /srv/git.debian.org/git/pkg-javascript/node-iconv-lite.git
More information about the Pkg-javascript-commits
mailing list