
We already include an .editorconfig that is supported by many editors, including emacs, so no need to repeat an emacs-specific modeline in every source file. Part-of: <https://gitlab.gnome.org/GNOME/gnome-shell/-/merge_requests/3431>
134 lines
3.5 KiB
JavaScript
134 lines
3.5 KiB
JavaScript
// Test cases for SearchResult description match highlighter
|
|
|
|
import Pango from 'gi://Pango';
|
|
|
|
import 'resource:///org/gnome/shell/ui/environment.js';
|
|
import {Highlighter} from 'resource:///org/gnome/shell/misc/util.js';
|
|
|
|
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: '<b>a</b>bc cb<b>a</b>',
|
|
},
|
|
{
|
|
input: 'abc cba',
|
|
terms: ['a', 'a'],
|
|
output: '<b>a</b>bc cb<b>a</b>',
|
|
},
|
|
{
|
|
input: 'CaSe InSenSiTiVe',
|
|
terms: ['cas', 'sens'],
|
|
output: '<b>CaS</b>e In<b>SenS</b>iTiVe',
|
|
},
|
|
{
|
|
input: 'This contains the < character',
|
|
terms: null,
|
|
output: 'This contains the < character',
|
|
},
|
|
{
|
|
input: 'Don\'t',
|
|
terms: ['t'],
|
|
output: 'Don'<b>t</b>',
|
|
},
|
|
{
|
|
input: 'Don\'t',
|
|
terms: ['n\'t'],
|
|
output: 'Do<b>n't</b>',
|
|
},
|
|
{
|
|
input: 'Don\'t',
|
|
terms: ['o', 't'],
|
|
output: 'D<b>o</b>n'<b>t</b>',
|
|
},
|
|
{
|
|
input: 'salt&pepper',
|
|
terms: ['salt'],
|
|
output: '<b>salt</b>&pepper',
|
|
},
|
|
{
|
|
input: 'salt&pepper',
|
|
terms: ['salt', 'alt'],
|
|
output: '<b>salt</b>&pepper',
|
|
},
|
|
{
|
|
input: 'salt&pepper',
|
|
terms: ['pepper'],
|
|
output: 'salt&<b>pepper</b>',
|
|
},
|
|
{
|
|
input: 'salt&pepper',
|
|
terms: ['salt', 'pepper'],
|
|
output: '<b>salt</b>&<b>pepper</b>',
|
|
},
|
|
{
|
|
input: 'salt&pepper',
|
|
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'],
|
|
output: 'sal<b>t</b><b>&</b><b>p</b>e<b>p</b><b>p</b>er',
|
|
},
|
|
{
|
|
input: 'salt&pepper',
|
|
terms: ['e'],
|
|
output: 'salt&p<b>e</b>pp<b>e</b>r',
|
|
},
|
|
{
|
|
input: 'salt&pepper',
|
|
terms: ['&a', '&am', '&', '&'],
|
|
output: 'salt&pepper',
|
|
},
|
|
{
|
|
input: '&&&&&',
|
|
terms: ['a'],
|
|
output: '&&&&&',
|
|
},
|
|
{
|
|
input: '&;&;&;&;&;',
|
|
terms: ['a'],
|
|
output: '&;&;&;&;&;',
|
|
},
|
|
{
|
|
input: '&;&;&;&;&;',
|
|
terms: [';'],
|
|
output: '&<b>;</b>&<b>;</b>&<b>;</b>&<b>;</b>&<b>;</b>',
|
|
},
|
|
{
|
|
input: '&',
|
|
terms: ['a'],
|
|
output: '&<b>a</b>mp;',
|
|
},
|
|
];
|
|
|
|
for (const test of tests) {
|
|
const {terms, input, output: expected} = test;
|
|
|
|
it(`highlights ${JSON.stringify(terms)} in "${input}"`, () => {
|
|
const highlighter = new Highlighter(terms);
|
|
const output = highlighter.highlight(input);
|
|
|
|
expect(output).toEqual(expected);
|
|
expect(() => Pango.parse_markup(output, -1, '')).not.toThrow();
|
|
});
|
|
}
|
|
});
|