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,146 +2,134 @@
|
|||||||
|
|
||||||
// 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';
|
||||||
|
|
||||||
const tests = [
|
describe('Highlighter', () => {
|
||||||
{
|
const tests = [
|
||||||
input: 'abc cba',
|
{
|
||||||
terms: null,
|
input: 'abc cba',
|
||||||
output: 'abc cba',
|
terms: null,
|
||||||
},
|
output: 'abc cba',
|
||||||
{
|
},
|
||||||
input: 'abc cba',
|
{
|
||||||
terms: [],
|
input: 'abc cba',
|
||||||
output: 'abc cba',
|
terms: [],
|
||||||
},
|
output: 'abc cba',
|
||||||
{
|
},
|
||||||
input: 'abc cba',
|
{
|
||||||
terms: [''],
|
input: 'abc cba',
|
||||||
output: 'abc cba',
|
terms: [''],
|
||||||
},
|
output: 'abc cba',
|
||||||
{
|
},
|
||||||
input: 'abc cba',
|
{
|
||||||
terms: ['a'],
|
input: 'abc cba',
|
||||||
output: '<b>a</b>bc cb<b>a</b>',
|
terms: ['a'],
|
||||||
},
|
output: '<b>a</b>bc cb<b>a</b>',
|
||||||
{
|
},
|
||||||
input: 'abc cba',
|
{
|
||||||
terms: ['a', 'a'],
|
input: 'abc cba',
|
||||||
output: '<b>a</b>bc cb<b>a</b>',
|
terms: ['a', 'a'],
|
||||||
},
|
output: '<b>a</b>bc cb<b>a</b>',
|
||||||
{
|
},
|
||||||
input: 'CaSe InSenSiTiVe',
|
{
|
||||||
terms: ['cas', 'sens'],
|
input: 'CaSe InSenSiTiVe',
|
||||||
output: '<b>CaS</b>e In<b>SenS</b>iTiVe',
|
terms: ['cas', 'sens'],
|
||||||
},
|
output: '<b>CaS</b>e In<b>SenS</b>iTiVe',
|
||||||
{
|
},
|
||||||
input: 'This contains the < character',
|
{
|
||||||
terms: null,
|
input: 'This contains the < character',
|
||||||
output: 'This contains the < character',
|
terms: null,
|
||||||
},
|
output: 'This contains the < character',
|
||||||
{
|
},
|
||||||
input: 'Don\'t',
|
{
|
||||||
terms: ['t'],
|
input: 'Don\'t',
|
||||||
output: 'Don'<b>t</b>',
|
terms: ['t'],
|
||||||
},
|
output: 'Don'<b>t</b>',
|
||||||
{
|
},
|
||||||
input: 'Don\'t',
|
{
|
||||||
terms: ['n\'t'],
|
input: 'Don\'t',
|
||||||
output: 'Do<b>n't</b>',
|
terms: ['n\'t'],
|
||||||
},
|
output: 'Do<b>n't</b>',
|
||||||
{
|
},
|
||||||
input: 'Don\'t',
|
{
|
||||||
terms: ['o', 't'],
|
input: 'Don\'t',
|
||||||
output: 'D<b>o</b>n'<b>t</b>',
|
terms: ['o', 't'],
|
||||||
},
|
output: 'D<b>o</b>n'<b>t</b>',
|
||||||
{
|
},
|
||||||
input: 'salt&pepper',
|
{
|
||||||
terms: ['salt'],
|
input: 'salt&pepper',
|
||||||
output: '<b>salt</b>&pepper',
|
terms: ['salt'],
|
||||||
},
|
output: '<b>salt</b>&pepper',
|
||||||
{
|
},
|
||||||
input: 'salt&pepper',
|
{
|
||||||
terms: ['salt', 'alt'],
|
input: 'salt&pepper',
|
||||||
output: '<b>salt</b>&pepper',
|
terms: ['salt', 'alt'],
|
||||||
},
|
output: '<b>salt</b>&pepper',
|
||||||
{
|
},
|
||||||
input: 'salt&pepper',
|
{
|
||||||
terms: ['pepper'],
|
input: 'salt&pepper',
|
||||||
output: 'salt&<b>pepper</b>',
|
terms: ['pepper'],
|
||||||
},
|
output: 'salt&<b>pepper</b>',
|
||||||
{
|
},
|
||||||
input: 'salt&pepper',
|
{
|
||||||
terms: ['salt', 'pepper'],
|
input: 'salt&pepper',
|
||||||
output: '<b>salt</b>&<b>pepper</b>',
|
terms: ['salt', 'pepper'],
|
||||||
},
|
output: '<b>salt</b>&<b>pepper</b>',
|
||||||
{
|
},
|
||||||
input: 'salt&pepper',
|
{
|
||||||
terms: ['t', 'p'],
|
input: 'salt&pepper',
|
||||||
output: 'sal<b>t</b>&<b>p</b>e<b>p</b><b>p</b>er',
|
terms: ['t', 'p'],
|
||||||
},
|
output: 'sal<b>t</b>&<b>p</b>e<b>p</b><b>p</b>er',
|
||||||
{
|
},
|
||||||
input: 'salt&pepper',
|
{
|
||||||
terms: ['t', '&', 'p'],
|
input: 'salt&pepper',
|
||||||
output: 'sal<b>t</b><b>&</b><b>p</b>e<b>p</b><b>p</b>er',
|
terms: ['t', '&', 'p'],
|
||||||
},
|
output: 'sal<b>t</b><b>&</b><b>p</b>e<b>p</b><b>p</b>er',
|
||||||
{
|
},
|
||||||
input: 'salt&pepper',
|
{
|
||||||
terms: ['e'],
|
input: 'salt&pepper',
|
||||||
output: 'salt&p<b>e</b>pp<b>e</b>r',
|
terms: ['e'],
|
||||||
},
|
output: 'salt&p<b>e</b>pp<b>e</b>r',
|
||||||
{
|
},
|
||||||
input: 'salt&pepper',
|
{
|
||||||
terms: ['&a', '&am', '&', '&'],
|
input: 'salt&pepper',
|
||||||
output: 'salt&pepper',
|
terms: ['&a', '&am', '&', '&'],
|
||||||
},
|
output: 'salt&pepper',
|
||||||
{
|
},
|
||||||
input: '&&&&&',
|
{
|
||||||
terms: ['a'],
|
input: '&&&&&',
|
||||||
output: '&&&&&',
|
terms: ['a'],
|
||||||
},
|
output: '&&&&&',
|
||||||
{
|
},
|
||||||
input: '&;&;&;&;&;',
|
{
|
||||||
terms: ['a'],
|
input: '&;&;&;&;&;',
|
||||||
output: '&;&;&;&;&;',
|
terms: ['a'],
|
||||||
},
|
output: '&;&;&;&;&;',
|
||||||
{
|
},
|
||||||
input: '&;&;&;&;&;',
|
{
|
||||||
terms: [';'],
|
input: '&;&;&;&;&;',
|
||||||
output: '&<b>;</b>&<b>;</b>&<b>;</b>&<b>;</b>&<b>;</b>',
|
terms: [';'],
|
||||||
},
|
output: '&<b>;</b>&<b>;</b>&<b>;</b>&<b>;</b>&<b>;</b>',
|
||||||
{
|
},
|
||||||
input: '&',
|
{
|
||||||
terms: ['a'],
|
input: '&',
|
||||||
output: '&<b>a</b>mp;',
|
terms: ['a'],
|
||||||
},
|
output: '&<b>a</b>mp;',
|
||||||
];
|
},
|
||||||
|
];
|
||||||
|
|
||||||
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