deno.land / std@0.224.0 / path / dirname_test.ts

dirname_test.ts
View Documentation
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
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
103
104
// Copyright 2018-2024 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 "../assert/mod.ts";import { dirname } from "./dirname.ts";import * as posix from "./posix/mod.ts";import * as windows from "./windows/mod.ts";
// Test suite from "GNU core utilities"// https://github.com/coreutils/coreutils/blob/master/tests/misc/dirname.plconst COREUTILS_TESTSUITE = [ ["d/f", "d"], ["/d/f", "/d"], ["d/f/", "d"], ["d/f//", "d"], ["f", "."], ["/", "/"], ["//", "/"], ["///", "/"], ["//a//", "/"], ["///a///", "/"], ["///a///b", "///a"], ["///a//b/", "///a"], ["", "."],] as const;
const POSIX_TESTSUITE = [ ["/a/b/", "/a"], ["/a/b", "/a"], ["/a", "/"], ["", "."], ["/", "/"], ["////", "/"], ["//a", "/"], ["foo", "."],] as const;
const WINDOWS_TESTSUITE = [ ["c:\\", "c:\\"], ["c:\\foo", "c:\\"], ["c:\\foo\\", "c:\\"], ["c:\\foo\\bar", "c:\\foo"], ["c:\\foo\\bar\\", "c:\\foo"], ["c:\\foo\\bar\\baz", "c:\\foo\\bar"], ["\\", "\\"], ["\\foo", "\\"], ["\\foo\\", "\\"], ["\\foo\\bar", "\\foo"], ["\\foo\\bar\\", "\\foo"], ["\\foo\\bar\\baz", "\\foo\\bar"], ["c:", "c:"], ["c:foo", "c:"], ["c:foo\\", "c:"], ["c:foo\\bar", "c:foo"], ["c:foo\\bar\\", "c:foo"], ["c:foo\\bar\\baz", "c:foo\\bar"], ["file:stream", "."], ["dir\\file:stream", "dir"], ["\\\\unc\\share", "\\\\unc\\share"], ["\\\\unc\\share\\foo", "\\\\unc\\share\\"], ["\\\\unc\\share\\foo\\", "\\\\unc\\share\\"], ["\\\\unc\\share\\foo\\bar", "\\\\unc\\share\\foo"], ["\\\\unc\\share\\foo\\bar\\", "\\\\unc\\share\\foo"], ["\\\\unc\\share\\foo\\bar\\baz", "\\\\unc\\share\\foo\\bar"], ["/a/b/", "/a"], ["/a/b", "/a"], ["/a", "/"], ["", "."], ["/", "/"], ["////", "/"], ["foo", "."],] as const;
Deno.test("posix.dirname()", function () { for (const [name, expected] of COREUTILS_TESTSUITE) { assertEquals(dirname(name), expected); }
for (const [name, expected] of POSIX_TESTSUITE) { assertEquals(posix.dirname(name), expected); }
// POSIX treats backslash as any other character. assertEquals(posix.dirname("\\foo/bar"), "\\foo"); assertEquals(posix.dirname("\\/foo/bar"), "\\/foo"); assertEquals(posix.dirname("/foo/bar\\baz/qux"), "/foo/bar\\baz"); assertEquals(posix.dirname("/foo/bar/baz\\"), "/foo/bar");});
Deno.test("windows.dirname()", function () { for (const [name, expected] of WINDOWS_TESTSUITE) { assertEquals(windows.dirname(name), expected); }
// windows should pass all "forward slash" posix tests as well. for (const [name, expected] of COREUTILS_TESTSUITE) { assertEquals(windows.dirname(name), expected); }
for (const [name, expected] of POSIX_TESTSUITE) { assertEquals(windows.dirname(name), expected); }});
std

Version Info

Tagged at
6 months ago