From 4a96c741392c94827240d317fbdd0af097d33baf Mon Sep 17 00:00:00 2001 From: Zack Radisic Date: Tue, 16 Apr 2024 15:49:08 -0700 Subject: [PATCH] fix scan test --- src/glob.zig | 10 ++++++++-- test/js/bun/glob/scan.test.ts | 20 ++++++++++---------- 2 files changed, 18 insertions(+), 12 deletions(-) diff --git a/src/glob.zig b/src/glob.zig index 3690a3fc5f5de5..ed2fe92e2822fc 100644 --- a/src/glob.zig +++ b/src/glob.zig @@ -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(); diff --git a/test/js/bun/glob/scan.test.ts b/test/js/bun/glob/scan.test.ts index d999b625cdb2c5..05be353d0dc514 100644 --- a/test/js/bun/glob/scan.test.ts +++ b/test/js/bun/glob/scan.test.ts @@ -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}`); }); @@ -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 })); @@ -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 })); @@ -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}`);