Enhance test coverage by adding new cases for file listing, reading, and ripgrep functionalities. Implement tests for hidden files, depth handling, and path normalization in list_files tests. Expand read_file tests to cover line skipping and reading from empty files. Improve ripgrep tests with various pattern matching scenarios, including regex handling and file pattern exclusions.

This commit is contained in:
sebseb7
2025-08-11 23:07:59 +02:00
parent 15d8e96b49
commit b91c4bf5e7
4 changed files with 133 additions and 0 deletions

View File

@@ -139,6 +139,66 @@ function cases() {
expect: { error: /ripgrep error:/ }
});
// 7. No line numbers (n_flag false)
list.push({
name: 'no line numbers',
before: { 'a.txt': 'foo\nbar\nfoo' },
args: async ({ dir }) => ({ pattern: 'foo', filePattern: path.relative(chrootRoot, path.join(dir, '**')), n_flag: false, i_flag: false }),
expect: { equals: [
`${path.relative(chrootRoot, path.join(sandboxRoot, '07-no-line-numbers/a.txt'))}:foo`,
`${path.relative(chrootRoot, path.join(sandboxRoot, '07-no-line-numbers/a.txt'))}:foo`
].join('\n') }
});
// 8. filePattern include-only to exclude .md (tool supports single -g, so include *.txt)
list.push({
name: 'filePattern include-only excludes md',
before: { 'a.txt': 'hit', 'b.md': 'hit' },
args: async ({ dir }) => ({ pattern: 'hit', filePattern: path.relative(chrootRoot, path.join(dir, '**/*.txt')), n_flag: true, i_flag: false }),
expect: { equals: `${path.relative(chrootRoot, path.join(sandboxRoot, '08-filepattern-negation-excludes-md/a.txt'))}:1:hit` }
});
// 9. Empty filePattern searches all (we'll scope to the case dir by pattern and path shape)
list.push({
name: 'empty filePattern searches all',
before: { 'x.js': 'Hello', 'y.txt': 'Hello' },
args: async ({ dir }) => ({ pattern: 'Hello', filePattern: path.relative(chrootRoot, path.join(dir, '**')), n_flag: true, i_flag: false }),
expect: { equals: [
`${path.relative(chrootRoot, path.join(sandboxRoot, '09-empty-filepattern-searches-all/x.js'))}:1:Hello`,
`${path.relative(chrootRoot, path.join(sandboxRoot, '09-empty-filepattern-searches-all/y.txt'))}:1:Hello`
].join('\n') }
});
// 10. Anchored regex
list.push({
name: 'anchored regex',
before: { 'a.txt': 'Hello\nHello world\nHello' },
args: async ({ dir }) => ({ pattern: '^Hello$', filePattern: path.relative(chrootRoot, path.join(dir, '**')), n_flag: true, i_flag: false }),
expect: { equals: [
`${path.relative(chrootRoot, path.join(sandboxRoot, '10-anchored-regex/a.txt'))}:1:Hello`,
`${path.relative(chrootRoot, path.join(sandboxRoot, '10-anchored-regex/a.txt'))}:3:Hello`
].join('\n') }
});
// 11. Special regex characters
list.push({
name: 'special regex characters',
before: { 'a.txt': 'a+b?c\\d and a+b?c\\d' },
args: async ({ dir }) => ({ pattern: 'a\\+b\\?c\\\\d', filePattern: path.relative(chrootRoot, path.join(dir, '**')), n_flag: true, i_flag: false }),
expect: { equals: `${path.relative(chrootRoot, path.join(sandboxRoot, '11-special-regex-characters/a.txt'))}:1:a+b?c\\d and a+b?c\\d` }
});
// 12. Multiple files across dirs deterministic order
list.push({
name: 'multi dirs deterministic',
before: { 'b/b.txt': 'X', 'a/a.txt': 'X' },
args: async ({ dir }) => ({ pattern: '^X$', filePattern: path.relative(chrootRoot, path.join(dir, '**')), n_flag: true, i_flag: false }),
expect: { equals: [
`${path.relative(chrootRoot, path.join(sandboxRoot, '12-multi-dirs-deterministic/a/a.txt'))}:1:X`,
`${path.relative(chrootRoot, path.join(sandboxRoot, '12-multi-dirs-deterministic/b/b.txt'))}:1:X`
].join('\n') }
});
return list;
}