mirror of
https://github.com/denoland/std.git
synced 2024-11-22 04:59:05 +00:00
27 lines
1009 B
TypeScript
27 lines
1009 B
TypeScript
// Copyright 2018-2024 the Deno authors. All rights reserved. MIT license.
|
|
|
|
import { assertEquals } from "@std/assert";
|
|
import { CHAR_FORWARD_SLASH } from "./constants.ts";
|
|
import { normalizeString } from "./normalize_string.ts";
|
|
|
|
function isSeparator(code: number): boolean {
|
|
return code === CHAR_FORWARD_SLASH;
|
|
}
|
|
|
|
Deno.test("normalizeSring()", () => {
|
|
assertEquals(normalizeString("", true, "/", isSeparator), "");
|
|
assertEquals(normalizeString("", false, "/", isSeparator), "");
|
|
assertEquals(normalizeString("a/../b", true, "/", isSeparator), "b");
|
|
assertEquals(normalizeString("foo/bar/", true, "/", isSeparator), "foo/bar");
|
|
assertEquals(normalizeString("/foo/bar", true, "/", isSeparator), "foo/bar");
|
|
assertEquals(normalizeString("./foo/bar", true, "/", isSeparator), "foo/bar");
|
|
assertEquals(
|
|
normalizeString("../foo/bar/baz/", true, "/", isSeparator),
|
|
"../foo/bar/baz",
|
|
);
|
|
assertEquals(
|
|
normalizeString("/foo/../../bar", true, "/", isSeparator),
|
|
"../bar",
|
|
);
|
|
});
|