Skip to content

Commit

Permalink
Fix glob_test.ts
Browse files Browse the repository at this point in the history
  • Loading branch information
ry committed May 13, 2019
1 parent 1b67eca commit c97e2fa
Show file tree
Hide file tree
Showing 2 changed files with 14 additions and 32 deletions.
42 changes: 12 additions & 30 deletions fs/glob_test.ts
Original file line number Diff line number Diff line change
@@ -1,32 +1,12 @@
const { mkdir, open } = Deno;
type FileInfo = Deno.FileInfo;
import { test } from "../testing/mod.ts";
import { test, runIfMain } from "../testing/mod.ts";
import { assertEquals } from "../testing/asserts.ts";
import { glob } from "./glob.ts";
import { join } from "./path.ts";
import { testWalk } from "./walk_test.ts";
import { walk, walkSync, WalkOptions } from "./walk.ts";

async function touch(path: string): Promise<void> {
await open(path, "w");
}

async function walkArray(
dirname: string = ".",
options: WalkOptions = {}
): Promise<string[]> {
const arr: string[] = [];
for await (const f of walk(dirname, { ...options })) {
arr.push(f.path.replace(/\\/g, "/"));
}
arr.sort();
const arrSync = Array.from(
walkSync(dirname, options),
(f: FileInfo): string => f.path.replace(/\\/g, "/")
).sort();
assertEquals(arr, arrSync);
return arr;
}
import { touch, walkArray } from "./walk_test.ts";

test({
name: "glob: glob to regex",
Expand Down Expand Up @@ -77,7 +57,7 @@ testWalk(
async function globInWalk(): Promise<void> {
const arr = await walkArray(".", { match: [glob("*.ts")] });
assertEquals(arr.length, 1);
assertEquals(arr[0], "./a/x.ts");
assertEquals(arr[0], "a/x.ts");
}
);

Expand All @@ -92,8 +72,8 @@ testWalk(
async function globInWalkWildcardFiles(): Promise<void> {
const arr = await walkArray(".", { match: [glob("*.ts")] });
assertEquals(arr.length, 2);
assertEquals(arr[0], "./a/x.ts");
assertEquals(arr[1], "./b/z.ts");
assertEquals(arr[0], "a/x.ts");
assertEquals(arr[1], "b/z.ts");
}
);

Expand All @@ -113,7 +93,7 @@ testWalk(
]
});
assertEquals(arr.length, 1);
assertEquals(arr[0], "./a/yo/x.ts");
assertEquals(arr[0], "a/yo/x.ts");
}
);

Expand All @@ -137,8 +117,8 @@ testWalk(
]
});
assertEquals(arr.length, 2);
assertEquals(arr[0], "./a/deno/x.ts");
assertEquals(arr[1], "./a/raptor/x.ts");
assertEquals(arr[0], "a/deno/x.ts");
assertEquals(arr[1], "a/raptor/x.ts");
}
);

Expand All @@ -154,7 +134,9 @@ testWalk(
});
console.log(arr);
assertEquals(arr.length, 2);
assertEquals(arr[0], "./x.js");
assertEquals(arr[1], "./x.ts");
assertEquals(arr[0], "x.js");
assertEquals(arr[1], "x.ts");
}
);

runIfMain(import.meta);
4 changes: 2 additions & 2 deletions fs/walk_test.ts
Original file line number Diff line number Diff line change
Expand Up @@ -30,7 +30,7 @@ function normalize([filename, _info]: [string, FileInfo]): string {
return filename.replace(/\\/g, "/")
}

async function walkArray(
export async function walkArray(
root: string = ".",
options: WalkOptions = {}
): Promise<string[]> {
Expand All @@ -48,7 +48,7 @@ async function walkArray(
return arr;
}

async function touch(path: string): Promise<void> {
export async function touch(path: string): Promise<void> {
await open(path, "w");
}

Expand Down

0 comments on commit c97e2fa

Please sign in to comment.