From a8c7c78e6c6c0066d56a62b1a40cbdbc1ca6c3d3 Mon Sep 17 00:00:00 2001 From: "Alexander A. Kropotin" Date: Sun, 22 Aug 2021 19:46:59 +0500 Subject: [PATCH] chore(ResourcePathTest.swift) add the ResourcePath test cases --- commons/FileSystem/ResourcePath.swift | 3 +- quick-symlink-tests/Info.plist | 22 ++++ quick-symlink-tests/ResourcePathTest.swift | 49 +++++++++ quick-symlink.xcodeproj/project.pbxproj | 118 +++++++++++++++++++++ 4 files changed, 191 insertions(+), 1 deletion(-) create mode 100644 quick-symlink-tests/Info.plist create mode 100644 quick-symlink-tests/ResourcePathTest.swift diff --git a/commons/FileSystem/ResourcePath.swift b/commons/FileSystem/ResourcePath.swift index 2417bf7..fa4fb6c 100644 --- a/commons/FileSystem/ResourcePath.swift +++ b/commons/FileSystem/ResourcePath.swift @@ -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; @@ -51,6 +50,8 @@ public class ResourcePath: Path { destinationPath.appendPathComponent(pathFragment); } + //pathFragments!.append(contentsOf: targetPathFragments!); + return ResourcePath.of(url: destinationPath); } diff --git a/quick-symlink-tests/Info.plist b/quick-symlink-tests/Info.plist new file mode 100644 index 0000000..6c40a6c --- /dev/null +++ b/quick-symlink-tests/Info.plist @@ -0,0 +1,22 @@ + + + + + CFBundleDevelopmentRegion + $(DEVELOPMENT_LANGUAGE) + CFBundleExecutable + $(EXECUTABLE_NAME) + CFBundleIdentifier + $(PRODUCT_BUNDLE_IDENTIFIER) + CFBundleInfoDictionaryVersion + 6.0 + CFBundleName + $(PRODUCT_NAME) + CFBundlePackageType + BNDL + CFBundleShortVersionString + 1.0 + CFBundleVersion + 1 + + diff --git a/quick-symlink-tests/ResourcePathTest.swift b/quick-symlink-tests/ResourcePathTest.swift new file mode 100644 index 0000000..40f4b7e --- /dev/null +++ b/quick-symlink-tests/ResourcePathTest.swift @@ -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"); + } +} diff --git a/quick-symlink.xcodeproj/project.pbxproj b/quick-symlink.xcodeproj/project.pbxproj index d1a60af..1de801c 100644 --- a/quick-symlink.xcodeproj/project.pbxproj +++ b/quick-symlink.xcodeproj/project.pbxproj @@ -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 */; }; @@ -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 */; @@ -58,6 +68,9 @@ /* Begin PBXFileReference section */ A307B41626D21E39002EEF58 /* Path.swift */ = {isa = PBXFileReference; lastKnownFileType = sourcecode.swift; path = Path.swift; sourceTree = ""; }; A307B41926D22116002EEF58 /* ResourcePath.swift */ = {isa = PBXFileReference; lastKnownFileType = sourcecode.swift; path = ResourcePath.swift; sourceTree = ""; }; + 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 = ""; }; + A307B42E26D2563B002EEF58 /* ResourcePathTest.swift */ = {isa = PBXFileReference; lastKnownFileType = sourcecode.swift; path = ResourcePathTest.swift; sourceTree = ""; }; 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 = ""; }; A30B9AAC265CA63300ACAA63 /* ViewController.swift */ = {isa = PBXFileReference; lastKnownFileType = sourcecode.swift; path = ViewController.swift; sourceTree = ""; }; @@ -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; @@ -124,6 +144,15 @@ path = FileSystem; sourceTree = ""; }; + A307B42526D255FB002EEF58 /* quick-symlink-tests */ = { + isa = PBXGroup; + children = ( + A307B42826D255FB002EEF58 /* Info.plist */, + A307B42E26D2563B002EEF58 /* ResourcePathTest.swift */, + ); + path = "quick-symlink-tests"; + sourceTree = ""; + }; A30B9A9E265CA63300ACAA63 = { isa = PBXGroup; children = ( @@ -131,6 +160,7 @@ A3D93EB726A09B5A004E068D /* Localizable.strings */, A30B9AA9265CA63300ACAA63 /* quick-symlink */, A30B9ABF265CA68900ACAA63 /* quick-symlink-extension */, + A307B42526D255FB002EEF58 /* quick-symlink-tests */, A30B9AA8265CA63300ACAA63 /* Products */, ); sourceTree = ""; @@ -140,6 +170,7 @@ children = ( A30B9AA7265CA63300ACAA63 /* quick-symlink.app */, A30B9ABE265CA68900ACAA63 /* quick-symlink-extension.appex */, + A307B42426D255FB002EEF58 /* quick-symlink-tests.xctest */, ); name = Products; sourceTree = ""; @@ -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" */; @@ -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; @@ -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; @@ -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; @@ -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 */; @@ -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 = { @@ -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 = (