diff --git a/.github/workflows/cocoapods.yml b/.github/workflows/cocoapods.yml new file mode 100644 index 0000000..1277659 --- /dev/null +++ b/.github/workflows/cocoapods.yml @@ -0,0 +1,29 @@ +name: cocoapods + +on: + push: + branches: + - master + - hotfix + pull_request: + branches: + - '*' + + +jobs: + build: + + runs-on: macOS-latest + + steps: + - uses: actions/checkout@v1 + - name: Install cocoapods + run: gem install cocoapods + - name: Run mac os x tests + run: xcodebuild -project WebLinking.xcodeproj -scheme WebLinking test -destination "platform=macOS" | xcpretty && exit ${PIPESTATUS[0]} + - name: Upload results + run: bash <(curl -s https://codecov.io/bash) + - name: Run ios tests + run: xcodebuild -project WebLinking.xcodeproj -scheme WebLinking test -destination "name=iPhone 11 Pro" ONLY_ACTIVE_ARCH=NO | xcpretty && exit ${PIPESTATUS[0]} + - name: Run pod lint + run: pod lib lint --quick diff --git a/.github/workflows/spm.yml b/.github/workflows/spm.yml new file mode 100644 index 0000000..5120b40 --- /dev/null +++ b/.github/workflows/spm.yml @@ -0,0 +1,19 @@ +name: SPM + +on: + push: + branches: [ master ] + pull_request: + branches: [ master ] + +jobs: + build: + + runs-on: macos-latest + + steps: + - uses: actions/checkout@v2 + - name: Build + run: swift build -v + - name: Run tests + run: swift test -v diff --git a/.travis.yml b/.travis.yml index 97f436f..b82af4d 100644 --- a/.travis.yml +++ b/.travis.yml @@ -2,8 +2,9 @@ matrix: include: - os: osx language: objective-c - osx_image: xcode9 - + osx_image: xcode9.2 +before_install: +- gem install cocoapods # Lets have latest version script: - set pipefail - xcodebuild -project WebLinking.xcodeproj -scheme WebLinking test -sdk macosx | xcpretty diff --git a/Package.swift b/Package.swift index 9776596..84d0311 100644 --- a/Package.swift +++ b/Package.swift @@ -1,6 +1,20 @@ -import PackageDescription +// swift-tools-version:5.1 +// +// Package.swift +// +import PackageDescription -let package = Package( - name: "WebLinking" -) +let package = Package(name: "WebLinking", + platforms: [.macOS(.v10_12), + .iOS(.v8), + .tvOS(.v9), + .watchOS(.v2)], + products: [.library(name: "WebLinking", + targets: ["WebLinking"])], + targets: [.target(name: "WebLinking", + path: "Sources"), + .testTarget(name: "WebLinkingTests", + dependencies: ["WebLinking"], + path: "Tests")], + swiftLanguageVersions: [.v5]) \ No newline at end of file diff --git a/Sources/WebLinking.swift b/Sources/WebLinking.swift index bfe533d..3f1e916 100644 --- a/Sources/WebLinking.swift +++ b/Sources/WebLinking.swift @@ -14,11 +14,6 @@ public struct Link: Equatable, Hashable { self.parameters = parameters ?? [:] } - /// Returns the hash value - public var hashValue: Int { - return uri.hashValue - } - /// Relation type of the Link. public var relationType: String? { return parameters["rel"] @@ -35,11 +30,6 @@ public struct Link: Equatable, Hashable { } } -/// Returns whether two Link's are equivalent -public func == (lhs: Link, rhs: Link) -> Bool { - return lhs.uri == rhs.uri && lhs.parameters == rhs.parameters -} - // MARK: HTML Element Conversion /// An extension to Link to provide conversion to a HTML element @@ -49,7 +39,7 @@ extension Link { let components = parameters.map { key, value in "\(key)=\"\(value)\"" } + ["href=\"\(uri)\""] - let elements = components.joined(separator: " ") + let elements = components.sorted().joined(separator: " ") return "" } } @@ -63,7 +53,7 @@ extension Link { let components = ["<\(uri)>"] + parameters.map { key, value in "\(key)=\"\(value)\"" } - return components.joined(separator: "; ") + return components.sorted().joined(separator: "; ") } /*** Initialize a Link with a HTTP Link header @@ -181,7 +171,7 @@ func split(_ separator: String) -> (String) -> (String, String) { /// Separate the first element in an array from the rest func takeFirst(_ input: [String]) -> (String, ArraySlice) { - if let first = input.first { + if let first = input.first, first.count > 0 { let items = input[input.indices.suffix(from: (input.startIndex + 1))] return (first, items) } @@ -193,7 +183,7 @@ func takeFirst(_ input: [String]) -> (String, ArraySlice) { func trim(_ lhs: Character, _ rhs: Character) -> (String) -> String { return { input in if input.hasPrefix("\(lhs)") && input.hasSuffix("\(rhs)") { - return String(input[input.characters.index(after: input.startIndex)..; rel=\"stylesheet\"; type=\"text/css\", ; rel=\"stylesheet\"; type=\"text/css\"", + ] + let response = HTTPURLResponse(url: url, statusCode: 200, httpVersion: nil, headerFields: headers)! + let foundLink = response.findLink(["rel": "someImage"]) + + XCTAssertNil(foundLink) + } func testResponseFindLinkRelation() { let url = URL(string: "http://test.com/")! @@ -113,7 +157,44 @@ class LinkHTMLTests: XCTestCase { } func testConversionToHTML() { - let html = "" + let html = "" XCTAssertEqual(link.html, html) } } + + +class LinkWihoutParamentersTests: XCTestCase { + var link:Link! + + override func setUp() { + super.setUp() + link = Link(uri: "/style.css") + } + + func testHasURI() { + XCTAssertEqual(link.uri, "/style.css") + } + + func testHasParameters() { + XCTAssertEqual(link.parameters, [:]) +} +} + + +class EmptyHeaderLinkTests: XCTestCase { + var link:Link! + + override func setUp() { + super.setUp() + link = Link(header: String()) + } + + func testHasURI() { + XCTAssertEqual(link.uri, "") + } + + func testHasParameters() { + XCTAssertEqual(link.parameters, [:]) + } + +} diff --git a/WebLinking.podspec b/WebLinking.podspec index 4033cd9..3841250 100644 --- a/WebLinking.podspec +++ b/WebLinking.podspec @@ -1,6 +1,6 @@ Pod::Spec.new do |spec| spec.name = 'WebLinking' - spec.version = '2.0.0' + spec.version = '2.1.0' spec.summary = 'Swift implementation of Web Linking and Link headers (RFC5988)' spec.homepage = 'https://github.com/kylef/WebLinking.swift' spec.license = { :type => 'MIT', :file => 'LICENSE' } @@ -13,4 +13,5 @@ Pod::Spec.new do |spec| spec.watchos.deployment_target = '2.0' spec.tvos.deployment_target = '9.0' spec.requires_arc = true + spec.swift_version = '5.0' end diff --git a/WebLinking.xcodeproj/project.pbxproj b/WebLinking.xcodeproj/project.pbxproj index c593c22..b00e77c 100644 --- a/WebLinking.xcodeproj/project.pbxproj +++ b/WebLinking.xcodeproj/project.pbxproj @@ -181,16 +181,16 @@ attributes = { LastSwiftMigration = 0700; LastSwiftUpdateCheck = 0700; - LastUpgradeCheck = 0900; + LastUpgradeCheck = 1030; ORGANIZATIONNAME = Cocode; TargetAttributes = { 272A93981A6E67F8004B3785 = { CreatedOnToolsVersion = 6.2; - LastSwiftMigration = 0800; + LastSwiftMigration = 1030; }; 272A93A31A6E67F8004B3785 = { CreatedOnToolsVersion = 6.2; - LastSwiftMigration = 0800; + LastSwiftMigration = 1030; }; }; }; @@ -199,6 +199,7 @@ developmentRegion = English; hasScannedForEncodings = 0; knownRegions = ( + English, en, ); mainGroup = 272A938F1A6E67F8004B3785; @@ -261,6 +262,7 @@ isa = XCBuildConfiguration; buildSettings = { ALWAYS_SEARCH_USER_PATHS = NO; + CLANG_ANALYZER_LOCALIZABILITY_NONLOCALIZED = YES; CLANG_CXX_LANGUAGE_STANDARD = "gnu++0x"; CLANG_CXX_LIBRARY = "libc++"; CLANG_ENABLE_MODULES = YES; @@ -269,12 +271,14 @@ CLANG_WARN_BOOL_CONVERSION = YES; CLANG_WARN_COMMA = YES; CLANG_WARN_CONSTANT_CONVERSION = YES; + CLANG_WARN_DEPRECATED_OBJC_IMPLEMENTATIONS = YES; CLANG_WARN_DIRECT_OBJC_ISA_USAGE = YES_ERROR; CLANG_WARN_EMPTY_BODY = YES; CLANG_WARN_ENUM_CONVERSION = YES; CLANG_WARN_INFINITE_RECURSION = YES; CLANG_WARN_INT_CONVERSION = YES; CLANG_WARN_NON_LITERAL_NULL_CONVERSION = YES; + CLANG_WARN_OBJC_IMPLICIT_RETAIN_SELF = YES; CLANG_WARN_OBJC_LITERAL_CONVERSION = YES; CLANG_WARN_OBJC_ROOT_CLASS = YES_ERROR; CLANG_WARN_RANGE_LOOP_ANALYSIS = YES; @@ -307,7 +311,7 @@ ONLY_ACTIVE_ARCH = YES; SDKROOT = macosx; SWIFT_OPTIMIZATION_LEVEL = "-Onone"; - SWIFT_VERSION = 4.0; + SWIFT_VERSION = 5.0; TVOS_DEPLOYMENT_TARGET = 9.0; VERSIONING_SYSTEM = "apple-generic"; VERSION_INFO_PREFIX = ""; @@ -319,6 +323,7 @@ isa = XCBuildConfiguration; buildSettings = { ALWAYS_SEARCH_USER_PATHS = NO; + CLANG_ANALYZER_LOCALIZABILITY_NONLOCALIZED = YES; CLANG_CXX_LANGUAGE_STANDARD = "gnu++0x"; CLANG_CXX_LIBRARY = "libc++"; CLANG_ENABLE_MODULES = YES; @@ -327,12 +332,14 @@ CLANG_WARN_BOOL_CONVERSION = YES; CLANG_WARN_COMMA = YES; CLANG_WARN_CONSTANT_CONVERSION = YES; + CLANG_WARN_DEPRECATED_OBJC_IMPLEMENTATIONS = YES; CLANG_WARN_DIRECT_OBJC_ISA_USAGE = YES_ERROR; CLANG_WARN_EMPTY_BODY = YES; CLANG_WARN_ENUM_CONVERSION = YES; CLANG_WARN_INFINITE_RECURSION = YES; CLANG_WARN_INT_CONVERSION = YES; CLANG_WARN_NON_LITERAL_NULL_CONVERSION = YES; + CLANG_WARN_OBJC_IMPLICIT_RETAIN_SELF = YES; CLANG_WARN_OBJC_LITERAL_CONVERSION = YES; CLANG_WARN_OBJC_ROOT_CLASS = YES_ERROR; CLANG_WARN_RANGE_LOOP_ANALYSIS = YES; @@ -358,7 +365,7 @@ MTL_ENABLE_DEBUG_INFO = NO; SDKROOT = macosx; SWIFT_OPTIMIZATION_LEVEL = "-Owholemodule"; - SWIFT_VERSION = 4.0; + SWIFT_VERSION = 5.0; TVOS_DEPLOYMENT_TARGET = 9.0; VERSIONING_SYSTEM = "apple-generic"; VERSION_INFO_PREFIX = ""; @@ -383,6 +390,7 @@ PRODUCT_NAME = "$(TARGET_NAME)"; SKIP_INSTALL = YES; SWIFT_OPTIMIZATION_LEVEL = "-Onone"; + SWIFT_VERSION = 5.0; }; name = Debug; }; @@ -402,6 +410,7 @@ PRODUCT_BUNDLE_IDENTIFIER = "org.cocode.$(PRODUCT_NAME:rfc1034identifier)"; PRODUCT_NAME = "$(TARGET_NAME)"; SKIP_INSTALL = YES; + SWIFT_VERSION = 5.0; }; name = Release; }; @@ -417,6 +426,7 @@ INFOPLIST_FILE = Tests/Info.plist; PRODUCT_BUNDLE_IDENTIFIER = "org.cocode.$(PRODUCT_NAME:rfc1034identifier)"; PRODUCT_NAME = "$(TARGET_NAME)"; + SWIFT_VERSION = 5.0; }; name = Debug; }; @@ -428,6 +438,7 @@ INFOPLIST_FILE = Tests/Info.plist; PRODUCT_BUNDLE_IDENTIFIER = "org.cocode.$(PRODUCT_NAME:rfc1034identifier)"; PRODUCT_NAME = "$(TARGET_NAME)"; + SWIFT_VERSION = 5.0; }; name = Release; }; diff --git a/WebLinking.xcodeproj/project.xcworkspace/xcshareddata/IDEWorkspaceChecks.plist b/WebLinking.xcodeproj/project.xcworkspace/xcshareddata/IDEWorkspaceChecks.plist new file mode 100644 index 0000000..18d9810 --- /dev/null +++ b/WebLinking.xcodeproj/project.xcworkspace/xcshareddata/IDEWorkspaceChecks.plist @@ -0,0 +1,8 @@ + + + + + IDEDidComputeMac32BitWarning + + + diff --git a/WebLinking.xcodeproj/project.xcworkspace/xcshareddata/WorkspaceSettings.xcsettings b/WebLinking.xcodeproj/project.xcworkspace/xcshareddata/WorkspaceSettings.xcsettings new file mode 100644 index 0000000..f9b0d7c --- /dev/null +++ b/WebLinking.xcodeproj/project.xcworkspace/xcshareddata/WorkspaceSettings.xcsettings @@ -0,0 +1,8 @@ + + + + + PreviewsEnabled + + + diff --git a/WebLinking.xcodeproj/xcshareddata/xcschemes/WebLinking.xcscheme b/WebLinking.xcodeproj/xcshareddata/xcschemes/WebLinking.xcscheme index 0a1e713..5b3185a 100644 --- a/WebLinking.xcodeproj/xcshareddata/xcschemes/WebLinking.xcscheme +++ b/WebLinking.xcodeproj/xcshareddata/xcschemes/WebLinking.xcscheme @@ -1,6 +1,6 @@ + shouldUseLaunchSchemeArgsEnv = "YES" + codeCoverageEnabled = "YES"> + + + + @@ -54,23 +63,11 @@ - - - - - - - -