gnome-shell/tests/unit/url.js
Florian Müllner 9546860d05 tests/unit: Access shell sources from resource
Unit tests currently load shell sources directly from the
filesystem.

This is currently blocking generated sources - namely config.js - to
ESM, because a relative import from the source dir will fail to
locate the file in the build dir.

Address this by using the same GResource as gnome-shell instead of
direct filesystem access, as the resource will always include all
sources files at the expected location.

Part-of: <https://gitlab.gnome.org/GNOME/gnome-shell/-/merge_requests/2880>
2023-08-10 17:42:23 +00:00

123 lines
3.5 KiB
JavaScript
Raw Blame History

This file contains invisible Unicode characters

This file contains invisible Unicode characters that are indistinguishable to humans but may be processed differently by a computer. If you think that this is intentional, you can safely ignore this warning. Use the Escape button to reveal them.

// -*- mode: js; js-indent-level: 4; indent-tabs-mode: nil -*-
// Test cases for MessageTray URLification
const JsUnit = imports.jsUnit;
import 'resource:///org/gnome/shell/ui/environment.js';
import * as Util from 'resource:///org/gnome/shell/misc/util.js';
const tests = [
{
input: 'This is a test',
output: [],
},
{
input: 'This is http://www.gnome.org a test',
output: [{url: 'http://www.gnome.org', pos: 8}],
},
{
input: 'This is http://www.gnome.org',
output: [{url: 'http://www.gnome.org', pos: 8}],
},
{
input: 'http://www.gnome.org a test',
output: [{url: 'http://www.gnome.org', pos: 0}],
},
{
input: 'http://www.gnome.org',
output: [{url: 'http://www.gnome.org', pos: 0}],
},
{
input: 'Go to http://www.gnome.org.',
output: [{url: 'http://www.gnome.org', pos: 6}],
},
{
input: 'Go to http://www.gnome.org/.',
output: [{url: 'http://www.gnome.org/', pos: 6}],
},
{
input: '(Go to http://www.gnome.org!)',
output: [{url: 'http://www.gnome.org', pos: 7}],
},
{
input: 'Use GNOME (http://www.gnome.org).',
output: [{url: 'http://www.gnome.org', pos: 11}],
},
{
input: 'This is a http://www.gnome.org/path test.',
output: [{url: 'http://www.gnome.org/path', pos: 10}],
},
{
input: 'This is a www.gnome.org scheme-less test.',
output: [{url: 'www.gnome.org', pos: 10}],
},
{
input: 'This is a www.gnome.org/scheme-less test.',
output: [{url: 'www.gnome.org/scheme-less', pos: 10}],
},
{
input: 'This is a http://www.gnome.org:99/port test.',
output: [{url: 'http://www.gnome.org:99/port', pos: 10}],
},
{
input: 'This is an ftp://www.gnome.org/ test.',
output: [{url: 'ftp://www.gnome.org/', pos: 11}],
},
{
input: 'https://www.gnome.org/(some_url,_with_very_unusual_characters)',
output: [{url: 'https://www.gnome.org/(some_url,_with_very_unusual_characters)', pos: 0}],
},
{
input: 'https://www.gnome.org/(some_url_with_unbalanced_parenthesis',
output: [{url: 'https://www.gnome.org/', pos: 0}],
},
{
input: 'https://www.gnome.org/ plus trailing junk',
output: [{url: 'https://www.gnome.org/', pos: 0}],
},
{
input: 'Visit http://www.gnome.org/ and http://developer.gnome.org',
output: [{url: 'http://www.gnome.org/', pos: 6},
{url: 'http://developer.gnome.org', pos: 32}],
},
{
input: 'This is not.a.domain test.',
output: [],
},
{
input: 'This is not:a.url test.',
output: [],
},
{
input: 'This is not:/a.url/ test.',
output: [],
},
{
input: 'This is not:/a.url/ test.',
output: [],
},
{
input: 'This is not@a.url/ test.',
output: [],
},
{
input: 'This is surely@not.a/url test.',
output: [],
},
];
for (let i = 0; i < tests.length; i++) {
let match = Util.findUrls(tests[i].input);
JsUnit.assertEquals(`Test ${i} match length`,
match.length, tests[i].output.length);
for (let j = 0; j < match.length; j++) {
JsUnit.assertEquals(`Test ${i}, match ${j} url`, match[j].url, tests[i].output[j].url);
JsUnit.assertEquals(`Test ${i}, match ${j} position`, match[j].pos, tests[i].output[j].pos);
}
}