about summary refs log tree commit diff stats
path: root/js/blotbotboot/node_modules/irc/test/test-convert-encoding.js
blob: bbd62fac43ed77987cd58e0b0acf86aa634fd96a (plain) (blame)
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
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();
});