Skip to content

Commit

Permalink
Update Tests
Browse files Browse the repository at this point in the history
  • Loading branch information
Jason3S committed Jun 29, 2024
1 parent 4cc7a56 commit 345736c
Show file tree
Hide file tree
Showing 2 changed files with 9 additions and 83 deletions.
17 changes: 9 additions & 8 deletions packages/cspell-glob/src/GlobMatcher.test.ts
Original file line number Diff line number Diff line change
Expand Up @@ -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'],
Expand Down
75 changes: 0 additions & 75 deletions packages/cspell-glob/src/GlobMatcher.ts
Original file line number Diff line number Diff line change
Expand Up @@ -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))
Expand Down Expand Up @@ -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<T extends object>(values: T[]): T[] {
// const keyMap = new Map<string, Set<unknown>>();

// 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<string, unknown>;
// const b = bb as Record<string, unknown>;
// 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<string, unknown>;
// const b = (prev || {}) as Record<string, unknown>;
// 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;
// }

0 comments on commit 345736c

Please sign in to comment.