Something went wrong. Try again.
[READ-ONLY] Mirror of https://github.com/Aquaticat/Monochromatic. TypeScript and Rust monorepo: Claude Code and Pi coding-agent plugins, a m
Something went wrong. Try again.
123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173174175176177178179180181182183184185186187188189190191192193194195196197198199200201202203204205206207208209210211212213214215216217218219220221222223224225226227228229230231232233234235236237238239240241242243244245246247248249250251252253254255256257258259260261262263264265266267268269270/** Tests for wildcard pattern splitting and literal-part matching. @module */
import { describe, expect, it,} from '@monochromatic-dev/module-test/ts';
import { compilePattern, matchParts, splitPattern,} from '../dist/final/neutral/index.mjs';
await describe({ name: '', children: [ describe({ name: splitPattern.name, children: [ it({ name: 'returns one part when the pattern holds no wildcard', fn: async () => { expect(splitPattern('abc',),).toEqual([ 'abc', ],); }, },),
it({ name: 'splits on unescaped wildcards', fn: async () => { expect(splitPattern('a*b',),).toEqual([ 'a', 'b', ],); expect(splitPattern('*a*b*',),).toEqual([ '', 'a', 'b', '', ],); }, },),
it({ name: 'keeps escaped wildcards literal', fn: async () => { /** Backslash code unit for the escaped patterns below. */ const escape = String.fromCodePoint(92,); expect(splitPattern(`a${escape}*b`,),).toEqual([ 'a*b', ],); expect(splitPattern(`*${escape}**`,),).toEqual([ '', '*', '', ],); }, },),
it({ name: 'escapes any character after a backslash', fn: async () => { /** Backslash code unit for the escaped patterns below. */ const escape = String.fromCodePoint(92,); expect(splitPattern(`${escape}a${escape}b`,),).toEqual([ 'ab', ],); }, },),
it({ name: 'keeps a trailing backslash literal', fn: async () => { /** Backslash code unit for the trailing-escape pattern below. */ const escape = String.fromCodePoint(92,); expect(splitPattern(`test${escape}`,),).toEqual([ `test${escape}`, ],); }, },), ], },),
describe({ name: matchParts.name, children: [ it({ name: 'compares exactly when only one part exists', fn: async () => { expect(matchParts({ input: 'abc', parts: ['abc'], },),).toBe(true,); expect(matchParts({ input: 'abcd', parts: ['abc'], },),).toBe(false,); }, },),
it({ name: 'matches prefix and suffix around one wildcard', fn: async () => { expect(matchParts({ input: 'foobar', parts: [ 'foo', 'bar', ], },),).toBe(true,); expect(matchParts({ input: 'foobaz', parts: [ 'foo', 'bar', ], },),).toBe(false,); }, },),
it({ name: 'rejects a missing prefix or suffix', fn: async () => { expect(matchParts({ input: 'xbar', parts: [ 'foo', 'bar', ], },),).toBe(false,); expect(matchParts({ input: 'foox', parts: [ 'foo', 'bar', ], },),).toBe(false,); }, },),
it({ name: 'rejects middle parts past the suffix room', fn: async () => { expect(matchParts({ input: 'abc', parts: [ '', 'bc', 'abc', ], },),).toBe(false,); }, },),
it({ name: 'rejects overlapping prefix and suffix', fn: async () => { expect(matchParts({ input: 'a', parts: [ 'a', 'a', ], },),).toBe(false,); expect(matchParts({ input: 'aa', parts: [ 'a', 'a', ], },),).toBe(true,); }, },),
it({ name: 'orders middle parts without overlap', fn: async () => { expect(matchParts({ input: 'xaxbx', parts: [ '', 'a', 'b', '', ], },),).toBe(true,); expect(matchParts({ input: 'xbxax', parts: [ '', 'a', 'b', '', ], },),).toBe(false,); }, },), ], },),
describe({ name: compilePattern.name, children: [ it({ name: 'marks leading-bang patterns as negated', fn: async () => { expect(compilePattern({ pattern: '!foo', caseSensitive: false, },).negated,).toBe(true,); expect(compilePattern({ pattern: 'foo', caseSensitive: false, },).negated,).toBe(false,); }, },),
it({ name: 'tests folded inputs against folded parts', fn: async () => { /** Compiled case-insensitive pattern under test. */ const compiled = compilePattern({ pattern: 'uni*', caseSensitive: false, },); expect(compiled.test('UNICORN',),).toBe(true,); expect(compiled.test('rainbow',),).toBe(false,); }, },),
it({ name: 'strips one negation level and keeps the remainder', fn: async () => { /** Backslash code unit for the escaped-bang pattern below. */ const escape = String.fromCodePoint(92,); expect(compilePattern({ pattern: '!!foo', caseSensitive: true, },).test('!foo',),).toBe(true,); expect(compilePattern({ pattern: `${escape}!foo`, caseSensitive: true, },).test('!foo',),).toBe(true,); expect(compilePattern({ pattern: 'a*b', caseSensitive: true, },).test('axb',),).toBe(true,); }, },), ], },), ],},);