This repository was archived by the owner on Sep 6, 2021. It is now read-only.
-
Notifications
You must be signed in to change notification settings - Fork 7.5k
Expand file tree
/
Copy pathFileUtils-test.js
More file actions
169 lines (134 loc) · 7.97 KB
/
FileUtils-test.js
File metadata and controls
169 lines (134 loc) · 7.97 KB
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
105
106
107
108
109
110
111
112
113
114
115
116
117
118
119
120
121
122
123
124
125
126
127
128
129
130
131
132
133
134
135
136
137
138
139
140
141
142
143
144
145
146
147
148
149
150
151
152
153
154
155
156
157
158
159
160
161
162
163
164
165
166
167
168
169
/*
* Copyright (c) 2013 Adobe Systems Incorporated. All rights reserved.
*
* Permission is hereby granted, free of charge, to any person obtaining a
* copy of this software and associated documentation files (the "Software"),
* to deal in the Software without restriction, including without limitation
* the rights to use, copy, modify, merge, publish, distribute, sublicense,
* and/or sell copies of the Software, and to permit persons to whom the
* Software is furnished to do so, subject to the following conditions:
*
* The above copyright notice and this permission notice shall be included in
* all copies or substantial portions of the Software.
*
* THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR
* IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY,
* FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL THE
* AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER
* LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING
* FROM, OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER
* DEALINGS IN THE SOFTWARE.
*
*/
/*jslint vars: true, plusplus: true, devel: true, nomen: true, indent: 4, maxerr: 50 */
/*global define, describe, it, expect, beforeEach, afterEach, waitsFor, runs, window, $, jasmine, brackets */
/*unittests: FileUtils*/
define(function (require, exports, module) {
"use strict";
var FileUtils = require("file/FileUtils");
describe("FileUtils", function () {
describe("convertWindowsPathToUnixPath", function () {
var origPlatform;
beforeEach(function () {
origPlatform = brackets.platform;
});
afterEach(function () {
brackets.platform = origPlatform;
});
it("should convert a Windows path to a Unix-style path when on Windows", function () {
brackets.platform = "win";
expect(FileUtils.convertWindowsPathToUnixPath("C:\\foo\\bar\\baz.txt")).toBe("C:/foo/bar/baz.txt");
});
it("should not modify a native path when on Mac, even if it has backslashes", function () {
brackets.platform = "mac";
expect(FileUtils.convertWindowsPathToUnixPath("/some/back\\slash/path.txt")).toBe("/some/back\\slash/path.txt");
});
});
describe("getDirectoryPath", function () {
it("should get the parent directory of a normalized win file path", function () {
expect(FileUtils.getDirectoryPath("C:/foo/bar/baz.txt")).toBe("C:/foo/bar/");
});
it("should get the parent directory of a posix file path", function () {
expect(FileUtils.getDirectoryPath("/foo/bar/baz.txt")).toBe("/foo/bar/");
});
it("should return the unchanged directory of a normalized win directory path", function () {
expect(FileUtils.getDirectoryPath("C:/foo/bar/")).toBe("C:/foo/bar/");
});
it("should return the unchanged directory of a posix directory path", function () {
expect(FileUtils.getDirectoryPath("C:/foo/bar/")).toBe("C:/foo/bar/");
});
});
describe("getBaseName", function () {
it("should get the file name of a normalized win file path", function () {
expect(FileUtils.getBaseName("C:/foo/bar/baz.txt")).toBe("baz.txt");
});
it("should get the file name of a posix file path", function () {
expect(FileUtils.getBaseName("/foo/bar/baz.txt")).toBe("baz.txt");
});
it("should return the directory name of a normalized win directory path", function () {
expect(FileUtils.getBaseName("C:/foo/bar/")).toBe("bar");
});
it("should return the directory name of a posix directory path", function () {
expect(FileUtils.getBaseName("C:/foo/bar/")).toBe("bar");
});
it("should return the file name of a path containing #", function () {
expect(FileUtils.getBaseName("C:/foo/bar/#baz/jaz.txt")).toBe("jaz.txt");
expect(FileUtils.getBaseName("C:/foo/bar/baz/#jaz.txt")).toBe("#jaz.txt");
});
it("should return the directory name of a path containing #", function () {
expect(FileUtils.getBaseName("C:/foo/bar/#baz/jaz/")).toBe("jaz");
expect(FileUtils.getBaseName("C:/foo/bar/baz/#jaz/")).toBe("#jaz");
});
});
describe("getFileExtension", function () {
it("should get the extension of a normalized win file path", function () {
expect(FileUtils.getFileExtension("C:/foo/bar/baz.txt")).toBe("txt");
});
it("should get the extension of a posix file path", function () {
expect(FileUtils.getFileExtension("/foo/bar/baz.txt")).toBe("txt");
});
it("should return empty extension for a normalized win directory path", function () {
expect(FileUtils.getFileExtension("C:/foo/bar/")).toBe("");
});
it("should return empty extension for a posix directory path", function () {
expect(FileUtils.getFileExtension("bar")).toBe("");
});
it("should return the extension of a filename containing .", function () {
expect(FileUtils.getFileExtension("C:/foo/bar/.baz/jaz.txt")).toBe("txt");
expect(FileUtils.getFileExtension("foo/bar/baz/.jaz.txt")).toBe("txt");
expect(FileUtils.getFileExtension("foo.bar.baz..jaz.txt")).toBe("txt");
});
});
describe("getSmartFileExtension", function () {
it("should get the extension of a normalized win file path", function () {
expect(FileUtils.getSmartFileExtension("C:/foo/bar/baz.txt")).toBe("txt");
});
it("should get the extension of a posix file path", function () {
expect(FileUtils.getSmartFileExtension("/foo/bar/baz.txt")).toBe("txt");
});
it("should return empty extension for a normalized win directory path", function () {
expect(FileUtils.getSmartFileExtension("C:/foo/bar/")).toBe("");
});
it("should return empty extension for a posix directory path", function () {
expect(FileUtils.getSmartFileExtension("bar")).toBe("");
});
it("should return the extension of a filename containing .", function () {
expect(FileUtils.getSmartFileExtension("C:/foo/bar/.baz/jaz.txt")).toBe("txt");
expect(FileUtils.getSmartFileExtension("foo/bar/baz/.jaz.txt")).toBe("txt");
expect(FileUtils.getSmartFileExtension("foo.bar.baz..jaz.txt")).toBe("txt");
});
it("should return no extension for files with only . as a first character", function () {
expect(FileUtils.getSmartFileExtension("C:/foo/bar/.baz/.jaz")).toBe("");
});
it("should return the extension containing . for known types", function () {
expect(FileUtils.getSmartFileExtension("C:/foo/bar/.baz/jaz.scss.erb")).toBe("scss.erb");
expect(FileUtils.getSmartFileExtension("foo/bar/baz/.jaz.js.erb")).toBe("js.erb");
});
it("should return the extension combined from other known extensions", function () {
expect(FileUtils.getSmartFileExtension("foo.bar.php.js")).toBe("php.js");
expect(FileUtils.getSmartFileExtension("foo.bar.php.html.js")).toBe("php.html.js");
expect(FileUtils.getSmartFileExtension("foo.bar.php.scss.erb")).toBe("php.scss.erb");
});
});
});
});