// @ts-nocheck import test from 'node:test'; import assert from 'node:assert/strict'; import { urlMatchesPattern } from '../src/commands/tabs-query'; const TWITCH = 'https://www.twitch.tv/somechannel'; test('plain pattern is a case-sensitive substring match (historic behavior)', () => { assert.equal(urlMatchesPattern(TWITCH, 'twitch.tv'), true); assert.equal(urlMatchesPattern(TWITCH, 'somechannel'), true); assert.equal(urlMatchesPattern(TWITCH, 'Twitch.tv'), false, 'case-sensitive'); assert.equal(urlMatchesPattern(TWITCH, 'youtube.com'), false); }); test('glob with /* matches anywhere in the URL', () => { // The reported case: a glob, not a literal substring. assert.equal(urlMatchesPattern(TWITCH, 'twitch.tv/*'), true); assert.equal(urlMatchesPattern('https://www.twitch.tv/', 'twitch.tv/*'), true); assert.equal(urlMatchesPattern('https://twitch.tv', 'twitch.tv/*'), false, 'no slash → no match'); }); test('leading wildcard and ? wildcard work', () => { assert.equal(urlMatchesPattern(TWITCH, '*.twitch.tv/*'), true); assert.equal(urlMatchesPattern('https://a.twitch.tv/x', 'https://?.twitch.tv/*'), true); assert.equal(urlMatchesPattern('https://ab.twitch.tv/x', 'https://?.twitch.tv/*'), false, '? is one char'); }); test('regex metacharacters in a non-glob pattern stay literal', () => { assert.equal(urlMatchesPattern('https://x.dev/a.b', 'a.b'), true); assert.equal(urlMatchesPattern('https://x.dev/axb', 'a.b'), false, 'plain substring is literal — "." is not a regex wildcard'); }); test('regex metacharacters next to a glob are escaped', () => { // The "." must stay literal even when "*" promotes the pattern to a glob. assert.equal(urlMatchesPattern('https://x.dev/foo', 'x.dev/*'), true); assert.equal(urlMatchesPattern('https://xydev/foo', 'x.dev/*'), false, '. does not match y'); }); test('empty url or pattern never matches', () => { assert.equal(urlMatchesPattern('', 'twitch.tv'), false); assert.equal(urlMatchesPattern(undefined, 'twitch.tv'), false); assert.equal(urlMatchesPattern(TWITCH, ''), false); });