diff --git a/.github/workflows/ci.yml b/.github/workflows/ci.yml index 841ea90..f9306f6 100644 --- a/.github/workflows/ci.yml +++ b/.github/workflows/ci.yml @@ -1,6 +1,7 @@ name: CI on: + workflow_dispatch: push: branches: [ main, develop ] pull_request: @@ -8,19 +9,20 @@ on: workflow_dispatch: jobs: macos: - runs-on: macOS-latest + runs-on: macos-latest steps: - name: Checkout uses: actions/checkout@v1 - name: Build and Test run: swift test + linux: runs-on: ubuntu-latest strategy: matrix: - swift: ["5.2"] + swift: ["5.3"] container: image: swift:${{ matrix.swift }} @@ -28,6 +30,8 @@ jobs: steps: - name: Checkout uses: actions/checkout@v1 + + - name: Build run: swift build - name: Test diff --git a/Sources/TwitterText/Configuration.swift b/Sources/TwitterText/Configuration.swift index a1a8062..2129968 100644 --- a/Sources/TwitterText/Configuration.swift +++ b/Sources/TwitterText/Configuration.swift @@ -56,11 +56,11 @@ public class Configuration { } } - public static func configuration(fromJSONResource jsonResource: String) -> Configuration? { - guard let url = Bundle.module.url(forResource: jsonResource, withExtension: "json"), let jsonData = try? Data(contentsOf: url) else { + public static func configuration(fromType type: ConfigurationType) -> Configuration? { + guard let url = Bundle.module.url(forResource: type.rawValue, withExtension: "json"), + let jsonData = try? Data(contentsOf: url) else { return nil } - return Configuration(jsonData: jsonData) } diff --git a/Sources/TwitterText/ConfigurationType.swift b/Sources/TwitterText/ConfigurationType.swift index 28a8293..015d725 100644 --- a/Sources/TwitterText/ConfigurationType.swift +++ b/Sources/TwitterText/ConfigurationType.swift @@ -1,14 +1,14 @@ // // File.swift -// +// // // Created by Pawel Madej on 22/09/2020. // import Foundation -public enum ConfigurationType { - public static let classic = "v1" - public static let v2 = "v2" - public static let v3 = "v3" +public enum ConfigurationType: String { + case classic = "v1" + case v2 = "v2" + case v3 = "v3" } diff --git a/Sources/TwitterText/Parser.swift b/Sources/TwitterText/Parser.swift index 61738a6..13cfaf5 100644 --- a/Sources/TwitterText/Parser.swift +++ b/Sources/TwitterText/Parser.swift @@ -7,7 +7,7 @@ import Foundation import CoreFoundation public class Parser { - public static var defaultParser = Parser(with: Configuration.configuration(fromJSONResource: ConfigurationType.v3)!) + public static var defaultParser = Parser(with: Configuration.configuration(fromType: ConfigurationType.v3)!) public static func setDefaultParser(with configuration: Configuration) { defaultParser = Parser(with: configuration) diff --git a/Tests/TwitterTextTests/TwitterTextEmojiTests.swift b/Tests/TwitterTextTests/TwitterTextEmojiTests.swift index 9ce758e..19aa2d9 100644 --- a/Tests/TwitterTextTests/TwitterTextEmojiTests.swift +++ b/Tests/TwitterTextTests/TwitterTextEmojiTests.swift @@ -64,4 +64,5 @@ final class TwitterTextEmojiTests: XCTestCase { XCTAssertFalse("A".isEmoji) XCTAssertFalse("Á".isEmoji) } + } diff --git a/Tests/TwitterTextTests/TwitterTextTests.swift b/Tests/TwitterTextTests/TwitterTextTests.swift index 34a371c..193aa07 100644 --- a/Tests/TwitterTextTests/TwitterTextTests.swift +++ b/Tests/TwitterTextTests/TwitterTextTests.swift @@ -611,7 +611,7 @@ final class TwitterTextTests: XCTestCase { return } - Parser.setDefaultParser(with: Configuration.configuration(fromJSONResource: ConfigurationType.classic)!) + Parser.setDefaultParser(with: Configuration.configuration(fromType: ConfigurationType.classic)!) guard let tests = validation["tests"] as? [String: Any] else { XCTFail() @@ -694,17 +694,17 @@ final class TwitterTextTests: XCTestCase { } func testUnicodePointTweetLengthCounting() { - Parser.setDefaultParser(with: Configuration.configuration(fromJSONResource: ConfigurationType.v2)!) + Parser.setDefaultParser(with: Configuration.configuration(fromType: ConfigurationType.v2)!) self._testWeightedTweetsCountingWithTestSuite(testSuite: "WeightedTweetsCounterTest") } func testEmojiWeightedTweetLengthCounting() { - Parser.setDefaultParser(with: Configuration.configuration(fromJSONResource: ConfigurationType.v3)!) + Parser.setDefaultParser(with: Configuration.configuration(fromType: ConfigurationType.v3)!) self._testWeightedTweetsCountingWithTestSuite(testSuite: "WeightedTweetsWithDiscountedEmojiCounterTest") } func testEmojiWeightedTweetLengthCountingWithDiscountedUnicode9Emoji() { - Parser.setDefaultParser(with: Configuration.configuration(fromJSONResource: ConfigurationType.v3)!) + Parser.setDefaultParser(with: Configuration.configuration(fromType: ConfigurationType.v3)!) self._testWeightedTweetsCountingWithTestSuite(testSuite: "WeightedTweetsWithDiscountedUnicode9EmojiCounterTest") } @@ -718,7 +718,7 @@ final class TwitterTextTests: XCTestCase { return } - Parser.setDefaultParser(with: Configuration.configuration(fromJSONResource: ConfigurationType.v3)!) + Parser.setDefaultParser(with: Configuration.configuration(fromType: ConfigurationType.v3)!) self._testWeightedTweetsCountingWithTestSuite(testSuite: "WeightedTweetsWithDiscountedUnicode10EmojiCounterTest") } @@ -728,7 +728,7 @@ final class TwitterTextTests: XCTestCase { var text = "ZWJ: क्ष -> क्\u{200D}ष; ZWNJ: क्ष -> क्\u{200C}ष" text = self.stringByParsingUnicodeEscapes(string: text) - Parser.setDefaultParser(with: Configuration.configuration(fromJSONResource: ConfigurationType.v3)!) + Parser.setDefaultParser(with: Configuration.configuration(fromType: ConfigurationType.v3)!) let results = Parser.defaultParser.parseTweet(text: text) XCTAssertEqual(results.weightedLength, 35) @@ -903,9 +903,9 @@ final class TwitterTextTests: XCTestCase { func testTwitterTextParserConfigurationV2ToV3Transition() { guard let configurationV2 = Configuration - .configuration(fromJSONResource: ConfigurationType.v2), + .configuration(fromType: ConfigurationType.v2), let configurationV3 = Configuration - .configuration(fromJSONResource: ConfigurationType.v3) else { + .configuration(fromType: ConfigurationType.v3) else { XCTFail() return }