Permalink
Browse files

Merge pull request #5 from stagas/master

Added greek encodings
  • Loading branch information...
2 parents 5a12ae8 + 24eb810 commit 20f152de4fb80819ead974288cc46ce040c224ac @ashtuchkin committed Mar 9, 2012
Showing with 111 additions and 0 deletions.
  1. +32 −0 encodings/greek.js
  2. +79 −0 test/greek-test.js
View
@@ -0,0 +1,32 @@
+// Greek encodings
+
+module.exports = {
+ "windows1253": {
+ type: "singlebyte",
+ chars: "\u20ac\ufffd\u201a\u0192\u201e\u2026\u2020\u2021\ufffd\u2030\ufffd\u2039\ufffd\ufffd\ufffd\ufffd\ufffd\u2018\u2019\u201c\u201d\u2022\u2013\u2014\ufffd\u2122\ufffd\u203a\ufffd\ufffd\ufffd\ufffd\xa0\u0385\u0386\xa3\xa4\xa5\xa6\xa7\xa8\xa9\ufffd\xab\xac\xad\xae\u2015\xb0\xb1\xb2\xb3\u0384\xb5\xb6\xb7\u0388\u0389\u038a\xbb\u038c\xbd\u038e\u038f\u0390\u0391\u0392\u0393\u0394\u0395\u0396\u0397\u0398\u0399\u039a\u039b\u039c\u039d\u039e\u039f\u03a0\u03a1\ufffd\u03a3\u03a4\u03a5\u03a6\u03a7\u03a8\u03a9\u03aa\u03ab\u03ac\u03ad\u03ae\u03af\u03b0\u03b1\u03b2\u03b3\u03b4\u03b5\u03b6\u03b7\u03b8\u03b9\u03ba\u03bb\u03bc\u03bd\u03be\u03bf\u03c0\u03c1\u03c2\u03c3\u03c4\u03c5\u03c6\u03c7\u03c8\u03c9\u03ca\u03cb\u03cc\u03cd\u03ce\ufffd"
+ },
+ "windows-1253": "windows1253",
+ "win-1253": "windows1253",
+ "win1253": "windows1253",
+ "cp1253": "windows1253",
+ "cp-1253": "windows1253",
+ 1253: "windows1253",
+
+ "iso88597": {
+ type: "singlebyte",
+ chars: "\x80\x81\x82\x83\x84\x85\x86\x87\x88\x89\x8a\x8b\x8c\x8d\x8e\x8f\x90\x91\x92\x93\x94\x95\x96\x97\x98\x99\x9a\x9b\x9c\x9d\x9e\x9f\xa0\u2018\u2019\xa3\u20ac\u20af\xa6\xa7\xa8\xa9\u037a\xab\xac\xad\ufffd\u2015\xb0\xb1\xb2\xb3\u0384\u0385\u0386\xb7\u0388\u0389\u038a\xbb\u038c\xbd\u038e\u038f\u0390\u0391\u0392\u0393\u0394\u0395\u0396\u0397\u0398\u0399\u039a\u039b\u039c\u039d\u039e\u039f\u03a0\u03a1\ufffd\u03a3\u03a4\u03a5\u03a6\u03a7\u03a8\u03a9\u03aa\u03ab\u03ac\u03ad\u03ae\u03af\u03b0\u03b1\u03b2\u03b3\u03b4\u03b5\u03b6\u03b7\u03b8\u03b9\u03ba\u03bb\u03bc\u03bd\u03be\u03bf\u03c0\u03c1\u03c2\u03c3\u03c4\u03c5\u03c6\u03c7\u03c8\u03c9\u03ca\u03cb\u03cc\u03cd\u03ce\ufffd"
+ },
+ "iso-8859-7": "iso88597",
+ "greek": "iso88597",
+ "greek8": "iso88597",
+ "cp28597": "iso88597",
+ "cp-28597": "iso88597",
+ 28597: "iso88597",
+
+ "cp737": {
+ type: "singlebyte",
+ chars: "\u0391\u0392\u0393\u0394\u0395\u0396\u0397\u0398\u0399\u039a\u039b\u039c\u039d\u039e\u039f\u03a0\u03a1\u03a3\u03a4\u03a5\u03a6\u03a7\u03a8\u03a9\u03b1\u03b2\u03b3\u03b4\u03b5\u03b6\u03b7\u03b8\u03b9\u03ba\u03bb\u03bc\u03bd\u03be\u03bf\u03c0\u03c1\u03c3\u03c2\u03c4\u03c5\u03c6\u03c7\u03c8\u2591\u2592\u2593\u2502\u2524\u2561\u2562\u2556\u2555\u2563\u2551\u2557\u255d\u255c\u255b\u2510\u2514\u2534\u252c\u251c\u2500\u253c\u255e\u255f\u255a\u2554\u2569\u2566\u2560\u2550\u256c\u2567\u2568\u2564\u2565\u2559\u2558\u2552\u2553\u256b\u256a\u2518\u250c\u2588\u2584\u258c\u2590\u2580\u03c9\u03ac\u03ad\u03ae\u03ca\u03af\u03cc\u03cd\u03cb\u03ce\u0386\u0388\u0389\u038a\u038c\u038e\u038f\xb1\u2265\u2264\u03aa\u03ab\xf7\u2248\xb0\u2219\xb7\u221a\u207f\xb2\u25a0\xa0"
+ },
+ "cp-737": "cp737",
+ 737: "cp737"
+}
View
@@ -0,0 +1,79 @@
+var vows = require('vows'),
+ assert = require('assert'),
+ iconv = require(__dirname+'/../');
+
+var baseStrings = {
+ empty: "",
+ hi: "Γειά!",
+ ascii: '\x00\x01\x02\x03\x04\x05\x06\x07\x08\t\n\x0b\x0c\r\x0e\x0f\x10\x11\x12\x13\x14\x15\x16\x17\x18\x19\x1a\x1b\x1c\x1d\x1e\x1f'+
+ ' !"#$%&\'()*+,-./0123456789:;<=>?@ABCDEFGHIJKLMNOPQRSTUVWXYZ[\\]^_`abcdefghijklmnopqrstuvwxyz{|}~\x7f',
+ greek: "αβγδεζηθικλμνξοπρστυφχψωΑΒΓΔΕΖΗΘΙΚΛΜΝΞΟΠΡΣΤΥΦΧΨΩάέήίόύώΆΈΉΊΌΎΏϊϋΪΫ",
+ untranslatable: "Åçþÿ¿"
+};
+
+var encodings = [{
+ name: "windows1253",
+ variations: ['windows-1253', 'win-1253', 'win1253', 'cp1253', 'cp-1253', 1253],
+ encodedStrings: {
+ empty: new Buffer(''),
+ hi: new Buffer('\xc3\xe5\xe9\xdc!', 'binary'),
+ ascii: new Buffer(baseStrings.ascii, 'binary'),
+ greek: new Buffer('\xe1\xe2\xe3\xe4\xe5\xe6\xe7\xe8\xe9\xea\xeb\xec\xed\xee\xef\xf0\xf1\xf3\xf4\xf5\xf6\xf7\xf8\xf9\xc1\xc2\xc3\xc4\xc5\xc6\xc7\xc8\xc9\xca\xcb\xcc\xcd\xce\xcf\xd0\xd1\xd3\xd4\xd5\xd6\xd7\xd8\xd9\xdc\xdd\xde\xdf\xfc\xfd\xfe\xa2\xb8\xb9\xba\xbc\xbe\xbf\xfa\xfb\xda\xdb', 'binary'),
+ }
+}, {
+ name: "iso88597",
+ variations: ['iso-8859-7', 'greek', 'greek8', 'cp28597', 'cp-28597', 28597],
+ encodedStrings: {
+ empty: new Buffer(''),
+ hi: new Buffer('\xc3\xe5\xe9\xdc!', 'binary'),
+ ascii: new Buffer(baseStrings.ascii, 'binary'),
+ greek: new Buffer('\xe1\xe2\xe3\xe4\xe5\xe6\xe7\xe8\xe9\xea\xeb\xec\xed\xee\xef\xf0\xf1\xf3\xf4\xf5\xf6\xf7\xf8\xf9\xc1\xc2\xc3\xc4\xc5\xc6\xc7\xc8\xc9\xca\xcb\xcc\xcd\xce\xcf\xd0\xd1\xd3\xd4\xd5\xd6\xd7\xd8\xd9\xdc\xdd\xde\xdf\xfc\xfd\xfe\xb6\xb8\xb9\xba\xbc\xbe\xbf\xfa\xfb\xda\xdb', 'binary'),
+ }
+}, {
+ name: "cp737",
+ variations: ['cp-737', 737],
+ encodedStrings: {
+ empty: new Buffer(''),
+ hi: new Buffer('\x82\x9c\xa0\xe1!', 'binary'),
+ ascii: new Buffer(baseStrings.ascii, 'binary'),
+ greek: new Buffer('\x98\x99\x9a\x9b\x9c\x9d\x9e\x9f\xa0\xa1\xa2\xa3\xa4\xa5\xa6\xa7\xa8\xa9\xab\xac\xad\xae\xaf\xe0\x80\x81\x82\x83\x84\x85\x86\x87\x88\x89\x8a\x8b\x8c\x8d\x8e\x8f\x90\x91\x92\x93\x94\x95\x96\x97\xe1\xe2\xe3\xe5\xe6\xe7\xe9\xea\xeb\xec\xed\xee\xef\xf0\xe4\xe8\xf4\xf5', 'binary'),
+ }
+}];
+
+var testsBatch = {};
+encodings.forEach(function(encoding) {
+ var enc = encoding.variations[0];
+ var key = "hi";
+ var tests = {
+ "Convert to empty buffer": function() {
+ assert.strictEqual(iconv.toEncoding("", enc).toString('binary'), new Buffer('').toString('binary'));
+ },
+ "Convert from empty buffer": function() {
+ assert.strictEqual(iconv.fromEncoding(new Buffer(''), enc), "");
+ },
+ "Convert from buffer": function() {
+ for (var key in encoding.encodedStrings)
+ assert.strictEqual(iconv.fromEncoding(encoding.encodedStrings[key], enc),
+ baseStrings[key]);
+ },
+ "Convert to buffer": function() {
+ for (var key in encoding.encodedStrings)
+ assert.strictEqual(iconv.toEncoding(baseStrings[key], enc).toString('binary'),
+ encoding.encodedStrings[key].toString('binary'));
+ },
+ "Try different variations of encoding": function() {
+ encoding.variations.forEach(function(enc) {
+ assert.strictEqual(iconv.fromEncoding(encoding.encodedStrings[key], enc), baseStrings[key]);
+ assert.strictEqual(iconv.toEncoding(baseStrings[key], enc).toString('binary'), encoding.encodedStrings[key].toString('binary'));
+ });
+ },
+ "Untranslatable chars are converted to defaultCharSingleByte": function() {
+ var expected = baseStrings.untranslatable.split('').map(function(c) {return iconv.defaultCharSingleByte; }).join('');
+ assert.strictEqual(iconv.toEncoding(baseStrings.untranslatable, enc).toString('binary'), expected); // Only '?' characters.
+ }
+ };
+
+ testsBatch[encoding.name+":"] = tests;
+});
+
+vows.describe("Test Greek encodings").addBatch(testsBatch).export(module);

0 comments on commit 20f152d

Please sign in to comment.