Skip to content
This repository was archived by the owner on Sep 6, 2021. It is now read-only.
Merged
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
77 changes: 47 additions & 30 deletions test/spec/FileUtils-test.js
Original file line number Diff line number Diff line change
@@ -1,24 +1,24 @@
/*
* 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
* 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,
* 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
* 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 */
Expand All @@ -27,65 +27,82 @@

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("convertToNativePath", function () {
it("should convert windows URL syntax to Windows native path.", function () {
expect(FileUtils.convertToNativePath("/C:/foo/bar/baz.txt")).toBe("C:/foo/bar/baz.txt");
});

it("should not modify a windows non-URL path syntax.", function () {
expect(FileUtils.convertToNativePath("C:/foo/bar/baz.txt")).toBe("C:/foo/bar/baz.txt");
});

it("should not modify a posix path.", function () {
expect(FileUtils.convertToNativePath("/foo/bar/baz.txt")).toBe("/foo/bar/baz.txt");
expect(FileUtils.convertToNativePath("foo/bar/baz.txt")).toBe("foo/bar/baz.txt");
expect(FileUtils.convertToNativePath("/foo/bar/")).toBe("/foo/bar/");
expect(FileUtils.convertToNativePath("foo/bar/")).toBe("foo/bar/");
});
});

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");
});
Expand All @@ -102,19 +119,19 @@ define(function (require, exports, module) {
});

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("");
});
Expand Down