intl/uconv/tests/unit/test_bug449578.js

changeset 0
6474c204b198
     1.1 --- /dev/null	Thu Jan 01 00:00:00 1970 +0000
     1.2 +++ b/intl/uconv/tests/unit/test_bug449578.js	Wed Dec 31 06:09:35 2014 +0100
     1.3 @@ -0,0 +1,55 @@
     1.4 +/* Tests conversion from ISO-2022-KR to Unicode (bug 449578)
     1.5 + */
     1.6 +
     1.7 +// designator sequence at beginning of line - legal
     1.8 +const in1 = "%1B$)C%0E0!3*4Y6s%0F 1234";     
     1.9 +// empty non-ASCII sequence -- illegal
    1.10 +const in2 = "%1B$)Cab%0E%0Fcd";
    1.11 +// designator sequence not at beginning of line - illegal
    1.12 +const in3 = "abc %1B$)C%0E0!3*4Y6s%0F 1234";
    1.13 +
    1.14 +const expected1 = "\uAC00\uB098\uB2E4\uB77C 1234";
    1.15 +const expected2 = "ab\uFFFD\cd";
    1.16 +const expected3 = "abc \u001B$)C\uAC00\uB098\uB2E4\uB77C 1234";
    1.17 +
    1.18 +function testCase(inStr, expected)
    1.19 +{
    1.20 +    var dataURI = "data:text/plain;charset=ISO-2022-KR," + inStr;
    1.21 +
    1.22 +    var IOService = Components.Constructor("@mozilla.org/network/io-service;1",
    1.23 +					 "nsIIOService");
    1.24 +    var ConverterInputStream =
    1.25 +	Components.Constructor("@mozilla.org/intl/converter-input-stream;1",
    1.26 +			       "nsIConverterInputStream",
    1.27 +			       "init");
    1.28 +
    1.29 +    var ios = new IOService();
    1.30 +    var channel = ios.newChannel(dataURI, "", null);
    1.31 +    var testInputStream = channel.open();
    1.32 +    var testConverter = new ConverterInputStream(testInputStream,
    1.33 +						 "ISO-2022-KR",
    1.34 +						 8192,
    1.35 +						 0xFFFD);
    1.36 +
    1.37 +    if (!(testConverter instanceof
    1.38 +	  Components.interfaces.nsIUnicharLineInputStream))
    1.39 +	throw "not line input stream";
    1.40 +
    1.41 +    var outStr = "";
    1.42 +    var more;
    1.43 +    do {
    1.44 +	// read the line and check for eof
    1.45 +	var line = {};
    1.46 +	more = testConverter.readLine(line);
    1.47 +	outStr += line.value;
    1.48 +    } while (more);
    1.49 +
    1.50 +    do_check_eq(outStr, expected);
    1.51 +}
    1.52 +    
    1.53 +function run_test()
    1.54 +{
    1.55 +    testCase(in1, expected1);
    1.56 +    testCase(in2, expected2);
    1.57 +    testCase(in3, expected3);
    1.58 +}

mercurial