summaryrefslogtreecommitdiffstats
path: root/intl/uconv/tests/unit/test_bug399257.js
blob: 06e2f116c3da8e716d5f6c0cda870660a9e9318a (plain)
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
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
// Tests encoding of characters below U+0020
load('CharsetConversionTests.js');

const inString = "Hello\u000aWorld";
const expectedString = "Hello\nWorld";

function run_test() {
    var failures = false;
    var encodingConverter = CreateScriptableConverter();

    var encoders = [
        "Big5",
        "Big5-HKSCS",
        "EUC-JP",
        "EUC-KR",
        "gb18030",
        "gbk",
        "IBM866",
        "ISO-2022-JP",
        "ISO-8859-1",
        "ISO-8859-2",
        "ISO-8859-3",
        "ISO-8859-4",
        "ISO-8859-5",
        "ISO-8859-6",
        "ISO-8859-7",
        "ISO-8859-8",
        "ISO-8859-8-I",
        "ISO-8859-10",
        "ISO-8859-13",
        "ISO-8859-14",
        "ISO-8859-15",
        "ISO-8859-16",
        "KOI8-R",
        "KOI8-U",
        "Shift_JIS",
        "windows-1250",
        "windows-1251",
        "windows-1252",
        "windows-1253",
        "windows-1254",
        "windows-1255",
        "windows-1256",
        "windows-1257",
        "windows-1258",
        "windows-874",
        "macintosh",
        "x-mac-cyrillic",
        "x-user-defined",
        "UTF-8"
    ];

    var counter = 0;
    while (counter < encoders.length) {
	var charset = encoders[counter++];
        dump("testing " + counter + " " + charset + "\n");

        encodingConverter.charset = charset;
        var codepageString = encodingConverter.ConvertFromUnicode(inString) +
            encodingConverter.Finish();
	if (codepageString != expectedString) {
	    dump(charset + " encoding failed\n");
	    for (var i = 0; i < expectedString.length; ++i) {
		if (codepageString.charAt(i) != expectedString.charAt(i)) {
		    dump(i.toString(16) + ": 0x" +
			 codepageString.charCodeAt(i).toString(16) + " != " +
			 expectedString.charCodeAt(i).toString(16) + "\n");
		}
	    }
	    failures = true;
	}
    }
    if (failures) {
	do_throw("test failed\n");
    }
}