tests: Port Highlighter test to jasmine
Part-of: <https://gitlab.gnome.org/GNOME/gnome-shell/-/merge_requests/3164>
This commit is contained in:
parent
ea4f859547
commit
9315d42dd6
@ -20,6 +20,7 @@ unit_testenv.append('GI_TYPELIB_PATH', shell_typelib_path, separator: ':')
|
|||||||
unit_testenv.append('GI_TYPELIB_PATH', st_typelib_path, separator: ':')
|
unit_testenv.append('GI_TYPELIB_PATH', st_typelib_path, separator: ':')
|
||||||
|
|
||||||
unit_tests = [
|
unit_tests = [
|
||||||
|
'highlighter',
|
||||||
]
|
]
|
||||||
|
|
||||||
foreach test : unit_tests
|
foreach test : unit_tests
|
||||||
@ -38,7 +39,6 @@ foreach test : unit_tests
|
|||||||
endforeach
|
endforeach
|
||||||
|
|
||||||
legacy_tests = [
|
legacy_tests = [
|
||||||
'highlighter',
|
|
||||||
'injectionManager',
|
'injectionManager',
|
||||||
'insertSorted',
|
'insertSorted',
|
||||||
'jsParse',
|
'jsParse',
|
||||||
|
@ -2,12 +2,12 @@
|
|||||||
|
|
||||||
// Test cases for SearchResult description match highlighter
|
// Test cases for SearchResult description match highlighter
|
||||||
|
|
||||||
const JsUnit = imports.jsUnit;
|
|
||||||
import Pango from 'gi://Pango';
|
import Pango from 'gi://Pango';
|
||||||
|
|
||||||
import 'resource:///org/gnome/shell/ui/environment.js';
|
import 'resource:///org/gnome/shell/ui/environment.js';
|
||||||
import * as Util from 'resource:///org/gnome/shell/misc/util.js';
|
import {Highlighter} from 'resource:///org/gnome/shell/misc/util.js';
|
||||||
|
|
||||||
|
describe('Highlighter', () => {
|
||||||
const tests = [
|
const tests = [
|
||||||
{
|
{
|
||||||
input: 'abc cba',
|
input: 'abc cba',
|
||||||
@ -121,27 +121,15 @@ const tests = [
|
|||||||
},
|
},
|
||||||
];
|
];
|
||||||
|
|
||||||
try {
|
for (const test of tests) {
|
||||||
for (let i = 0; i < tests.length; i++) {
|
const {terms, input, output: expected} = test;
|
||||||
let highlighter = new Util.Highlighter(tests[i].terms);
|
|
||||||
let output = highlighter.highlight(tests[i].input);
|
|
||||||
|
|
||||||
JsUnit.assertEquals(`Test ${i + 1} highlight ` +
|
it(`highlights ${JSON.stringify(terms)} in "${input}"`, () => {
|
||||||
`"${tests[i].terms}" in "${tests[i].input}"`,
|
const highlighter = new Highlighter(terms);
|
||||||
output, tests[i].output);
|
const output = highlighter.highlight(input);
|
||||||
|
|
||||||
let parsed = false;
|
expect(output).toEqual(expected);
|
||||||
try {
|
expect(() => Pango.parse_markup(output, -1, '')).not.toThrow();
|
||||||
Pango.parse_markup(output, -1, '');
|
});
|
||||||
parsed = true;
|
|
||||||
} catch (e) {}
|
|
||||||
JsUnit.assertEquals(`Test ${i + 1} is valid markup`, true, parsed);
|
|
||||||
}
|
|
||||||
} catch (e) {
|
|
||||||
if (typeof e.isJsUnitException != 'undefined' &&
|
|
||||||
e.isJsUnitException) {
|
|
||||||
if (e.comment)
|
|
||||||
log(`Error in: ${e.comment}`);
|
|
||||||
}
|
|
||||||
throw e;
|
|
||||||
}
|
}
|
||||||
|
});
|
||||||
|
Loading…
x
Reference in New Issue
Block a user