tests/unit: Fix remaining ESLint errors
Part-of: <https://gitlab.gnome.org/GNOME/gnome-shell/-/merge_requests/2822>
This commit is contained in:
parent
26e018206d
commit
c570011376
@ -8,6 +8,6 @@ overrides:
|
|||||||
- js/portalHelper/**
|
- js/portalHelper/**
|
||||||
- subprojects/extensions-app/**
|
- subprojects/extensions-app/**
|
||||||
- subprojects/extensions-tool/**
|
- subprojects/extensions-tool/**
|
||||||
- tests/shell/**
|
- tests/**
|
||||||
parserOptions:
|
parserOptions:
|
||||||
sourceType: module
|
sourceType: module
|
||||||
|
@ -11,72 +11,116 @@ Environment.init();
|
|||||||
const Util = imports.misc.util;
|
const Util = imports.misc.util;
|
||||||
|
|
||||||
const tests = [
|
const tests = [
|
||||||
{ input: 'abc cba',
|
{
|
||||||
|
input: 'abc cba',
|
||||||
terms: null,
|
terms: null,
|
||||||
output: 'abc cba' },
|
output: 'abc cba',
|
||||||
{ input: 'abc cba',
|
},
|
||||||
|
{
|
||||||
|
input: 'abc cba',
|
||||||
terms: [],
|
terms: [],
|
||||||
output: 'abc cba' },
|
output: 'abc cba',
|
||||||
{ input: 'abc cba',
|
},
|
||||||
|
{
|
||||||
|
input: 'abc cba',
|
||||||
terms: [''],
|
terms: [''],
|
||||||
output: 'abc cba' },
|
output: 'abc cba',
|
||||||
{ input: 'abc cba',
|
},
|
||||||
|
{
|
||||||
|
input: 'abc cba',
|
||||||
terms: ['a'],
|
terms: ['a'],
|
||||||
output: '<b>a</b>bc cb<b>a</b>' },
|
output: '<b>a</b>bc cb<b>a</b>',
|
||||||
{ input: 'abc cba',
|
},
|
||||||
|
{
|
||||||
|
input: 'abc cba',
|
||||||
terms: ['a', 'a'],
|
terms: ['a', 'a'],
|
||||||
output: '<b>a</b>bc cb<b>a</b>' },
|
output: '<b>a</b>bc cb<b>a</b>',
|
||||||
{ input: 'CaSe InSenSiTiVe',
|
},
|
||||||
|
{
|
||||||
|
input: 'CaSe InSenSiTiVe',
|
||||||
terms: ['cas', 'sens'],
|
terms: ['cas', 'sens'],
|
||||||
output: '<b>CaS</b>e In<b>SenS</b>iTiVe' },
|
output: '<b>CaS</b>e In<b>SenS</b>iTiVe',
|
||||||
{ input: 'This contains the < character',
|
},
|
||||||
|
{
|
||||||
|
input: 'This contains the < character',
|
||||||
terms: null,
|
terms: null,
|
||||||
output: 'This contains the < character' },
|
output: 'This contains the < character',
|
||||||
{ input: 'Don\'t',
|
},
|
||||||
|
{
|
||||||
|
input: 'Don\'t',
|
||||||
terms: ['t'],
|
terms: ['t'],
|
||||||
output: 'Don'<b>t</b>' },
|
output: 'Don'<b>t</b>',
|
||||||
{ input: 'Don\'t',
|
},
|
||||||
|
{
|
||||||
|
input: 'Don\'t',
|
||||||
terms: ['n\'t'],
|
terms: ['n\'t'],
|
||||||
output: 'Do<b>n't</b>' },
|
output: 'Do<b>n't</b>',
|
||||||
{ input: 'Don\'t',
|
},
|
||||||
|
{
|
||||||
|
input: 'Don\'t',
|
||||||
terms: ['o', 't'],
|
terms: ['o', 't'],
|
||||||
output: 'D<b>o</b>n'<b>t</b>' },
|
output: 'D<b>o</b>n'<b>t</b>',
|
||||||
{ input: 'salt&pepper',
|
},
|
||||||
|
{
|
||||||
|
input: 'salt&pepper',
|
||||||
terms: ['salt'],
|
terms: ['salt'],
|
||||||
output: '<b>salt</b>&pepper' },
|
output: '<b>salt</b>&pepper',
|
||||||
{ input: 'salt&pepper',
|
},
|
||||||
|
{
|
||||||
|
input: 'salt&pepper',
|
||||||
terms: ['salt', 'alt'],
|
terms: ['salt', 'alt'],
|
||||||
output: '<b>salt</b>&pepper' },
|
output: '<b>salt</b>&pepper',
|
||||||
{ input: 'salt&pepper',
|
},
|
||||||
|
{
|
||||||
|
input: 'salt&pepper',
|
||||||
terms: ['pepper'],
|
terms: ['pepper'],
|
||||||
output: 'salt&<b>pepper</b>' },
|
output: 'salt&<b>pepper</b>',
|
||||||
{ input: 'salt&pepper',
|
},
|
||||||
|
{
|
||||||
|
input: 'salt&pepper',
|
||||||
terms: ['salt', 'pepper'],
|
terms: ['salt', 'pepper'],
|
||||||
output: '<b>salt</b>&<b>pepper</b>' },
|
output: '<b>salt</b>&<b>pepper</b>',
|
||||||
{ input: 'salt&pepper',
|
},
|
||||||
|
{
|
||||||
|
input: 'salt&pepper',
|
||||||
terms: ['t', 'p'],
|
terms: ['t', 'p'],
|
||||||
output: 'sal<b>t</b>&<b>p</b>e<b>p</b><b>p</b>er' },
|
output: 'sal<b>t</b>&<b>p</b>e<b>p</b><b>p</b>er',
|
||||||
{ input: 'salt&pepper',
|
},
|
||||||
|
{
|
||||||
|
input: 'salt&pepper',
|
||||||
terms: ['t', '&', 'p'],
|
terms: ['t', '&', 'p'],
|
||||||
output: 'sal<b>t</b><b>&</b><b>p</b>e<b>p</b><b>p</b>er' },
|
output: 'sal<b>t</b><b>&</b><b>p</b>e<b>p</b><b>p</b>er',
|
||||||
{ input: 'salt&pepper',
|
},
|
||||||
|
{
|
||||||
|
input: 'salt&pepper',
|
||||||
terms: ['e'],
|
terms: ['e'],
|
||||||
output: 'salt&p<b>e</b>pp<b>e</b>r' },
|
output: 'salt&p<b>e</b>pp<b>e</b>r',
|
||||||
{ input: 'salt&pepper',
|
},
|
||||||
|
{
|
||||||
|
input: 'salt&pepper',
|
||||||
terms: ['&a', '&am', '&', '&'],
|
terms: ['&a', '&am', '&', '&'],
|
||||||
output: 'salt&pepper' },
|
output: 'salt&pepper',
|
||||||
{ input: '&&&&&',
|
},
|
||||||
|
{
|
||||||
|
input: '&&&&&',
|
||||||
terms: ['a'],
|
terms: ['a'],
|
||||||
output: '&&&&&' },
|
output: '&&&&&',
|
||||||
{ input: '&;&;&;&;&;',
|
},
|
||||||
|
{
|
||||||
|
input: '&;&;&;&;&;',
|
||||||
terms: ['a'],
|
terms: ['a'],
|
||||||
output: '&;&;&;&;&;' },
|
output: '&;&;&;&;&;',
|
||||||
{ input: '&;&;&;&;&;',
|
},
|
||||||
|
{
|
||||||
|
input: '&;&;&;&;&;',
|
||||||
terms: [';'],
|
terms: [';'],
|
||||||
output: '&<b>;</b>&<b>;</b>&<b>;</b>&<b>;</b>&<b>;</b>' },
|
output: '&<b>;</b>&<b>;</b>&<b>;</b>&<b>;</b>&<b>;</b>',
|
||||||
{ input: '&',
|
},
|
||||||
|
{
|
||||||
|
input: '&',
|
||||||
terms: ['a'],
|
terms: ['a'],
|
||||||
output: '&<b>a</b>mp;' }
|
output: '&<b>a</b>mp;',
|
||||||
|
},
|
||||||
];
|
];
|
||||||
|
|
||||||
try {
|
try {
|
||||||
@ -96,9 +140,8 @@ try {
|
|||||||
JsUnit.assertEquals(`Test ${i + 1} is valid markup`, true, parsed);
|
JsUnit.assertEquals(`Test ${i + 1} is valid markup`, true, parsed);
|
||||||
}
|
}
|
||||||
} catch (e) {
|
} catch (e) {
|
||||||
if (typeof(e.isJsUnitException) != 'undefined'
|
if (typeof e.isJsUnitException != 'undefined' &&
|
||||||
&& e.isJsUnitException)
|
e.isJsUnitException) {
|
||||||
{
|
|
||||||
if (e.comment)
|
if (e.comment)
|
||||||
log(`Error in: ${e.comment}`);
|
log(`Error in: ${e.comment}`);
|
||||||
}
|
}
|
||||||
|
@ -20,10 +20,10 @@ Util.insertSorted(arrayInt, 3);
|
|||||||
|
|
||||||
Assertions.assertArrayEquals('second test', [1, 2, 3, 3, 4, 5, 6], arrayInt);
|
Assertions.assertArrayEquals('second test', [1, 2, 3, 3, 4, 5, 6], arrayInt);
|
||||||
|
|
||||||
let obj1 = { a: 1 };
|
let obj1 = {a: 1};
|
||||||
let obj2 = { a: 2, b: 0 };
|
let obj2 = {a: 2, b: 0};
|
||||||
let obj3 = { a: 2, b: 1 };
|
let obj3 = {a: 2, b: 1};
|
||||||
let obj4 = { a: 3 };
|
let obj4 = {a: 3};
|
||||||
|
|
||||||
let arrayObj = [obj1, obj3, obj4];
|
let arrayObj = [obj1, obj3, obj4];
|
||||||
|
|
||||||
|
@ -10,90 +10,146 @@ Environment.init();
|
|||||||
|
|
||||||
const JsParse = imports.misc.jsParse;
|
const JsParse = imports.misc.jsParse;
|
||||||
|
|
||||||
const HARNESS_COMMAND_HEADER = "let imports = obj;" +
|
const HARNESS_COMMAND_HEADER = 'let imports = obj;' +
|
||||||
"let global = obj;" +
|
'let global = obj;' +
|
||||||
"let Main = obj;" +
|
'let Main = obj;' +
|
||||||
"let foo = obj;" +
|
'let foo = obj;' +
|
||||||
"let r = obj;";
|
'let r = obj;';
|
||||||
|
|
||||||
const testsFindMatchingQuote = [
|
const testsFindMatchingQuote = [
|
||||||
{ input: '"double quotes"',
|
{
|
||||||
output: 0 },
|
input: '"double quotes"',
|
||||||
{ input: '\'single quotes\'',
|
output: 0,
|
||||||
output: 0 },
|
},
|
||||||
{ input: 'some unquoted "some quoted"',
|
{
|
||||||
output: 14 },
|
input: '\'single quotes\'',
|
||||||
{ input: '"mixed \' quotes\'"',
|
output: 0,
|
||||||
output: 0 },
|
},
|
||||||
{ input: '"escaped \\" quote"',
|
{
|
||||||
output: 0 }
|
input: 'some unquoted "some quoted"',
|
||||||
|
output: 14,
|
||||||
|
},
|
||||||
|
{
|
||||||
|
input: '"mixed \' quotes\'"',
|
||||||
|
output: 0,
|
||||||
|
},
|
||||||
|
{
|
||||||
|
input: '"escaped \\" quote"',
|
||||||
|
output: 0,
|
||||||
|
},
|
||||||
];
|
];
|
||||||
const testsFindMatchingSlash = [
|
const testsFindMatchingSlash = [
|
||||||
{ input: '/slash/',
|
{
|
||||||
output: 0 },
|
input: '/slash/',
|
||||||
{ input: '/slash " with $ funny ^\' stuff/',
|
output: 0,
|
||||||
output: 0 },
|
},
|
||||||
{ input: 'some unslashed /some slashed/',
|
{
|
||||||
output: 15 },
|
input: '/slash " with $ funny ^\' stuff/',
|
||||||
{ input: '/escaped \\/ slash/',
|
output: 0,
|
||||||
output: 0 }
|
},
|
||||||
|
{
|
||||||
|
input: 'some unslashed /some slashed/',
|
||||||
|
output: 15,
|
||||||
|
},
|
||||||
|
{
|
||||||
|
input: '/escaped \\/ slash/',
|
||||||
|
output: 0,
|
||||||
|
},
|
||||||
];
|
];
|
||||||
const testsFindMatchingBrace = [
|
const testsFindMatchingBrace = [
|
||||||
{ input: '[square brace]',
|
{
|
||||||
output: 0 },
|
input: '[square brace]',
|
||||||
{ input: '(round brace)',
|
output: 0,
|
||||||
output: 0 },
|
},
|
||||||
{ input: '([()][nesting!])',
|
{
|
||||||
output: 0 },
|
input: '(round brace)',
|
||||||
{ input: '[we have "quoted [" braces]',
|
output: 0,
|
||||||
output: 0 },
|
},
|
||||||
{ input: '[we have /regex [/ braces]',
|
{
|
||||||
output: 0 },
|
input: '([()][nesting!])',
|
||||||
{ input: '([[])[] mismatched braces ]',
|
output: 0,
|
||||||
output: 1 }
|
},
|
||||||
|
{
|
||||||
|
input: '[we have "quoted [" braces]',
|
||||||
|
output: 0,
|
||||||
|
},
|
||||||
|
{
|
||||||
|
input: '[we have /regex [/ braces]',
|
||||||
|
output: 0,
|
||||||
|
},
|
||||||
|
{
|
||||||
|
input: '([[])[] mismatched braces ]',
|
||||||
|
output: 1,
|
||||||
|
},
|
||||||
];
|
];
|
||||||
const testsGetExpressionOffset = [
|
const testsGetExpressionOffset = [
|
||||||
{ input: 'abc.123',
|
{
|
||||||
output: 0 },
|
input: 'abc.123',
|
||||||
{ input: 'foo().bar',
|
output: 0,
|
||||||
output: 0 },
|
},
|
||||||
{ input: 'foo(bar',
|
{
|
||||||
output: 4 },
|
input: 'foo().bar',
|
||||||
{ input: 'foo[abc.match(/"/)]',
|
output: 0,
|
||||||
output: 0 }
|
},
|
||||||
|
{
|
||||||
|
input: 'foo(bar',
|
||||||
|
output: 4,
|
||||||
|
},
|
||||||
|
{
|
||||||
|
input: 'foo[abc.match(/"/)]',
|
||||||
|
output: 0,
|
||||||
|
},
|
||||||
];
|
];
|
||||||
const testsGetDeclaredConstants = [
|
const testsGetDeclaredConstants = [
|
||||||
{ input: 'const foo = X; const bar = Y;',
|
{
|
||||||
output: ['foo', 'bar'] },
|
input: 'const foo = X; const bar = Y;',
|
||||||
{ input: 'const foo=X; const bar=Y',
|
output: ['foo', 'bar'],
|
||||||
output: ['foo', 'bar'] }
|
},
|
||||||
|
{
|
||||||
|
input: 'const foo=X; const bar=Y',
|
||||||
|
output: ['foo', 'bar'],
|
||||||
|
},
|
||||||
];
|
];
|
||||||
const testsIsUnsafeExpression = [
|
const testsIsUnsafeExpression = [
|
||||||
{ input: 'foo.bar',
|
{
|
||||||
output: false },
|
input: 'foo.bar',
|
||||||
{ input: 'foo[\'bar\']',
|
output: false,
|
||||||
output: false },
|
},
|
||||||
{ input: 'foo["a=b=c".match(/=/)',
|
{
|
||||||
output: false },
|
input: 'foo[\'bar\']',
|
||||||
{ input: 'foo[1==2]',
|
output: false,
|
||||||
output: false },
|
},
|
||||||
{ input: '(x=4)',
|
{
|
||||||
output: true },
|
input: 'foo["a=b=c".match(/=/)',
|
||||||
{ input: '(x = 4)',
|
output: false,
|
||||||
output: true },
|
},
|
||||||
{ input: '(x;y)',
|
{
|
||||||
output: true }
|
input: 'foo[1==2]',
|
||||||
|
output: false,
|
||||||
|
},
|
||||||
|
{
|
||||||
|
input: '(x=4)',
|
||||||
|
output: true,
|
||||||
|
},
|
||||||
|
{
|
||||||
|
input: '(x = 4)',
|
||||||
|
output: true,
|
||||||
|
},
|
||||||
|
{
|
||||||
|
input: '(x;y)',
|
||||||
|
output: true,
|
||||||
|
},
|
||||||
];
|
];
|
||||||
const testsModifyScope = [
|
const testsModifyScope = [
|
||||||
"foo['a",
|
"foo['a",
|
||||||
"foo()['b'",
|
"foo()['b'",
|
||||||
"obj.foo()('a', 1, 2, 'b')().",
|
"obj.foo()('a', 1, 2, 'b')().",
|
||||||
"foo.[.",
|
'foo.[.',
|
||||||
"foo]]]()))].",
|
'foo]]]()))].',
|
||||||
"123'ab\"",
|
"123'ab\"",
|
||||||
"Main.foo.bar = 3; bar.",
|
'Main.foo.bar = 3; bar.',
|
||||||
"(Main.foo = 3).",
|
'(Main.foo = 3).',
|
||||||
"Main[Main.foo+=-1]."
|
'Main[Main.foo+=-1].',
|
||||||
];
|
];
|
||||||
|
|
||||||
//
|
//
|
||||||
@ -104,7 +160,7 @@ for (let i = 0; i < testsFindMatchingQuote.length; i++) {
|
|||||||
let text = testsFindMatchingQuote[i].input;
|
let text = testsFindMatchingQuote[i].input;
|
||||||
let match = JsParse.findMatchingQuote(text, text.length - 1);
|
let match = JsParse.findMatchingQuote(text, text.length - 1);
|
||||||
|
|
||||||
JsUnit.assertEquals('Test testsFindMatchingQuote ' + i,
|
JsUnit.assertEquals(`Test testsFindMatchingQuote ${i}`,
|
||||||
match, testsFindMatchingQuote[i].output);
|
match, testsFindMatchingQuote[i].output);
|
||||||
}
|
}
|
||||||
|
|
||||||
@ -112,7 +168,7 @@ for (let i = 0; i < testsFindMatchingSlash.length; i++) {
|
|||||||
let text = testsFindMatchingSlash[i].input;
|
let text = testsFindMatchingSlash[i].input;
|
||||||
let match = JsParse.findMatchingSlash(text, text.length - 1);
|
let match = JsParse.findMatchingSlash(text, text.length - 1);
|
||||||
|
|
||||||
JsUnit.assertEquals('Test testsFindMatchingSlash ' + i,
|
JsUnit.assertEquals(`Test testsFindMatchingSlash ${i}`,
|
||||||
match, testsFindMatchingSlash[i].output);
|
match, testsFindMatchingSlash[i].output);
|
||||||
}
|
}
|
||||||
|
|
||||||
@ -120,7 +176,7 @@ for (let i = 0; i < testsFindMatchingBrace.length; i++) {
|
|||||||
let text = testsFindMatchingBrace[i].input;
|
let text = testsFindMatchingBrace[i].input;
|
||||||
let match = JsParse.findMatchingBrace(text, text.length - 1);
|
let match = JsParse.findMatchingBrace(text, text.length - 1);
|
||||||
|
|
||||||
JsUnit.assertEquals('Test testsFindMatchingBrace ' + i,
|
JsUnit.assertEquals(`Test testsFindMatchingBrace ${i}`,
|
||||||
match, testsFindMatchingBrace[i].output);
|
match, testsFindMatchingBrace[i].output);
|
||||||
}
|
}
|
||||||
|
|
||||||
@ -128,7 +184,7 @@ for (let i = 0; i < testsGetExpressionOffset.length; i++) {
|
|||||||
let text = testsGetExpressionOffset[i].input;
|
let text = testsGetExpressionOffset[i].input;
|
||||||
let match = JsParse.getExpressionOffset(text, text.length - 1);
|
let match = JsParse.getExpressionOffset(text, text.length - 1);
|
||||||
|
|
||||||
JsUnit.assertEquals('Test testsGetExpressionOffset ' + i,
|
JsUnit.assertEquals(`Test testsGetExpressionOffset ${i}`,
|
||||||
match, testsGetExpressionOffset[i].output);
|
match, testsGetExpressionOffset[i].output);
|
||||||
}
|
}
|
||||||
|
|
||||||
@ -136,7 +192,7 @@ for (let i = 0; i < testsGetDeclaredConstants.length; i++) {
|
|||||||
let text = testsGetDeclaredConstants[i].input;
|
let text = testsGetDeclaredConstants[i].input;
|
||||||
let match = JsParse.getDeclaredConstants(text);
|
let match = JsParse.getDeclaredConstants(text);
|
||||||
|
|
||||||
Assertions.assertArrayEquals('Test testsGetDeclaredConstants ' + i,
|
Assertions.assertArrayEquals(`Test testsGetDeclaredConstants ${i}`,
|
||||||
match, testsGetDeclaredConstants[i].output);
|
match, testsGetDeclaredConstants[i].output);
|
||||||
}
|
}
|
||||||
|
|
||||||
@ -144,7 +200,7 @@ for (let i = 0; i < testsIsUnsafeExpression.length; i++) {
|
|||||||
let text = testsIsUnsafeExpression[i].input;
|
let text = testsIsUnsafeExpression[i].input;
|
||||||
let unsafe = JsParse.isUnsafeExpression(text);
|
let unsafe = JsParse.isUnsafeExpression(text);
|
||||||
|
|
||||||
JsUnit.assertEquals('Test testsIsUnsafeExpression ' + i,
|
JsUnit.assertEquals(`Test testsIsUnsafeExpression ${i}`,
|
||||||
unsafe, testsIsUnsafeExpression[i].output);
|
unsafe, testsIsUnsafeExpression[i].output);
|
||||||
}
|
}
|
||||||
|
|
||||||
@ -165,19 +221,17 @@ for (let i = 0; i < testsModifyScope.length; i++) {
|
|||||||
|
|
||||||
let matches = text.match(/(.*)\.(.*)/);
|
let matches = text.match(/(.*)\.(.*)/);
|
||||||
if (matches) {
|
if (matches) {
|
||||||
let [expr, base, attrHead] = matches;
|
let [, base] = matches;
|
||||||
|
|
||||||
if (!JsParse.isUnsafeExpression(base)) {
|
if (!JsParse.isUnsafeExpression(base)) {
|
||||||
with (obj) {
|
|
||||||
try {
|
try {
|
||||||
eval(HARNESS_COMMAND_HEADER + base);
|
eval(HARNESS_COMMAND_HEADER + base);
|
||||||
} catch (e) {
|
} catch (e) {
|
||||||
JsUnit.assertNotEquals("Code '" + base + "' is valid code", e.constructor, SyntaxError);
|
JsUnit.assertNotEquals(`Code '${base}' is valid code`, e.constructor, SyntaxError);
|
||||||
}
|
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
let propertyNames = Object.getOwnPropertyNames(obj);
|
let propertyNames = Object.getOwnPropertyNames(obj);
|
||||||
JsUnit.assertEquals("The context '" + JSON.stringify(obj) + "' was not modified", propertyNames.length, 0);
|
JsUnit.assertEquals(`The context '${JSON.stringify(obj)}' was not modified`, propertyNames.length, 0);
|
||||||
}
|
}
|
||||||
|
@ -8,12 +8,17 @@ const Pango = imports.gi.Pango;
|
|||||||
const Environment = imports.ui.environment;
|
const Environment = imports.ui.environment;
|
||||||
Environment.init();
|
Environment.init();
|
||||||
|
|
||||||
const Main = imports.ui.main; // unused, but needed to break dependency loop
|
imports.ui.main; // eslint-disable-line no-unused-expressions
|
||||||
const MessageList = imports.ui.messageList;
|
const MessageList = imports.ui.messageList;
|
||||||
|
|
||||||
// Assert that @input, assumed to be markup, gets "fixed" to @output,
|
/**
|
||||||
// which is valid markup. If @output is null, @input is expected to
|
* Assert that `input`, assumed to be markup, gets "fixed" to `output`,
|
||||||
// convert to itself
|
* which is valid markup. If `output` is null, `input` is expected to
|
||||||
|
* convert to itself
|
||||||
|
*
|
||||||
|
* @param {string} input the input
|
||||||
|
* @param {string} output the output
|
||||||
|
*/
|
||||||
function assertConverts(input, output) {
|
function assertConverts(input, output) {
|
||||||
if (!output)
|
if (!output)
|
||||||
output = input;
|
output = input;
|
||||||
@ -28,8 +33,14 @@ function assertConverts(input, output) {
|
|||||||
JsUnit.assertEquals(true, parsed);
|
JsUnit.assertEquals(true, parsed);
|
||||||
}
|
}
|
||||||
|
|
||||||
// Assert that @input, assumed to be plain text, gets escaped to @output,
|
|
||||||
// which is valid markup.
|
/**
|
||||||
|
* Assert that `input`, assumed to be plain text, gets escaped to `output`,
|
||||||
|
* which is valid markup.
|
||||||
|
*
|
||||||
|
* @param {string} input the input
|
||||||
|
* @param {string} output the output
|
||||||
|
*/
|
||||||
function assertEscapes(input, output) {
|
function assertEscapes(input, output) {
|
||||||
let fixed = MessageList._fixMarkup(input, false);
|
let fixed = MessageList._fixMarkup(input, false);
|
||||||
JsUnit.assertEquals(output, fixed);
|
JsUnit.assertEquals(output, fixed);
|
||||||
|
@ -1,6 +1,13 @@
|
|||||||
const JsUnit = imports.jsUnit;
|
const JsUnit = imports.jsUnit;
|
||||||
const Params = imports.misc.params;
|
const Params = imports.misc.params;
|
||||||
|
|
||||||
|
/**
|
||||||
|
* Asserts that two "param" objects have the same properties
|
||||||
|
* with the same values.
|
||||||
|
*
|
||||||
|
* @param {object} params the parsed params
|
||||||
|
* @param {object} expected the expected params
|
||||||
|
*/
|
||||||
function assertParamsEqual(params, expected) {
|
function assertParamsEqual(params, expected) {
|
||||||
for (let p in params) {
|
for (let p in params) {
|
||||||
JsUnit.assertTrue(p in expected);
|
JsUnit.assertTrue(p in expected);
|
||||||
@ -11,7 +18,7 @@ function assertParamsEqual(params, expected) {
|
|||||||
let defaults = {
|
let defaults = {
|
||||||
foo: 'This is a test',
|
foo: 'This is a test',
|
||||||
bar: null,
|
bar: null,
|
||||||
baz: 42
|
baz: 42,
|
||||||
};
|
};
|
||||||
|
|
||||||
assertParamsEqual(
|
assertParamsEqual(
|
||||||
@ -19,14 +26,14 @@ assertParamsEqual(
|
|||||||
defaults);
|
defaults);
|
||||||
|
|
||||||
assertParamsEqual(
|
assertParamsEqual(
|
||||||
Params.parse({ bar: 23 }, defaults),
|
Params.parse({bar: 23}, defaults),
|
||||||
{ foo: 'This is a test', bar: 23, baz: 42 });
|
{foo: 'This is a test', bar: 23, baz: 42});
|
||||||
|
|
||||||
JsUnit.assertRaises(
|
JsUnit.assertRaises(
|
||||||
() => {
|
() => {
|
||||||
Params.parse({ extraArg: 'quz' }, defaults);
|
Params.parse({extraArg: 'quz'}, defaults);
|
||||||
});
|
});
|
||||||
|
|
||||||
assertParamsEqual(
|
assertParamsEqual(
|
||||||
Params.parse({ extraArg: 'quz' }, defaults, true),
|
Params.parse({extraArg: 'quz'}, defaults, true),
|
||||||
{ foo: 'This is a test', bar: null, baz: 42, extraArg: 'quz' });
|
{foo: 'This is a test', bar: null, baz: 42, extraArg: 'quz'});
|
||||||
|
@ -8,17 +8,17 @@ const JsUnit = imports.jsUnit;
|
|||||||
const Signals = imports.misc.signals;
|
const Signals = imports.misc.signals;
|
||||||
|
|
||||||
const Environment = imports.ui.environment;
|
const Environment = imports.ui.environment;
|
||||||
const { TransientSignalHolder, registerDestroyableType } = imports.misc.signalTracker;
|
const {TransientSignalHolder, registerDestroyableType} = imports.misc.signalTracker;
|
||||||
|
|
||||||
Environment.init();
|
Environment.init();
|
||||||
|
|
||||||
const Destroyable = GObject.registerClass({
|
const Destroyable = GObject.registerClass({
|
||||||
Signals: { 'destroy': {} },
|
Signals: {'destroy': {}},
|
||||||
}, class Destroyable extends GObject.Object {});
|
}, class Destroyable extends GObject.Object {});
|
||||||
registerDestroyableType(Destroyable);
|
registerDestroyableType(Destroyable);
|
||||||
|
|
||||||
const GObjectEmitter = GObject.registerClass({
|
const GObjectEmitter = GObject.registerClass({
|
||||||
Signals: { 'signal': {} },
|
Signals: {'signal': {}},
|
||||||
}, class GObjectEmitter extends Destroyable {});
|
}, class GObjectEmitter extends Destroyable {});
|
||||||
|
|
||||||
const emitter1 = new Signals.EventEmitter();
|
const emitter1 = new Signals.EventEmitter();
|
||||||
@ -27,6 +27,7 @@ const emitter2 = new GObjectEmitter();
|
|||||||
const tracked1 = new Destroyable();
|
const tracked1 = new Destroyable();
|
||||||
const tracked2 = {};
|
const tracked2 = {};
|
||||||
|
|
||||||
|
let transientHolder;
|
||||||
let count = 0;
|
let count = 0;
|
||||||
const handler = () => count++;
|
const handler = () => count++;
|
||||||
|
|
||||||
|
@ -10,68 +10,114 @@ Environment.init();
|
|||||||
const Util = imports.misc.util;
|
const Util = imports.misc.util;
|
||||||
|
|
||||||
const tests = [
|
const tests = [
|
||||||
{ input: 'This is a test',
|
{
|
||||||
output: [] },
|
input: 'This is a test',
|
||||||
{ input: 'This is http://www.gnome.org a test',
|
output: [],
|
||||||
output: [ { url: 'http://www.gnome.org', pos: 8 } ] },
|
},
|
||||||
{ input: 'This is http://www.gnome.org',
|
{
|
||||||
output: [ { url: 'http://www.gnome.org', pos: 8 } ] },
|
input: 'This is http://www.gnome.org a test',
|
||||||
{ input: 'http://www.gnome.org a test',
|
output: [{url: 'http://www.gnome.org', pos: 8}],
|
||||||
output: [ { url: 'http://www.gnome.org', pos: 0 } ] },
|
},
|
||||||
{ input: 'http://www.gnome.org',
|
{
|
||||||
output: [ { url: 'http://www.gnome.org', pos: 0 } ] },
|
input: 'This is http://www.gnome.org',
|
||||||
{ input: 'Go to http://www.gnome.org.',
|
output: [{url: 'http://www.gnome.org', pos: 8}],
|
||||||
output: [ { url: 'http://www.gnome.org', pos: 6 } ] },
|
},
|
||||||
{ input: 'Go to http://www.gnome.org/.',
|
{
|
||||||
output: [ { url: 'http://www.gnome.org/', pos: 6 } ] },
|
input: 'http://www.gnome.org a test',
|
||||||
{ input: '(Go to http://www.gnome.org!)',
|
output: [{url: 'http://www.gnome.org', pos: 0}],
|
||||||
output: [ { url: 'http://www.gnome.org', pos: 7 } ] },
|
},
|
||||||
{ input: 'Use GNOME (http://www.gnome.org).',
|
{
|
||||||
output: [ { url: 'http://www.gnome.org', pos: 11 } ] },
|
input: 'http://www.gnome.org',
|
||||||
{ input: 'This is a http://www.gnome.org/path test.',
|
output: [{url: 'http://www.gnome.org', pos: 0}],
|
||||||
output: [ { url: 'http://www.gnome.org/path', pos: 10 } ] },
|
},
|
||||||
{ input: 'This is a www.gnome.org scheme-less test.',
|
{
|
||||||
output: [ { url: 'www.gnome.org', pos: 10 } ] },
|
input: 'Go to http://www.gnome.org.',
|
||||||
{ input: 'This is a www.gnome.org/scheme-less test.',
|
output: [{url: 'http://www.gnome.org', pos: 6}],
|
||||||
output: [ { url: 'www.gnome.org/scheme-less', pos: 10 } ] },
|
},
|
||||||
{ input: 'This is a http://www.gnome.org:99/port test.',
|
{
|
||||||
output: [ { url: 'http://www.gnome.org:99/port', pos: 10 } ] },
|
input: 'Go to http://www.gnome.org/.',
|
||||||
{ input: 'This is an ftp://www.gnome.org/ test.',
|
output: [{url: 'http://www.gnome.org/', pos: 6}],
|
||||||
output: [ { url: 'ftp://www.gnome.org/', pos: 11 } ] },
|
},
|
||||||
{ input: 'https://www.gnome.org/(some_url,_with_very_unusual_characters)',
|
{
|
||||||
output: [ { url: 'https://www.gnome.org/(some_url,_with_very_unusual_characters)', pos: 0 } ] },
|
input: '(Go to http://www.gnome.org!)',
|
||||||
{ input: 'https://www.gnome.org/(some_url_with_unbalanced_parenthesis',
|
output: [{url: 'http://www.gnome.org', pos: 7}],
|
||||||
output: [ { url: 'https://www.gnome.org/', pos: 0 } ] },
|
},
|
||||||
{ input: 'https://www.gnome.org/ plus trailing junk',
|
{
|
||||||
output: [ { url: 'https://www.gnome.org/', pos: 0 } ] },
|
input: 'Use GNOME (http://www.gnome.org).',
|
||||||
|
output: [{url: 'http://www.gnome.org', pos: 11}],
|
||||||
|
},
|
||||||
|
{
|
||||||
|
input: 'This is a http://www.gnome.org/path test.',
|
||||||
|
output: [{url: 'http://www.gnome.org/path', pos: 10}],
|
||||||
|
},
|
||||||
|
{
|
||||||
|
input: 'This is a www.gnome.org scheme-less test.',
|
||||||
|
output: [{url: 'www.gnome.org', pos: 10}],
|
||||||
|
},
|
||||||
|
{
|
||||||
|
input: 'This is a www.gnome.org/scheme-less test.',
|
||||||
|
output: [{url: 'www.gnome.org/scheme-less', pos: 10}],
|
||||||
|
},
|
||||||
|
{
|
||||||
|
input: 'This is a http://www.gnome.org:99/port test.',
|
||||||
|
output: [{url: 'http://www.gnome.org:99/port', pos: 10}],
|
||||||
|
},
|
||||||
|
{
|
||||||
|
input: 'This is an ftp://www.gnome.org/ test.',
|
||||||
|
output: [{url: 'ftp://www.gnome.org/', pos: 11}],
|
||||||
|
},
|
||||||
|
{
|
||||||
|
input: 'https://www.gnome.org/(some_url,_with_very_unusual_characters)',
|
||||||
|
output: [{url: 'https://www.gnome.org/(some_url,_with_very_unusual_characters)', pos: 0}],
|
||||||
|
},
|
||||||
|
{
|
||||||
|
input: 'https://www.gnome.org/(some_url_with_unbalanced_parenthesis',
|
||||||
|
output: [{url: 'https://www.gnome.org/', pos: 0}],
|
||||||
|
},
|
||||||
|
{
|
||||||
|
input: 'https://www.gnome.org/ plus trailing junk',
|
||||||
|
output: [{url: 'https://www.gnome.org/', pos: 0}],
|
||||||
|
},
|
||||||
|
|
||||||
{ input: 'Visit http://www.gnome.org/ and http://developer.gnome.org',
|
{
|
||||||
output: [ { url: 'http://www.gnome.org/', pos: 6 },
|
input: 'Visit http://www.gnome.org/ and http://developer.gnome.org',
|
||||||
{ url: 'http://developer.gnome.org', pos: 32 } ] },
|
output: [{url: 'http://www.gnome.org/', pos: 6},
|
||||||
|
{url: 'http://developer.gnome.org', pos: 32}],
|
||||||
|
},
|
||||||
|
|
||||||
{ input: 'This is not.a.domain test.',
|
{
|
||||||
output: [ ] },
|
input: 'This is not.a.domain test.',
|
||||||
{ input: 'This is not:a.url test.',
|
output: [],
|
||||||
output: [ ] },
|
},
|
||||||
{ input: 'This is not:/a.url/ test.',
|
{
|
||||||
output: [ ] },
|
input: 'This is not:a.url test.',
|
||||||
{ input: 'This is not:/a.url/ test.',
|
output: [],
|
||||||
output: [ ] },
|
},
|
||||||
{ input: 'This is not@a.url/ test.',
|
{
|
||||||
output: [ ] },
|
input: 'This is not:/a.url/ test.',
|
||||||
{ input: 'This is surely@not.a/url test.',
|
output: [],
|
||||||
output: [ ] }
|
},
|
||||||
|
{
|
||||||
|
input: 'This is not:/a.url/ test.',
|
||||||
|
output: [],
|
||||||
|
},
|
||||||
|
{
|
||||||
|
input: 'This is not@a.url/ test.',
|
||||||
|
output: [],
|
||||||
|
},
|
||||||
|
{
|
||||||
|
input: 'This is surely@not.a/url test.',
|
||||||
|
output: [],
|
||||||
|
},
|
||||||
];
|
];
|
||||||
|
|
||||||
for (let i = 0; i < tests.length; i++) {
|
for (let i = 0; i < tests.length; i++) {
|
||||||
let match = Util.findUrls(tests[i].input);
|
let match = Util.findUrls(tests[i].input);
|
||||||
|
|
||||||
JsUnit.assertEquals('Test ' + i + ' match length',
|
JsUnit.assertEquals(`Test ${i} match length`,
|
||||||
match.length, tests[i].output.length);
|
match.length, tests[i].output.length);
|
||||||
for (let j = 0; j < match.length; j++) {
|
for (let j = 0; j < match.length; j++) {
|
||||||
JsUnit.assertEquals('Test ' + i + ', match ' + j + ' url',
|
JsUnit.assertEquals(`Test ${i}, match ${j} url`, match[j].url, tests[i].output[j].url);
|
||||||
match[j].url, tests[i].output[j].url);
|
JsUnit.assertEquals(`Test ${i}, match ${j} position`, match[j].pos, tests[i].output[j].pos);
|
||||||
JsUnit.assertEquals('Test ' + i + ', match ' + j + ' position',
|
|
||||||
match[j].pos, tests[i].output[j].pos);
|
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
@ -10,43 +10,65 @@ Environment.init();
|
|||||||
const Util = imports.misc.util;
|
const Util = imports.misc.util;
|
||||||
|
|
||||||
const tests = [
|
const tests = [
|
||||||
{ v1: '40',
|
{
|
||||||
|
v1: '40',
|
||||||
v2: '40',
|
v2: '40',
|
||||||
res: 0 },
|
res: 0,
|
||||||
{ v1: '40',
|
},
|
||||||
|
{
|
||||||
|
v1: '40',
|
||||||
v2: '42',
|
v2: '42',
|
||||||
res: -1 },
|
res: -1,
|
||||||
{ v1: '42',
|
},
|
||||||
|
{
|
||||||
|
v1: '42',
|
||||||
v2: '40',
|
v2: '40',
|
||||||
res: 1 },
|
res: 1,
|
||||||
{ v1: '3.38.0',
|
},
|
||||||
|
{
|
||||||
|
v1: '3.38.0',
|
||||||
v2: '40',
|
v2: '40',
|
||||||
res: -1 },
|
res: -1,
|
||||||
{ v1: '40',
|
},
|
||||||
|
{
|
||||||
|
v1: '40',
|
||||||
v2: '3.38.0',
|
v2: '3.38.0',
|
||||||
res: 1 },
|
res: 1,
|
||||||
{ v1: '40',
|
},
|
||||||
|
{
|
||||||
|
v1: '40',
|
||||||
v2: '3.38.0',
|
v2: '3.38.0',
|
||||||
res: 1 },
|
res: 1,
|
||||||
{ v1: '40.alpha.1.1',
|
},
|
||||||
|
{
|
||||||
|
v1: '40.alpha.1.1',
|
||||||
v2: '40',
|
v2: '40',
|
||||||
res: -1 },
|
res: -1,
|
||||||
{ v1: '40',
|
},
|
||||||
|
{
|
||||||
|
v1: '40',
|
||||||
v2: '40.alpha.1.1',
|
v2: '40.alpha.1.1',
|
||||||
res: 1 },
|
res: 1,
|
||||||
{ v1: '40.beta',
|
},
|
||||||
|
{
|
||||||
|
v1: '40.beta',
|
||||||
v2: '40',
|
v2: '40',
|
||||||
res: -1 },
|
res: -1,
|
||||||
{ v1: '40.1',
|
},
|
||||||
|
{
|
||||||
|
v1: '40.1',
|
||||||
v2: '40',
|
v2: '40',
|
||||||
res: 1 },
|
res: 1,
|
||||||
{ v1: '',
|
},
|
||||||
|
{
|
||||||
|
v1: '',
|
||||||
v2: '40.alpha',
|
v2: '40.alpha',
|
||||||
res: -1 },
|
res: -1,
|
||||||
|
},
|
||||||
];
|
];
|
||||||
|
|
||||||
for (let i = 0; i < tests.length; i++) {
|
for (let i = 0; i < tests.length; i++) {
|
||||||
name = 'Test #' + i + ' v1: ' + tests[i].v1 + ', v2: ' + tests[i].v2;
|
const name = `Test #${i} v1: ${tests[i].v1}, v2: ${tests[i].v2}`;
|
||||||
print(name);
|
print(name);
|
||||||
JsUnit.assertEquals(name, Util.GNOMEversionCompare (tests[i].v1, tests[i].v2), tests[i].res);
|
JsUnit.assertEquals(name, Util.GNOMEversionCompare(tests[i].v1, tests[i].v2), tests[i].res);
|
||||||
}
|
}
|
||||||
|
Loading…
Reference in New Issue
Block a user