diff options
| author | 木杉 <zhmushan@qq.com> | 2018-12-19 10:29:39 +0800 |
|---|---|---|
| committer | Ryan Dahl <ry@tinyclouds.org> | 2018-12-18 21:29:39 -0500 |
| commit | 2d58da520fffaeaee1bceeb33b6e3dc339ea68a3 (patch) | |
| tree | b6b8beb08e828b45ca51fb5bbc44330d45b62df5 /path/zero_length_strings_test.ts | |
| parent | 3c8f564ab8c3087bac8256723aed9572faba756f (diff) | |
migrate deno_path to deno_std (denoland/deno_std#26)
Previously https://github.com/zhmushan/deno_path
Original: https://github.com/denoland/deno_std/commit/1a35f9daf5aa1c10c61d62cccbe7f9ae3c615a0e
Diffstat (limited to 'path/zero_length_strings_test.ts')
| -rw-r--r-- | path/zero_length_strings_test.ts | 46 |
1 files changed, 46 insertions, 0 deletions
diff --git a/path/zero_length_strings_test.ts b/path/zero_length_strings_test.ts new file mode 100644 index 000000000..dec9696d3 --- /dev/null +++ b/path/zero_length_strings_test.ts @@ -0,0 +1,46 @@ +// Copyright the Browserify authors. MIT License. +// Ported from https://github.com/browserify/path-browserify/ + +import { test, assertEqual } from "https://deno.land/x/testing/testing.ts"; +import * as path from "./index"; +import { cwd } from "deno"; + +const pwd = cwd(); + +test(function joinZeroLength() { + // join will internally ignore all the zero-length strings and it will return + // '.' if the joined string is a zero-length string. + assertEqual(path.posix.join(""), "."); + assertEqual(path.posix.join("", ""), "."); + if (path.win32) assertEqual(path.win32.join(""), "."); + if (path.win32) assertEqual(path.win32.join("", ""), "."); + assertEqual(path.join(pwd), pwd); + assertEqual(path.join(pwd, ""), pwd); +}); + +test(function normalizeZeroLength() { + // normalize will return '.' if the input is a zero-length string + assertEqual(path.posix.normalize(""), "."); + if (path.win32) assertEqual(path.win32.normalize(""), "."); + assertEqual(path.normalize(pwd), pwd); +}); + +test(function isAbsoluteZeroLength() { + // Since '' is not a valid path in any of the common environments, return false + assertEqual(path.posix.isAbsolute(""), false); + if (path.win32) assertEqual(path.win32.isAbsolute(""), false); +}); + +test(function resolveZeroLength() { + // resolve, internally ignores all the zero-length strings and returns the + // current working directory + assertEqual(path.resolve(""), pwd); + assertEqual(path.resolve("", ""), pwd); +}); + +test(function relativeZeroLength() { + // relative, internally calls resolve. So, '' is actually the current directory + assertEqual(path.relative("", pwd), ""); + assertEqual(path.relative(pwd, ""), ""); + assertEqual(path.relative(pwd, pwd), ""); +}); |
