Skip to content

Commit

Permalink
chore(ResourcePathTest.swift) add the ResourcePath test cases
Browse files Browse the repository at this point in the history
  • Loading branch information
ololx committed Aug 22, 2021
1 parent 6159399 commit a8c7c78
Show file tree
Hide file tree
Showing 4 changed files with 191 additions and 1 deletion.
3 changes: 2 additions & 1 deletion commons/FileSystem/ResourcePath.swift
Original file line number Diff line number Diff line change
Expand Up @@ -33,7 +33,6 @@ public class ResourcePath: Path {
var targetPathFragments = other.getPathFragments();

var destinationPath = URL.init(string: "./")!;

for targetPathFragment in targetPathFragments! {
if (!(pathFragments?.contains(targetPathFragment))!) {
break;
Expand All @@ -51,6 +50,8 @@ public class ResourcePath: Path {
destinationPath.appendPathComponent(pathFragment);
}

//pathFragments!.append(contentsOf: targetPathFragments!);

return ResourcePath.of(url: destinationPath);
}

Expand Down
22 changes: 22 additions & 0 deletions quick-symlink-tests/Info.plist
Original file line number Diff line number Diff line change
@@ -0,0 +1,22 @@
<?xml version="1.0" encoding="UTF-8"?>
<!DOCTYPE plist PUBLIC "-//Apple//DTD PLIST 1.0//EN" "http://www.apple.com/DTDs/PropertyList-1.0.dtd">
<plist version="1.0">
<dict>
<key>CFBundleDevelopmentRegion</key>
<string>$(DEVELOPMENT_LANGUAGE)</string>
<key>CFBundleExecutable</key>
<string>$(EXECUTABLE_NAME)</string>
<key>CFBundleIdentifier</key>
<string>$(PRODUCT_BUNDLE_IDENTIFIER)</string>
<key>CFBundleInfoDictionaryVersion</key>
<string>6.0</string>
<key>CFBundleName</key>
<string>$(PRODUCT_NAME)</string>
<key>CFBundlePackageType</key>
<string>BNDL</string>
<key>CFBundleShortVersionString</key>
<string>1.0</string>
<key>CFBundleVersion</key>
<string>1</string>
</dict>
</plist>
49 changes: 49 additions & 0 deletions quick-symlink-tests/ResourcePathTest.swift
Original file line number Diff line number Diff line change
@@ -0,0 +1,49 @@
//
// ResourcePathTest.swift
// quick-symlink-tests
//
// Created by Alexander A. Kropotin on 22/08/2021.
// Copyright © 2021 Alexander A. Kropotin. All rights reserved.
//

import XCTest

class ResourcePathTest: XCTestCase {

func test_toURL_methodExecution_returnedURLIsEqualToInitialURL() {
let uri: URL = URL.init(string: "/a/b/c/d")!;
let path: Path = ResourcePath.of(url: uri);

XCTAssert(path.toUrl() == uri, "The Path URL is not equal to URL");
}

func test_relativize_whenCurrentDirectoryIsNestedToOtherDirectory_thenReturnPathStartingFromOtherDirectory() {
let currentUri: URL = URL.init(string: "/a/b/c/d")!;
let otherUri: URL = URL.init(string: "/a/b")!;

let relativePath: Path = ResourcePath.of(url: currentUri)
.relativize(to: ResourcePath.of(url: otherUri));

XCTAssert(relativePath.toUriString() == "./c/d", "The relative path is wrong");
}

func test_relativize_whenOtherDirectoryIsNestedToCurrentDirectory_thenReturnPathWithOnlyJumpsAboveOtherDirectory() {
let currentUri: URL = URL.init(string: "/a/b")!;
let otherUri: URL = URL.init(string: "/a/b/c/d")!;

let relativePath: Path = ResourcePath.of(url: currentUri)
.relativize(to: ResourcePath.of(url: otherUri));

XCTAssert(relativePath.toUriString() == "./../..", "The relative path is wrong");
}

func test_relativize_whenCurrentDirectoryAndOtherDirectoryAreNestedToGeneralDirectoryy_thenReturnPathWithJumpsAboveOtherDirectoryAndPartOfCurrentDirectory() {
let currentUri: URL = URL.init(string: "/a/b/c1/d1")!;
let otherUri: URL = URL.init(string: "/a/b/c2/d2")!;

let relativePath: Path = ResourcePath.of(url: currentUri)
.relativize(to: ResourcePath.of(url: otherUri));

XCTAssert(relativePath.toUriString() == "./../../c1/d1", "The relative path is wrong");
}
}
118 changes: 118 additions & 0 deletions quick-symlink.xcodeproj/project.pbxproj
Original file line number Diff line number Diff line change
Expand Up @@ -11,6 +11,9 @@
A307B41826D21E39002EEF58 /* Path.swift in Sources */ = {isa = PBXBuildFile; fileRef = A307B41626D21E39002EEF58 /* Path.swift */; };
A307B41A26D22116002EEF58 /* ResourcePath.swift in Sources */ = {isa = PBXBuildFile; fileRef = A307B41926D22116002EEF58 /* ResourcePath.swift */; };
A307B41B26D22116002EEF58 /* ResourcePath.swift in Sources */ = {isa = PBXBuildFile; fileRef = A307B41926D22116002EEF58 /* ResourcePath.swift */; };
A307B42F26D2563B002EEF58 /* ResourcePathTest.swift in Sources */ = {isa = PBXBuildFile; fileRef = A307B42E26D2563B002EEF58 /* ResourcePathTest.swift */; };
A307B43026D257C5002EEF58 /* ResourcePath.swift in Sources */ = {isa = PBXBuildFile; fileRef = A307B41926D22116002EEF58 /* ResourcePath.swift */; };
A307B43126D257CA002EEF58 /* Path.swift in Sources */ = {isa = PBXBuildFile; fileRef = A307B41626D21E39002EEF58 /* Path.swift */; };
A30B9AAB265CA63300ACAA63 /* AppDelegate.swift in Sources */ = {isa = PBXBuildFile; fileRef = A30B9AAA265CA63300ACAA63 /* AppDelegate.swift */; };
A30B9AAD265CA63300ACAA63 /* ViewController.swift in Sources */ = {isa = PBXBuildFile; fileRef = A30B9AAC265CA63300ACAA63 /* ViewController.swift */; };
A30B9AAF265CA63300ACAA63 /* Assets.xcassets in Resources */ = {isa = PBXBuildFile; fileRef = A30B9AAE265CA63300ACAA63 /* Assets.xcassets */; };
Expand All @@ -32,6 +35,13 @@
/* End PBXBuildFile section */

/* Begin PBXContainerItemProxy section */
A307B42926D255FB002EEF58 /* PBXContainerItemProxy */ = {
isa = PBXContainerItemProxy;
containerPortal = A30B9A9F265CA63300ACAA63 /* Project object */;
proxyType = 1;
remoteGlobalIDString = A30B9AA6265CA63300ACAA63;
remoteInfo = "quick-symlink";
};
A30B9AC4265CA68900ACAA63 /* PBXContainerItemProxy */ = {
isa = PBXContainerItemProxy;
containerPortal = A30B9A9F265CA63300ACAA63 /* Project object */;
Expand All @@ -58,6 +68,9 @@
/* Begin PBXFileReference section */
A307B41626D21E39002EEF58 /* Path.swift */ = {isa = PBXFileReference; lastKnownFileType = sourcecode.swift; path = Path.swift; sourceTree = "<group>"; };
A307B41926D22116002EEF58 /* ResourcePath.swift */ = {isa = PBXFileReference; lastKnownFileType = sourcecode.swift; path = ResourcePath.swift; sourceTree = "<group>"; };
A307B42426D255FB002EEF58 /* quick-symlink-tests.xctest */ = {isa = PBXFileReference; explicitFileType = wrapper.cfbundle; includeInIndex = 0; path = "quick-symlink-tests.xctest"; sourceTree = BUILT_PRODUCTS_DIR; };
A307B42826D255FB002EEF58 /* Info.plist */ = {isa = PBXFileReference; lastKnownFileType = text.plist.xml; path = Info.plist; sourceTree = "<group>"; };
A307B42E26D2563B002EEF58 /* ResourcePathTest.swift */ = {isa = PBXFileReference; lastKnownFileType = sourcecode.swift; path = ResourcePathTest.swift; sourceTree = "<group>"; };
A30B9AA7265CA63300ACAA63 /* quick-symlink.app */ = {isa = PBXFileReference; explicitFileType = wrapper.application; includeInIndex = 0; path = "quick-symlink.app"; sourceTree = BUILT_PRODUCTS_DIR; };
A30B9AAA265CA63300ACAA63 /* AppDelegate.swift */ = {isa = PBXFileReference; lastKnownFileType = sourcecode.swift; path = AppDelegate.swift; sourceTree = "<group>"; };
A30B9AAC265CA63300ACAA63 /* ViewController.swift */ = {isa = PBXFileReference; lastKnownFileType = sourcecode.swift; path = ViewController.swift; sourceTree = "<group>"; };
Expand Down Expand Up @@ -86,6 +99,13 @@
/* End PBXFileReference section */

/* Begin PBXFrameworksBuildPhase section */
A307B42126D255FB002EEF58 /* Frameworks */ = {
isa = PBXFrameworksBuildPhase;
buildActionMask = 2147483647;
files = (
);
runOnlyForDeploymentPostprocessing = 0;
};
A30B9AA4265CA63300ACAA63 /* Frameworks */ = {
isa = PBXFrameworksBuildPhase;
buildActionMask = 2147483647;
Expand Down Expand Up @@ -124,13 +144,23 @@
path = FileSystem;
sourceTree = "<group>";
};
A307B42526D255FB002EEF58 /* quick-symlink-tests */ = {
isa = PBXGroup;
children = (
A307B42826D255FB002EEF58 /* Info.plist */,
A307B42E26D2563B002EEF58 /* ResourcePathTest.swift */,
);
path = "quick-symlink-tests";
sourceTree = "<group>";
};
A30B9A9E265CA63300ACAA63 = {
isa = PBXGroup;
children = (
A345C9BD26A0B12C004FBF0F /* commons */,
A3D93EB726A09B5A004E068D /* Localizable.strings */,
A30B9AA9265CA63300ACAA63 /* quick-symlink */,
A30B9ABF265CA68900ACAA63 /* quick-symlink-extension */,
A307B42526D255FB002EEF58 /* quick-symlink-tests */,
A30B9AA8265CA63300ACAA63 /* Products */,
);
sourceTree = "<group>";
Expand All @@ -140,6 +170,7 @@
children = (
A30B9AA7265CA63300ACAA63 /* quick-symlink.app */,
A30B9ABE265CA68900ACAA63 /* quick-symlink-extension.appex */,
A307B42426D255FB002EEF58 /* quick-symlink-tests.xctest */,
);
name = Products;
sourceTree = "<group>";
Expand Down Expand Up @@ -181,6 +212,24 @@
/* End PBXGroup section */

/* Begin PBXNativeTarget section */
A307B42326D255FB002EEF58 /* quick-symlink-tests */ = {
isa = PBXNativeTarget;
buildConfigurationList = A307B42B26D255FB002EEF58 /* Build configuration list for PBXNativeTarget "quick-symlink-tests" */;
buildPhases = (
A307B42026D255FB002EEF58 /* Sources */,
A307B42126D255FB002EEF58 /* Frameworks */,
A307B42226D255FB002EEF58 /* Resources */,
);
buildRules = (
);
dependencies = (
A307B42A26D255FB002EEF58 /* PBXTargetDependency */,
);
name = "quick-symlink-tests";
productName = "quick-symlink-tests";
productReference = A307B42426D255FB002EEF58 /* quick-symlink-tests.xctest */;
productType = "com.apple.product-type.bundle.unit-test";
};
A30B9AA6265CA63300ACAA63 /* quick-symlink */ = {
isa = PBXNativeTarget;
buildConfigurationList = A30B9AB7265CA63300ACAA63 /* Build configuration list for PBXNativeTarget "quick-symlink" */;
Expand Down Expand Up @@ -227,6 +276,11 @@
LastUpgradeCheck = 0920;
ORGANIZATIONNAME = "Alexander A. Kropotin";
TargetAttributes = {
A307B42326D255FB002EEF58 = {
CreatedOnToolsVersion = 9.2;
ProvisioningStyle = Automatic;
TestTargetID = A30B9AA6265CA63300ACAA63;
};
A30B9AA6265CA63300ACAA63 = {
CreatedOnToolsVersion = 9.2;
ProvisioningStyle = Automatic;
Expand Down Expand Up @@ -259,11 +313,19 @@
targets = (
A30B9AA6265CA63300ACAA63 /* quick-symlink */,
A30B9ABD265CA68900ACAA63 /* quick-symlink-extension */,
A307B42326D255FB002EEF58 /* quick-symlink-tests */,
);
};
/* End PBXProject section */

/* Begin PBXResourcesBuildPhase section */
A307B42226D255FB002EEF58 /* Resources */ = {
isa = PBXResourcesBuildPhase;
buildActionMask = 2147483647;
files = (
);
runOnlyForDeploymentPostprocessing = 0;
};
A30B9AA5265CA63300ACAA63 /* Resources */ = {
isa = PBXResourcesBuildPhase;
buildActionMask = 2147483647;
Expand All @@ -285,6 +347,16 @@
/* End PBXResourcesBuildPhase section */

/* Begin PBXSourcesBuildPhase section */
A307B42026D255FB002EEF58 /* Sources */ = {
isa = PBXSourcesBuildPhase;
buildActionMask = 2147483647;
files = (
A307B43026D257C5002EEF58 /* ResourcePath.swift in Sources */,
A307B42F26D2563B002EEF58 /* ResourcePathTest.swift in Sources */,
A307B43126D257CA002EEF58 /* Path.swift in Sources */,
);
runOnlyForDeploymentPostprocessing = 0;
};
A30B9AA3265CA63300ACAA63 /* Sources */ = {
isa = PBXSourcesBuildPhase;
buildActionMask = 2147483647;
Expand Down Expand Up @@ -319,6 +391,11 @@
/* End PBXSourcesBuildPhase section */

/* Begin PBXTargetDependency section */
A307B42A26D255FB002EEF58 /* PBXTargetDependency */ = {
isa = PBXTargetDependency;
target = A30B9AA6265CA63300ACAA63 /* quick-symlink */;
targetProxy = A307B42926D255FB002EEF58 /* PBXContainerItemProxy */;
};
A30B9AC5265CA68900ACAA63 /* PBXTargetDependency */ = {
isa = PBXTargetDependency;
target = A30B9ABD265CA68900ACAA63 /* quick-symlink-extension */;
Expand Down Expand Up @@ -353,6 +430,38 @@
/* End PBXVariantGroup section */

/* Begin XCBuildConfiguration section */
A307B42C26D255FB002EEF58 /* Debug */ = {
isa = XCBuildConfiguration;
buildSettings = {
BUNDLE_LOADER = "$(TEST_HOST)";
CODE_SIGN_STYLE = Automatic;
COMBINE_HIDPI_IMAGES = YES;
INFOPLIST_FILE = "quick-symlink-tests/Info.plist";
LD_RUNPATH_SEARCH_PATHS = "$(inherited) @executable_path/../Frameworks @loader_path/../Frameworks";
MACOSX_DEPLOYMENT_TARGET = 10.14;
PRODUCT_BUNDLE_IDENTIFIER = "org.ololx.quick-symlink-tests";
PRODUCT_NAME = "$(TARGET_NAME)";
SWIFT_VERSION = 4.0;
TEST_HOST = "$(BUILT_PRODUCTS_DIR)/quick-symlink.app/Contents/MacOS/quick-symlink";
};
name = Debug;
};
A307B42D26D255FB002EEF58 /* Release */ = {
isa = XCBuildConfiguration;
buildSettings = {
BUNDLE_LOADER = "$(TEST_HOST)";
CODE_SIGN_STYLE = Automatic;
COMBINE_HIDPI_IMAGES = YES;
INFOPLIST_FILE = "quick-symlink-tests/Info.plist";
LD_RUNPATH_SEARCH_PATHS = "$(inherited) @executable_path/../Frameworks @loader_path/../Frameworks";
MACOSX_DEPLOYMENT_TARGET = 10.14;
PRODUCT_BUNDLE_IDENTIFIER = "org.ololx.quick-symlink-tests";
PRODUCT_NAME = "$(TARGET_NAME)";
SWIFT_VERSION = 4.0;
TEST_HOST = "$(BUILT_PRODUCTS_DIR)/quick-symlink.app/Contents/MacOS/quick-symlink";
};
name = Release;
};
A30B9AB5265CA63300ACAA63 /* Debug */ = {
isa = XCBuildConfiguration;
buildSettings = {
Expand Down Expand Up @@ -530,6 +639,15 @@
/* End XCBuildConfiguration section */

/* Begin XCConfigurationList section */
A307B42B26D255FB002EEF58 /* Build configuration list for PBXNativeTarget "quick-symlink-tests" */ = {
isa = XCConfigurationList;
buildConfigurations = (
A307B42C26D255FB002EEF58 /* Debug */,
A307B42D26D255FB002EEF58 /* Release */,
);
defaultConfigurationIsVisible = 0;
defaultConfigurationName = Release;
};
A30B9AA2265CA63300ACAA63 /* Build configuration list for PBXProject "quick-symlink" */ = {
isa = XCConfigurationList;
buildConfigurations = (
Expand Down

0 comments on commit a8c7c78

Please sign in to comment.