diff options
author | Yoshiya Hinosawa <stibium121@gmail.com> | 2019-01-18 05:09:44 +0900 |
---|---|---|
committer | Ryan Dahl <ry@tinyclouds.org> | 2019-01-17 15:09:44 -0500 |
commit | f19622e7681b7753788137706e535f72c3ebb38e (patch) | |
tree | 0cd5261230f895359ca479d2b2234a56f137e924 /tools/util_test.ts | |
parent | befc6b2e7650af09f81562cd306a6f5d3f46dc21 (diff) |
Rewrite tools/format.py in deno (#1528)
Note: findFiles and findFilesWalk are borrowed from the previous
attempt of @pseudo-su (#1434)
Diffstat (limited to 'tools/util_test.ts')
-rw-r--r-- | tools/util_test.ts | 49 |
1 files changed, 49 insertions, 0 deletions
diff --git a/tools/util_test.ts b/tools/util_test.ts new file mode 100644 index 000000000..79868b440 --- /dev/null +++ b/tools/util_test.ts @@ -0,0 +1,49 @@ +// Copyright 2018-2019 the Deno authors. All rights reserved. MIT license. +import { test, assertEqual } from "../js/test_util.ts"; +import { findFiles } from "./util.ts"; + +const testDir = "tools/testdata/find_files_testdata"; + +// Sorts and replace backslashes with slashes. +const normalize = files => files.map(f => f.replace(/\\/g, "/")).sort(); + +test(function testFindFiles() { + const files = findFiles([testDir], [".ts", ".md"]); + assertEqual(normalize(files), [ + `${testDir}/bar.md`, + `${testDir}/bar.ts`, + `${testDir}/foo.md`, + `${testDir}/foo.ts`, + `${testDir}/subdir0/bar.ts`, + `${testDir}/subdir0/foo.ts`, + `${testDir}/subdir0/subdir0/bar.ts`, + `${testDir}/subdir0/subdir0/foo.ts`, + `${testDir}/subdir1/bar.ts`, + `${testDir}/subdir1/foo.ts` + ]); +}); + +test(function testFindFilesDepth() { + const files = findFiles([testDir], [".ts", ".md"], { depth: 1 }); + assertEqual(normalize(files), [ + `${testDir}/bar.md`, + `${testDir}/bar.ts`, + `${testDir}/foo.md`, + `${testDir}/foo.ts` + ]); +}); + +test(function testFindFilesSkip() { + const files = findFiles([testDir], [".ts", ".md"], { + skip: ["foo.md", "subdir1"] + }); + assertEqual(normalize(files), [ + `${testDir}/bar.md`, + `${testDir}/bar.ts`, + `${testDir}/foo.ts`, + `${testDir}/subdir0/bar.ts`, + `${testDir}/subdir0/foo.ts`, + `${testDir}/subdir0/subdir0/bar.ts`, + `${testDir}/subdir0/subdir0/foo.ts` + ]); +}); |