Bug 1515877 - Turn on ESLint in mailnews/intl. r=jorgk

--HG--
rename : mailnews/intl/test/unit/CharsetConversionTests.js => mailnews/intl/test/unit/head_CharsetConversionTests.js
This commit is contained in:
Geoff Lankow 2019-05-09 00:18:08 +02:00
Родитель 3c0ac6681b
Коммит 880994b196
9 изменённых файлов: 82 добавлений и 102 удалений

Просмотреть файл

@ -64,7 +64,6 @@ mailnews/mailnews.js
mailnews/extensions/dsn/content/dsn.js
mailnews/extensions/mdn/content/mdn.js
mailnews/extensions/smime/content/smime.js
mailnews/intl/*
mailnews/jsaccount/*
mailnews/mime/*

Просмотреть файл

@ -0,0 +1,14 @@
"use strict";
module.exports = {
"extends": "plugin:mozilla/xpcshell-test",
"rules": {
"func-names": "off",
"mozilla/import-headjs-globals": "error",
"no-unused-vars": ["error", {
"args": "none",
"vars": "all",
}],
},
};

Просмотреть файл

@ -1,86 +0,0 @@
var CC = Components.Constructor;
function CreateScriptableConverter()
{
var ScriptableUnicodeConverter =
CC("@mozilla.org/intl/scriptableunicodeconverter",
"nsIScriptableUnicodeConverter");
return new ScriptableUnicodeConverter();
}
function checkDecode(converter, charset, inText, expectedText)
{
let manager = Cc['@mozilla.org/charset-converter-manager;1']
.getService(Ci.nsICharsetConverterManager);
try {
converter.charset = manager.getCharsetAlias(charset);
} catch(e) {
converter.charset = "iso-8859-1";
}
dump("testing decoding from " + charset + " to Unicode.\n");
try {
var outText = converter.ConvertToUnicode(inText) + converter.Finish();
} catch(e) {
outText = "\ufffd";
}
Assert.equal(outText, expectedText);
}
function checkEncode(converter, charset, inText, expectedText)
{
let manager = Cc['@mozilla.org/charset-converter-manager;1']
.getService(Ci.nsICharsetConverterManager);
try {
converter.charset = manager.getCharsetAlias(charset);
} catch(e) {
converter.charset = "iso-8859-1";
}
dump("testing encoding from Unicode to " + charset + "\n");
var outText = converter.ConvertFromUnicode(inText) + converter.Finish();
Assert.equal(outText, expectedText);
}
function testDecodeAliases()
{
var converter = CreateScriptableConverter();
for (var i = 0; i < aliases.length; ++i) {
checkDecode(converter, aliases[i], inString, expectedString);
}
}
function testEncodeAliases()
{
var converter = CreateScriptableConverter();
for (var i = 0; i < aliases.length; ++i) {
checkEncode(converter, aliases[i], inString, expectedString);
}
}
function testDecodeAliasesInternal()
{
let manager = Cc['@mozilla.org/charset-converter-manager;1']
.getService(Ci.nsICharsetConverterManager);
let converter = CreateScriptableConverter();
converter.isInternal = true;
for (let i = 0; i < aliases.length; ++i) {
if (manager.getCharsetAlias(aliases[i]).toLowerCase() == "utf-7") {
Assert.equal(manager.utf7ToUnicode(inString), expectedString);
} else {
checkDecode(converter, aliases[i], inString, expectedString);
}
}
}
function testEncodeAliasesInternal()
{
var converter = CreateScriptableConverter();
converter.isInternal = true;
for (var i = 0; i < aliases.length; ++i) {
checkEncode(converter, aliases[i], inString, expectedString);
}
}

Просмотреть файл

@ -0,0 +1,43 @@
var CC = Components.Constructor;
function CreateScriptableConverter() {
var ScriptableUnicodeConverter =
CC("@mozilla.org/intl/scriptableunicodeconverter",
"nsIScriptableUnicodeConverter");
return new ScriptableUnicodeConverter();
}
function checkDecode(converter, charset, inText, expectedText) {
let manager = Cc["@mozilla.org/charset-converter-manager;1"]
.getService(Ci.nsICharsetConverterManager);
try {
converter.charset = manager.getCharsetAlias(charset);
} catch (e) {
converter.charset = "iso-8859-1";
}
dump("testing decoding from " + charset + " to Unicode.\n");
try {
var outText = converter.ConvertToUnicode(inText) + converter.Finish();
} catch (e) {
outText = "\ufffd";
}
Assert.equal(outText, expectedText);
}
function checkEncode(converter, charset, inText, expectedText) {
let manager = Cc["@mozilla.org/charset-converter-manager;1"]
.getService(Ci.nsICharsetConverterManager);
try {
converter.charset = manager.getCharsetAlias(charset);
} catch (e) {
converter.charset = "iso-8859-1";
}
dump("testing encoding from Unicode to " + charset + "\n");
var outText = converter.ConvertFromUnicode(inText) + converter.Finish();
Assert.equal(outText, expectedText);
}

Просмотреть файл

@ -1,7 +1,5 @@
// Tests conversion from UTF-7 to Unicode. The conversion should fail!
load('CharsetConversionTests.js');
var inString = "+LGI--+ITIipSIp- +AocCeQ-oddns +Ad0CjQ- s+ATECZQKH- p+AlAB3QJ5- u+AlACVA- no+Ao4- +Al8-I";
var expectedString = "+LGI--+ITIipSIp- +AocCeQ-oddns +Ad0CjQ- s+ATECZQKH- p+AlAB3QJ5- u+AlACVA- no+Ao4- +Al8-I";
@ -10,5 +8,8 @@ var aliases = [ "UTF-7", "utf-7", "x-unicode-2-0-utf-7", "unicode-2-0-utf-7",
"unicode-1-1-utf-7", "csunicode11utf7" ];
function run_test() {
testDecodeAliases();
let converter = CreateScriptableConverter();
for (let i = 0; i < aliases.length; ++i) {
checkDecode(converter, aliases[i], inString, expectedString);
}
}

Просмотреть файл

@ -1,7 +1,5 @@
// Tests conversion from UTF-7 to Unicode.
load('CharsetConversionTests.js');
var inString = "+LGI--+ITIipSIp- +AocCeQ-oddns +Ad0CjQ- s+ATECZQKH- p+AlAB3QJ5- u+AlACVA- no+Ao4- +Al8-I";
var expectedString = "\u2C62-\u2132\u22A5\u2229 \u0287\u0279oddns \u01DD\u028D s\u0131\u0265\u0287 p\u0250\u01DD\u0279 u\u0250\u0254 no\u028E \u025FI";
@ -9,5 +7,15 @@ var expectedString = "\u2C62-\u2132\u22A5\u2229 \u0287\u0279oddns \u01DD\u028D s
var aliases = [ "UTF-7", "utf-7", "x-unicode-2-0-utf-7", "unicode-2-0-utf-7",
"unicode-1-1-utf-7", "csunicode11utf7" ];
function run_test() {
testDecodeAliasesInternal();
let manager = Cc["@mozilla.org/charset-converter-manager;1"]
.getService(Ci.nsICharsetConverterManager);
let converter = CreateScriptableConverter();
converter.isInternal = true;
for (let i = 0; i < aliases.length; ++i) {
if (manager.getCharsetAlias(aliases[i]).toLowerCase() == "utf-7") {
Assert.equal(manager.utf7ToUnicode(inString), expectedString);
} else {
checkDecode(converter, aliases[i], inString, expectedString);
}
}
}

Просмотреть файл

@ -1,7 +1,5 @@
// Tests conversion from Unicode to UTF-7. The conversion should fail!
load('CharsetConversionTests.js');
var inString = "\u2C62-\u2132\u22A5\u2229 \u0287\u0279oddns \u01DD\u028D s\u0131\u0265\u0287 p\u0250\u01DD\u0279 u\u0250\u0254 no\u028E \u025FI";
var expectedString = "?-??? ??oddns ?? s??? p??? u?? no? ?I";
@ -10,5 +8,8 @@ var aliases = [ "UTF-7", "utf-7", "x-unicode-2-0-utf-7", "unicode-2-0-utf-7",
"unicode-1-1-utf-7", "csunicode11utf7" ];
function run_test() {
testEncodeAliases();
let converter = CreateScriptableConverter();
for (let i = 0; i < aliases.length; ++i) {
checkEncode(converter, aliases[i], inString, expectedString);
}
}

Просмотреть файл

@ -1,7 +1,5 @@
// Tests conversion from Unicode to UTF-7.
load('CharsetConversionTests.js');
var inString = "\u2C62-\u2132\u22A5\u2229 \u0287\u0279oddns \u01DD\u028D s\u0131\u0265\u0287 p\u0250\u01DD\u0279 u\u0250\u0254 no\u028E \u025FI";
var expectedString = "+LGI--+ITIipSIp- +AocCeQ-oddns +Ad0CjQ- s+ATECZQKH- p+AlAB3QJ5- u+AlACVA- no+Ao4- +Al8-I";
@ -10,5 +8,9 @@ var aliases = [ "UTF-7", "utf-7", "x-unicode-2-0-utf-7", "unicode-2-0-utf-7",
"unicode-1-1-utf-7", "csunicode11utf7" ];
function run_test() {
testEncodeAliasesInternal();
let converter = CreateScriptableConverter();
converter.isInternal = true;
for (let i = 0; i < aliases.length; ++i) {
checkEncode(converter, aliases[i], inString, expectedString);
}
}

Просмотреть файл

@ -1,8 +1,6 @@
[DEFAULT]
head =
head = head_CharsetConversionTests.js
tail =
support-files =
CharsetConversionTests.js
[test_decode_utf-7.js]
[test_decode_utf-7_internal.js]