From 345736c99812661473cfa40e98c62fe7f00a57cd Mon Sep 17 00:00:00 2001 From: Jason Dent Date: Sat, 29 Jun 2024 14:22:59 +0200 Subject: [PATCH] Update Tests --- packages/cspell-glob/src/GlobMatcher.test.ts | 17 ++--- packages/cspell-glob/src/GlobMatcher.ts | 75 -------------------- 2 files changed, 9 insertions(+), 83 deletions(-) diff --git a/packages/cspell-glob/src/GlobMatcher.test.ts b/packages/cspell-glob/src/GlobMatcher.test.ts index dbcfc6838e43..f64dd13ac624 100644 --- a/packages/cspell-glob/src/GlobMatcher.test.ts +++ b/packages/cspell-glob/src/GlobMatcher.test.ts @@ -568,14 +568,15 @@ function tests(): TestCase[] { [['node_modules/'], gitRoot, r(__dirname, 'node_modules/'), false, 'node_modules/'], [['node_modules/'], gitRoot, r(__dirname, 'project/node_modules/p/index.js'), true, 'node_modules/'], [['package.json'], gitRoot, r(__dirname, 'project/package.json'), true, 'package.json'], - // [{ glob: 'node_modules/', root: '${cwd}' }, gitRoot, r(__dirname, 'node_modules/p/index.js'), true, 'node_modules/'], - // [{ glob: 'node_modules/', root: '${cwd}' }, gitRoot, r(__dirname, 'node_modules/'), false, 'node_modules/'], - // [{ glob: 'node_modules/', root: '${cwd}' }, gitRoot, r(__dirname, 'project/node_modules/p/index.js'), true, 'node_modules/'], - // [{ glob: 'package.json', root: '${cwd}' }, gitRoot, r(__dirname, 'project/package.json'), true, 'package.json'], - // [['${cwd}/node_modules/'], gitRoot, r(__dirname, 'node_modules/p/index.js'), true, 'node_modules/'], - // [['${cwd}/node_modules/'], gitRoot, r(__dirname, 'node_modules/'), false, 'node_modules/'], - // [['${cwd}/node_modules/'], gitRoot, r(__dirname, 'project/node_modules/p/index.js'), true, 'node_modules/'], - // [['${cwd}/package.json'], gitRoot, r(__dirname, 'project/package.json'), true, 'package.json'], + [{ glob: 'node_modules/', root: '${cwd}' }, gitRoot, 'node_modules/p/index.js', true, 'node_modules/'], + [{ glob: 'node_modules/', root: '${cwd}' }, gitRoot, 'node_modules/', false, 'node_modules/'], + [{ glob: 'node_modules/', root: '${cwd}' }, gitRoot, 'project/node_modules/p/index.js', true, 'node_modules/'], + [{ glob: 'package.json', root: '${cwd}' }, gitRoot, 'project/package.json', true, 'package.json'], + [['${cwd}/node_modules/'], gitRoot, 'node_modules/p/index.js', true, 'node_modules/'], + [['${cwd}/node_modules/'], gitRoot, 'node_modules/', false, 'node_modules/'], + [['${cwd}/node_modules/'], gitRoot, 'node_modules/cspell/', true, 'node_modules/'], + [['${cwd}/node_modules/'], gitRoot, 'project/node_modules/p/index.js', false, 'node_modules/'], + [['${cwd}/package.json'], gitRoot, 'package.json', true, 'package.json'], [['*.json'], undefined, './settings.json', true, '*.json'], [['*.json'], undefined, 'settings.json', true, '*.json'], [['*.json'], undefined, '${cwd}/settings.json', true, '*.json'], diff --git a/packages/cspell-glob/src/GlobMatcher.ts b/packages/cspell-glob/src/GlobMatcher.ts index c4dcb7d9e228..9a468590423e 100644 --- a/packages/cspell-glob/src/GlobMatcher.ts +++ b/packages/cspell-glob/src/GlobMatcher.ts @@ -143,17 +143,6 @@ export class GlobMatcher { ? patterns.split(/\r?\n/g) : [patterns]; const globPatterns = normalizeGlobPatterns(patterns, this.options); - // console.error('GlobMatcher: %o', { - // root, - // dot, - // nested, - // mode, - // nobrace, - // cwd, - // p: patterns.filter(isGlobPatternWithOptionalRoot).filter((g) => g.root), - // }); - - // autoGroupSort(globPatterns); this.patternsNormalizedToRoot = globPatterns .map((g) => normalizeGlobToRoot(g, normalizedRoot, nodePath)) @@ -300,67 +289,3 @@ function buildMatcherFn(patterns: GlobPatternWithRoot[], options: NormalizedGlob }; return fn; } - -// function _joinRegExp(patterns: RegExp[]): RegExp | undefined { -// if (!patterns.length) { -// return undefined; -// } -// const joined = patterns.map((p) => `(?:${p.source})`).join('|'); -// return new RegExp(joined); -// } - -// function autoGroupSort(values: T[]): T[] { -// const keyMap = new Map>(); - -// for (const entry of values) { -// for (const [key, value] of Object.entries(entry)) { -// const valueSet = keyMap.get(key) || new Set(); -// keyMap.set(key, valueSet); -// valueSet.add(value); -// } -// } - -// const countEntries = [...keyMap.entries()] -// .map(([key, valueSet]) => [key, valueSet.size] as const) -// .sort((a, b) => a[1] - b[1] || (a[0] < b[0] ? -1 : 1)); -// const counts = new Map(countEntries); -// const sortedKeys = [...counts.keys()]; - -// function compare(aa: T, bb: T): number { -// const a = aa as Record; -// const b = bb as Record; -// for (const key of sortedKeys) { -// const aValue = `${a[key]}`; -// const bValue = `${b[key]}`; -// if (aValue !== bValue) { -// return aValue < bValue ? -1 : 1; -// } -// } -// return 0; -// } - -// function diff(curr: T, prev: T | undefined) { -// const a = curr as Record; -// const b = (prev || {}) as Record; -// let depth = 0; -// for (const key of sortedKeys) { -// const aValue = `${a[key]}`; -// const bValue = `${b[key]}`; -// if (aValue !== bValue) { -// console.log(key.padStart(depth * 2) + ': ' + aValue); -// } -// depth++; -// } -// } - -// const sorted = [...values].sort(compare); - -// let prev: T | undefined; - -// for (const v of sorted) { -// diff(v, prev); -// prev = v; -// } - -// return sorted; -// }