diff --git a/tests/meson.build b/tests/meson.build index 0a3d2d7da..b9729d9de 100644 --- a/tests/meson.build +++ b/tests/meson.build @@ -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_tests = [ + 'highlighter', ] foreach test : unit_tests @@ -38,7 +39,6 @@ foreach test : unit_tests endforeach legacy_tests = [ - 'highlighter', 'injectionManager', 'insertSorted', 'jsParse', diff --git a/tests/unit/highlighter.js b/tests/unit/highlighter.js index 3c0d3f188..814c0093e 100644 --- a/tests/unit/highlighter.js +++ b/tests/unit/highlighter.js @@ -2,146 +2,134 @@ // Test cases for SearchResult description match highlighter -const JsUnit = imports.jsUnit; import Pango from 'gi://Pango'; 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 = [ - { - input: 'abc cba', - terms: null, - output: 'abc cba', - }, - { - input: 'abc cba', - terms: [], - output: 'abc cba', - }, - { - input: 'abc cba', - terms: [''], - output: 'abc cba', - }, - { - input: 'abc cba', - terms: ['a'], - output: 'abc cba', - }, - { - input: 'abc cba', - terms: ['a', 'a'], - output: 'abc cba', - }, - { - input: 'CaSe InSenSiTiVe', - terms: ['cas', 'sens'], - output: 'CaSe InSenSiTiVe', - }, - { - input: 'This contains the < character', - terms: null, - output: 'This contains the < character', - }, - { - input: 'Don\'t', - terms: ['t'], - output: 'Don't', - }, - { - input: 'Don\'t', - terms: ['n\'t'], - output: 'Don't', - }, - { - input: 'Don\'t', - terms: ['o', 't'], - output: 'Don't', - }, - { - input: 'salt&pepper', - terms: ['salt'], - output: 'salt&pepper', - }, - { - input: 'salt&pepper', - terms: ['salt', 'alt'], - output: 'salt&pepper', - }, - { - input: 'salt&pepper', - terms: ['pepper'], - output: 'salt&pepper', - }, - { - input: 'salt&pepper', - terms: ['salt', 'pepper'], - output: 'salt&pepper', - }, - { - input: 'salt&pepper', - terms: ['t', 'p'], - output: 'salt&pepper', - }, - { - input: 'salt&pepper', - terms: ['t', '&', 'p'], - output: 'salt&pepper', - }, - { - input: 'salt&pepper', - terms: ['e'], - output: 'salt&pepper', - }, - { - input: 'salt&pepper', - terms: ['&a', '&am', '&', '&'], - output: 'salt&pepper', - }, - { - input: '&&&&&', - terms: ['a'], - output: '&&&&&', - }, - { - input: '&;&;&;&;&;', - terms: ['a'], - output: '&;&;&;&;&;', - }, - { - input: '&;&;&;&;&;', - terms: [';'], - output: '&;&;&;&;&;', - }, - { - input: '&', - terms: ['a'], - output: '&amp;', - }, -]; +describe('Highlighter', () => { + const tests = [ + { + input: 'abc cba', + terms: null, + output: 'abc cba', + }, + { + input: 'abc cba', + terms: [], + output: 'abc cba', + }, + { + input: 'abc cba', + terms: [''], + output: 'abc cba', + }, + { + input: 'abc cba', + terms: ['a'], + output: 'abc cba', + }, + { + input: 'abc cba', + terms: ['a', 'a'], + output: 'abc cba', + }, + { + input: 'CaSe InSenSiTiVe', + terms: ['cas', 'sens'], + output: 'CaSe InSenSiTiVe', + }, + { + input: 'This contains the < character', + terms: null, + output: 'This contains the < character', + }, + { + input: 'Don\'t', + terms: ['t'], + output: 'Don't', + }, + { + input: 'Don\'t', + terms: ['n\'t'], + output: 'Don't', + }, + { + input: 'Don\'t', + terms: ['o', 't'], + output: 'Don't', + }, + { + input: 'salt&pepper', + terms: ['salt'], + output: 'salt&pepper', + }, + { + input: 'salt&pepper', + terms: ['salt', 'alt'], + output: 'salt&pepper', + }, + { + input: 'salt&pepper', + terms: ['pepper'], + output: 'salt&pepper', + }, + { + input: 'salt&pepper', + terms: ['salt', 'pepper'], + output: 'salt&pepper', + }, + { + input: 'salt&pepper', + terms: ['t', 'p'], + output: 'salt&pepper', + }, + { + input: 'salt&pepper', + terms: ['t', '&', 'p'], + output: 'salt&pepper', + }, + { + input: 'salt&pepper', + terms: ['e'], + output: 'salt&pepper', + }, + { + input: 'salt&pepper', + terms: ['&a', '&am', '&', '&'], + output: 'salt&pepper', + }, + { + input: '&&&&&', + terms: ['a'], + output: '&&&&&', + }, + { + input: '&;&;&;&;&;', + terms: ['a'], + output: '&;&;&;&;&;', + }, + { + input: '&;&;&;&;&;', + terms: [';'], + output: '&;&;&;&;&;', + }, + { + input: '&', + terms: ['a'], + output: '&amp;', + }, + ]; -try { - for (let i = 0; i < tests.length; i++) { - let highlighter = new Util.Highlighter(tests[i].terms); - let output = highlighter.highlight(tests[i].input); + for (const test of tests) { + const {terms, input, output: expected} = test; - JsUnit.assertEquals(`Test ${i + 1} highlight ` + - `"${tests[i].terms}" in "${tests[i].input}"`, - output, tests[i].output); + it(`highlights ${JSON.stringify(terms)} in "${input}"`, () => { + const highlighter = new Highlighter(terms); + const output = highlighter.highlight(input); - let parsed = false; - try { - Pango.parse_markup(output, -1, ''); - parsed = true; - } catch (e) {} - JsUnit.assertEquals(`Test ${i + 1} is valid markup`, true, parsed); + expect(output).toEqual(expected); + expect(() => Pango.parse_markup(output, -1, '')).not.toThrow(); + }); } -} catch (e) { - if (typeof e.isJsUnitException != 'undefined' && - e.isJsUnitException) { - if (e.comment) - log(`Error in: ${e.comment}`); - } - throw e; -} +});