Skip to content

Commit

Permalink
fix scan test
Browse files Browse the repository at this point in the history
  • Loading branch information
zackradisic committed Apr 16, 2024
1 parent fd508dd commit 4a96c74
Show file tree
Hide file tree
Showing 2 changed files with 18 additions and 12 deletions.
10 changes: 8 additions & 2 deletions src/glob.zig
Original file line number Diff line number Diff line change
Expand Up @@ -1425,13 +1425,19 @@ pub fn GlobWalker_(
switch (c) {
'\\' => {
if (comptime isWindows) {
const end_cp = cp_len;
var end_cp = cp_len;
var end_byte = cursor.i;
// is last char
if (cursor.i + cursor.width == pattern.len) {
end_cp += 1;
end_byte += cursor.width;
}
if (makeComponent(
pattern,
start_cp,
end_cp,
start_byte,
cursor.i,
end_byte,
has_relative_patterns,
)) |component| {
saw_special = saw_special or component.syntax_hint.isSpecialSyntax();
Expand Down
20 changes: 10 additions & 10 deletions test/js/bun/glob/scan.test.ts
Original file line number Diff line number Diff line change
Expand Up @@ -330,14 +330,14 @@ describe("fast-glob e2e tests", async () => {
// const stripAbsoluteDir = (path: string): string => path;

regular.regular.forEach(pattern => {
console.log("ABSOLUTE PATTERN DIR", absolute_pattern_dir);
// console.log("ABSOLUTE PATTERN DIR", absolute_pattern_dir);
const absolutePattern = path.join(absolute_pattern_dir, pattern);
test(`(absolute) patterns regular ${pattern}`, () => {
let entries = buildsnapshot
? prepareEntries(fg.globSync(absolutePattern, { cwd }))
: prepareEntries(Array.from(new Glob(absolutePattern).scanSync({ cwd, followSymlinks: true })));

console.log("PATTERN", absolutePattern, entries);
// console.log("PATTERN", absolutePattern, entries);
expect(entries.map(stripAbsoluteDir)).toMatchSnapshot(`absolute: ${pattern}`);
});

Expand Down Expand Up @@ -540,7 +540,7 @@ test("glob.scan('.')", async () => {
describe("trailing directory separator", async () => {
test("matches directories absolute", async () => {
const tmpdir = TestBuilder.tmpdir();
const files = [`${tmpdir}/bunx-foo`, `${tmpdir}/bunx-bar`, `${tmpdir}/bunx-baz`];
const files = [`${tmpdir}${path.sep}bunx-foo`, `${tmpdir}${path.sep}bunx-bar`, `${tmpdir}${path.sep}bunx-baz`];
await Bun.$`touch ${files[0]}; touch ${files[1]}; mkdir ${files[2]}`;
const glob = new Glob(`${path.join(tmpdir, "bunx-*")}${path.sep}`);
const entries = await Array.fromAsync(glob.scan({ onlyFiles: false }));
Expand All @@ -560,7 +560,7 @@ describe("trailing directory separator", async () => {
describe("absolute path pattern", async () => {
test("works *", async () => {
const tmpdir = TestBuilder.tmpdir();
const files = [`${tmpdir}/bunx-foo`, `${tmpdir}/bunx-bar`, `${tmpdir}/bunx-baz`];
const files = [`${tmpdir}${path.sep}bunx-foo`, `${tmpdir}${path.sep}bunx-bar`, `${tmpdir}${path.sep}bunx-baz`];
await Bun.$`touch ${files[0]}; touch ${files[1]}; mkdir ${files[2]}`;
const glob = new Glob(`${path.join(tmpdir, "bunx-*")}`);
const entries = await Array.fromAsync(glob.scan({ onlyFiles: false }));
Expand All @@ -570,12 +570,12 @@ describe("absolute path pattern", async () => {
test("works **", async () => {
const tmpdir = TestBuilder.tmpdir();
const files = [
`${tmpdir}/bunx-foo`,
`${tmpdir}/bunx-bar`,
`${tmpdir}/bunx-baz`,
`${tmpdir}/bunx-foo/foo`,
`${tmpdir}/bunx-foo/bar`,
`${tmpdir}/bunx-baz/bar`,
`${tmpdir}${path.sep}bunx-foo`,
`${tmpdir}${path.sep}bunx-bar`,
`${tmpdir}${path.sep}bunx-baz`,
`${tmpdir}${path.sep}foo`,
`${tmpdir}${path.sep}bar`,
`${tmpdir}${path.sep}bar`,
];
await Bun.$`mkdir -p ${files.slice(0, 3)}; touch ${files.slice(3)}`;
const glob = new Glob(`${path.join(tmpdir, "**")}${path.sep}`);
Expand Down

0 comments on commit 4a96c74

Please sign in to comment.