about summary refs log tree commit diff stats
path: root/js/blotbotboot/node_modules/irc/test/test-convert-encoding.js
diff options
context:
space:
mode:
Diffstat (limited to 'js/blotbotboot/node_modules/irc/test/test-convert-encoding.js')
-rw-r--r--js/blotbotboot/node_modules/irc/test/test-convert-encoding.js53
1 files changed, 53 insertions, 0 deletions
diff --git a/js/blotbotboot/node_modules/irc/test/test-convert-encoding.js b/js/blotbotboot/node_modules/irc/test/test-convert-encoding.js
new file mode 100644
index 0000000..bbd62fa
--- /dev/null
+++ b/js/blotbotboot/node_modules/irc/test/test-convert-encoding.js
@@ -0,0 +1,53 @@
+var irc = require('../lib/irc');
+var test = require('tape');
+var testHelpers = require('./helpers');
+var checks = testHelpers.getFixtures('convert-encoding');
+var bindTo = { opt: { encoding: 'utf-8' } };
+
+test('irc.Client.convertEncoding old', function(assert) {
+    var convertEncoding = function(str) {
+        var self = this;
+
+        if (self.opt.encoding) {
+            var charsetDetector = require('node-icu-charset-detector');
+            var Iconv = require('iconv').Iconv;
+            var charset = charsetDetector.detectCharset(str).toString();
+            var to = new Iconv(charset, self.opt.encoding);
+
+            return to.convert(str);
+        } else {
+            return str;
+        }
+    }.bind(bindTo);
+
+    checks.causesException.forEach(function iterate(line) {
+        var causedException = false;
+        try {
+            convertEncoding(line);
+        } catch (e) {
+            causedException = true;
+        }
+
+        assert.equal(causedException, true, line + ' caused exception');
+    });
+
+    assert.end();
+});
+
+test('irc.Client.convertEncoding', function(assert) {
+    var convertEncoding = irc.Client.prototype.convertEncoding.bind(bindTo);
+
+    checks.causesException.forEach(function iterate(line) {
+        var causedException = false;
+
+        try {
+            convertEncoding(line);
+        } catch (e) {
+            causedException = true;
+        }
+
+        assert.equal(causedException, false, line + ' didn\'t cause exception');
+    });
+
+    assert.end();
+});