// 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: '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: '&',
},
];
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();
});
}
});