From 2c89f5b85f4fa39efdd8e7f55b4339676f1588c6 Mon Sep 17 00:00:00 2001 From: RandomHashTags Date: Fri, 4 Nov 2022 12:49:46 -0500 Subject: [PATCH] `Country` bug fix relating to additional keywords --- Sources/SwiftSovereignStates/Country.swift | 4 ++-- Sources/SwiftSovereignStates/SovereignState.swift | 7 +++++-- Tests/SwiftSovereignStatesTests/SwiftSovereignStates.swift | 2 ++ 3 files changed, 9 insertions(+), 4 deletions(-) diff --git a/Sources/SwiftSovereignStates/Country.swift b/Sources/SwiftSovereignStates/Country.swift index dc5ecde..3895000 100644 --- a/Sources/SwiftSovereignStates/Country.swift +++ b/Sources/SwiftSovereignStates/Country.swift @@ -318,11 +318,11 @@ public enum Country : String, CaseIterable, SovereignState { } public func getAdditionalKeywords() -> [String]? { - var keywords:[String] = [String]() + var keywords:[String] = getSovereignStateAdditionalKeywords() ?? [String]() if let parentISOAlpha2:String = getISOAlpha2ParentGroup() { keywords.append(parentISOAlpha2) } - return keywords + return keywords.isEmpty ? nil : keywords } public func getWikipediaURL() -> String { diff --git a/Sources/SwiftSovereignStates/SovereignState.swift b/Sources/SwiftSovereignStates/SovereignState.swift index b054121..3154e75 100644 --- a/Sources/SwiftSovereignStates/SovereignState.swift +++ b/Sources/SwiftSovereignStates/SovereignState.swift @@ -14,7 +14,7 @@ public protocol SovereignState : SovereignRegion { func getISOAlpha3() -> String? } public extension SovereignState { - func getAdditionalKeywords() -> [String]? { + func getSovereignStateAdditionalKeywords() -> [String]? { var keywords:[String] = [String]() if let isoAlpha2:String = getISOAlpha2() { keywords.append(isoAlpha2) @@ -22,6 +22,9 @@ public extension SovereignState { if let isoAlpha3:String = getISOAlpha3() { keywords.append(isoAlpha3) } - return keywords + return keywords.isEmpty ? nil : keywords + } + func getAdditionalKeywords() -> [String]? { + return getSovereignStateAdditionalKeywords() } } diff --git a/Tests/SwiftSovereignStatesTests/SwiftSovereignStates.swift b/Tests/SwiftSovereignStatesTests/SwiftSovereignStates.swift index 4fe9ee6..b965a45 100644 --- a/Tests/SwiftSovereignStatesTests/SwiftSovereignStates.swift +++ b/Tests/SwiftSovereignStatesTests/SwiftSovereignStates.swift @@ -247,6 +247,8 @@ final class SwiftSovereignStatesTests: XCTestCase { print("SwiftSovereignStatesTests;testCountryMentions;shouldn't be=[" + notMentioned.map({ $0.getIdentifier() }).joined(separator: ",") + "]") } XCTAssert(mentioned.count == targetCountries.count) + + XCTAssert(Country.valueOf("USA") != nil) } private func testSubdivisionMentions() { let targetSubdivisions:[any SovereignStateSubdivision] = [SubdivisionsMexico.baja_california, SubdivisionsUnitedStates.california]