deno.land / std@0.166.0 / path / basename_test.ts

basename_test.ts
نووسراو ببینە
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
// Copyright 2018-2022 the Deno authors. All rights reserved. MIT license.// Copyright the Browserify authors. MIT License.// Ported from https://github.com/browserify/path-browserify/import { assertEquals } from "../testing/asserts.ts";import * as path from "./mod.ts";
Deno.test("basename", function () { assertEquals(path.basename(".js", ".js"), ""); assertEquals(path.basename(""), ""); assertEquals(path.basename("/dir/basename.ext"), "basename.ext"); assertEquals(path.basename("/basename.ext"), "basename.ext"); assertEquals(path.basename("basename.ext"), "basename.ext"); assertEquals(path.basename("basename.ext/"), "basename.ext"); assertEquals(path.basename("basename.ext//"), "basename.ext"); assertEquals(path.basename("aaa/bbb", "/bbb"), "bbb"); assertEquals(path.basename("aaa/bbb", "a/bbb"), "bbb"); assertEquals(path.basename("aaa/bbb", "bbb"), "bbb"); assertEquals(path.basename("aaa/bbb//", "bbb"), "bbb"); assertEquals(path.basename("aaa/bbb", "bb"), "b"); assertEquals(path.basename("aaa/bbb", "b"), "bb"); assertEquals(path.basename("/aaa/bbb", "/bbb"), "bbb"); assertEquals(path.basename("/aaa/bbb", "a/bbb"), "bbb"); assertEquals(path.basename("/aaa/bbb", "bbb"), "bbb"); assertEquals(path.basename("/aaa/bbb//", "bbb"), "bbb"); assertEquals(path.basename("/aaa/bbb", "bb"), "b"); assertEquals(path.basename("/aaa/bbb", "b"), "bb"); assertEquals(path.basename("/aaa/bbb"), "bbb"); assertEquals(path.basename("/aaa/"), "aaa"); assertEquals(path.basename("/aaa/b"), "b"); assertEquals(path.basename("/a/b"), "b"); assertEquals(path.basename("//a"), "a");
// On unix a backslash is just treated as any other character. assertEquals( path.posix.basename("\\dir\\basename.ext"), "\\dir\\basename.ext", ); assertEquals(path.posix.basename("\\basename.ext"), "\\basename.ext"); assertEquals(path.posix.basename("basename.ext"), "basename.ext"); assertEquals(path.posix.basename("basename.ext\\"), "basename.ext\\"); assertEquals(path.posix.basename("basename.ext\\\\"), "basename.ext\\\\"); assertEquals(path.posix.basename("foo"), "foo");
// POSIX filenames may include control characters const controlCharFilename = "Icon" + String.fromCharCode(13); assertEquals( path.posix.basename("/a/b/" + controlCharFilename), controlCharFilename, );});
Deno.test("basenameWin32", function () { assertEquals(path.win32.basename("\\dir\\basename.ext"), "basename.ext"); assertEquals(path.win32.basename("\\basename.ext"), "basename.ext"); assertEquals(path.win32.basename("basename.ext"), "basename.ext"); assertEquals(path.win32.basename("basename.ext\\"), "basename.ext"); assertEquals(path.win32.basename("basename.ext\\\\"), "basename.ext"); assertEquals(path.win32.basename("foo"), "foo"); assertEquals(path.win32.basename("aaa\\bbb", "\\bbb"), "bbb"); assertEquals(path.win32.basename("aaa\\bbb", "a\\bbb"), "bbb"); assertEquals(path.win32.basename("aaa\\bbb", "bbb"), "bbb"); assertEquals(path.win32.basename("aaa\\bbb\\\\\\\\", "bbb"), "bbb"); assertEquals(path.win32.basename("aaa\\bbb", "bb"), "b"); assertEquals(path.win32.basename("aaa\\bbb", "b"), "bb"); assertEquals(path.win32.basename("C:"), ""); assertEquals(path.win32.basename("C:."), "."); assertEquals(path.win32.basename("C:\\"), ""); assertEquals(path.win32.basename("C:\\dir\\base.ext"), "base.ext"); assertEquals(path.win32.basename("C:\\basename.ext"), "basename.ext"); assertEquals(path.win32.basename("C:basename.ext"), "basename.ext"); assertEquals(path.win32.basename("C:basename.ext\\"), "basename.ext"); assertEquals(path.win32.basename("C:basename.ext\\\\"), "basename.ext"); assertEquals(path.win32.basename("C:foo"), "foo"); assertEquals(path.win32.basename("file:stream"), "file:stream");});
std
Deno standard library
GitHub Repositorydenoland/deno_std
GitHub Stars
2458

Version Info

Tagged at
2 months ago