From 2992edd945517cb790cce699d6a20a4406ab5821 Mon Sep 17 00:00:00 2001 From: Kyome22 Date: Sat, 12 Dec 2020 22:24:54 +0900 Subject: [PATCH 1/8] modified properties of Entity --- Sources/TwitterText/Entity.swift | 4 ++-- 1 file changed, 2 insertions(+), 2 deletions(-) diff --git a/Sources/TwitterText/Entity.swift b/Sources/TwitterText/Entity.swift index e56e563..89d918c 100644 --- a/Sources/TwitterText/Entity.swift +++ b/Sources/TwitterText/Entity.swift @@ -6,8 +6,8 @@ import Foundation public class Entity { - var type: EntityType - var range: NSRange + public internal(set) var type: EntityType + public internal(set) var range: NSRange public init(withType type: EntityType, range: NSRange) { self.type = type From 04304deeacd6c8e2f0752d65946e808cb943f583 Mon Sep 17 00:00:00 2001 From: Kyome22 Date: Sat, 12 Dec 2020 22:53:03 +0900 Subject: [PATCH 2/8] Fixed ConfigurationType --- Sources/TwitterText/Configuration.swift | 5 +++-- Sources/TwitterText/ConfigurationType.swift | 8 ++++---- Tests/TwitterTextTests/TwitterTextEmojiTests.swift | 4 ++++ 3 files changed, 11 insertions(+), 6 deletions(-) diff --git a/Sources/TwitterText/Configuration.swift b/Sources/TwitterText/Configuration.swift index 7bb4a89..ed37aa2 100644 --- a/Sources/TwitterText/Configuration.swift +++ b/Sources/TwitterText/Configuration.swift @@ -56,8 +56,9 @@ public class Configuration { } } - public static func configuration(fromJSONResource jsonResource: String) -> Configuration? { - let url = URL(fileURLWithPath: #file).deletingLastPathComponent().deletingLastPathComponent().deletingLastPathComponent().appendingPathComponent("config/\(jsonResource).json") + public static func configuration(fromType type: ConfigurationType) -> Configuration? { + let url = URL(fileURLWithPath: #file).deletingLastPathComponent().deletingLastPathComponent().deletingLastPathComponent().appendingPathComponent("config/\(type.rawValue).json") + Swift.print(url.absoluteURL) guard let jsonData = try? Data(contentsOf: url) else { return nil } diff --git a/Sources/TwitterText/ConfigurationType.swift b/Sources/TwitterText/ConfigurationType.swift index 99bd18c..9202154 100644 --- a/Sources/TwitterText/ConfigurationType.swift +++ b/Sources/TwitterText/ConfigurationType.swift @@ -7,8 +7,8 @@ import Foundation -enum ConfigurationType { - static let classic = "v1" - static let v2 = "v2" - static let v3 = "v3" +public enum ConfigurationType: String { + case classic = "v1" + case v2 = "v2" + case v3 = "v3" } diff --git a/Tests/TwitterTextTests/TwitterTextEmojiTests.swift b/Tests/TwitterTextTests/TwitterTextEmojiTests.swift index 9ce758e..cabec12 100644 --- a/Tests/TwitterTextTests/TwitterTextEmojiTests.swift +++ b/Tests/TwitterTextTests/TwitterTextEmojiTests.swift @@ -64,4 +64,8 @@ final class TwitterTextEmojiTests: XCTestCase { XCTAssertFalse("A".isEmoji) XCTAssertFalse("Á".isEmoji) } + + func testConfiguration() { + let _ = Configuration.configuration(fromJSONResource: ConfigurationType.v3) + } } From 7b564001733f76de303c44f5a12f87a2863bc337 Mon Sep 17 00:00:00 2001 From: Kyome22 Date: Sat, 12 Dec 2020 22:55:43 +0900 Subject: [PATCH 3/8] Fixed ConfigurationType 2 --- Sources/TwitterText/Parser.swift | 2 +- .../TwitterTextTests/TwitterTextEmojiTests.swift | 2 +- Tests/TwitterTextTests/TwitterTextTests.swift | 16 ++++++++-------- 3 files changed, 10 insertions(+), 10 deletions(-) diff --git a/Sources/TwitterText/Parser.swift b/Sources/TwitterText/Parser.swift index 49e5014..50583ff 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 cabec12..648cd3b 100644 --- a/Tests/TwitterTextTests/TwitterTextEmojiTests.swift +++ b/Tests/TwitterTextTests/TwitterTextEmojiTests.swift @@ -66,6 +66,6 @@ final class TwitterTextEmojiTests: XCTestCase { } func testConfiguration() { - let _ = Configuration.configuration(fromJSONResource: ConfigurationType.v3) + let _ = Configuration.configuration(fromType: ConfigurationType.v3) } } diff --git a/Tests/TwitterTextTests/TwitterTextTests.swift b/Tests/TwitterTextTests/TwitterTextTests.swift index 834a76a..e02e7e5 100644 --- a/Tests/TwitterTextTests/TwitterTextTests.swift +++ b/Tests/TwitterTextTests/TwitterTextTests.swift @@ -596,7 +596,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() @@ -679,17 +679,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") } @@ -703,7 +703,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") } @@ -713,7 +713,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) @@ -888,9 +888,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 } From 8b5bbc3e357045974d58a73d32ae1a62238c7808 Mon Sep 17 00:00:00 2001 From: Kyome22 Date: Sat, 12 Dec 2020 23:42:51 +0900 Subject: [PATCH 4/8] Solved config path --- Package.swift | 8 ++++++-- {config => Sources/TwitterText/Config}/v1.json | 0 {config => Sources/TwitterText/Config}/v2.json | 0 {config => Sources/TwitterText/Config}/v3.json | 0 Sources/TwitterText/Configuration.swift | 6 ++---- Sources/TwitterText/ConfigurationType.swift | 2 +- Tests/TwitterTextTests/TwitterTextEmojiTests.swift | 5 +---- 7 files changed, 10 insertions(+), 11 deletions(-) rename {config => Sources/TwitterText/Config}/v1.json (100%) rename {config => Sources/TwitterText/Config}/v2.json (100%) rename {config => Sources/TwitterText/Config}/v3.json (100%) diff --git a/Package.swift b/Package.swift index 9232507..198648e 100644 --- a/Package.swift +++ b/Package.swift @@ -1,4 +1,4 @@ -// swift-tools-version:5.1 +// swift-tools-version:5.3 // twitter-text // @@ -18,7 +18,11 @@ let package = Package( ], targets: [ - .target(name: "TwitterText", dependencies: ["UnicodeURL"]), + .target( + name: "TwitterText", + dependencies: ["UnicodeURL"], + resources: [.process("Config")] + ), .testTarget(name: "TwitterTextTests", dependencies: ["TwitterText"]) ] ) diff --git a/config/v1.json b/Sources/TwitterText/Config/v1.json similarity index 100% rename from config/v1.json rename to Sources/TwitterText/Config/v1.json diff --git a/config/v2.json b/Sources/TwitterText/Config/v2.json similarity index 100% rename from config/v2.json rename to Sources/TwitterText/Config/v2.json diff --git a/config/v3.json b/Sources/TwitterText/Config/v3.json similarity index 100% rename from config/v3.json rename to Sources/TwitterText/Config/v3.json diff --git a/Sources/TwitterText/Configuration.swift b/Sources/TwitterText/Configuration.swift index ed37aa2..2129968 100644 --- a/Sources/TwitterText/Configuration.swift +++ b/Sources/TwitterText/Configuration.swift @@ -57,12 +57,10 @@ public class Configuration { } public static func configuration(fromType type: ConfigurationType) -> Configuration? { - let url = URL(fileURLWithPath: #file).deletingLastPathComponent().deletingLastPathComponent().deletingLastPathComponent().appendingPathComponent("config/\(type.rawValue).json") - Swift.print(url.absoluteURL) - guard let jsonData = try? Data(contentsOf: url) else { + 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 9202154..7a2e326 100644 --- a/Sources/TwitterText/ConfigurationType.swift +++ b/Sources/TwitterText/ConfigurationType.swift @@ -7,7 +7,7 @@ import Foundation -public enum ConfigurationType: String { +enum ConfigurationType: String { case classic = "v1" case v2 = "v2" case v3 = "v3" diff --git a/Tests/TwitterTextTests/TwitterTextEmojiTests.swift b/Tests/TwitterTextTests/TwitterTextEmojiTests.swift index 648cd3b..19aa2d9 100644 --- a/Tests/TwitterTextTests/TwitterTextEmojiTests.swift +++ b/Tests/TwitterTextTests/TwitterTextEmojiTests.swift @@ -64,8 +64,5 @@ final class TwitterTextEmojiTests: XCTestCase { XCTAssertFalse("A".isEmoji) XCTAssertFalse("Á".isEmoji) } - - func testConfiguration() { - let _ = Configuration.configuration(fromType: ConfigurationType.v3) - } + } From 185bb70e780c8d6b403a1df39f609d0b29b521de Mon Sep 17 00:00:00 2001 From: Kyome22 Date: Sat, 12 Dec 2020 23:46:37 +0900 Subject: [PATCH 5/8] fixed access control of ConfigurationType --- Sources/TwitterText/ConfigurationType.swift | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/Sources/TwitterText/ConfigurationType.swift b/Sources/TwitterText/ConfigurationType.swift index 7a2e326..9202154 100644 --- a/Sources/TwitterText/ConfigurationType.swift +++ b/Sources/TwitterText/ConfigurationType.swift @@ -7,7 +7,7 @@ import Foundation -enum ConfigurationType: String { +public enum ConfigurationType: String { case classic = "v1" case v2 = "v2" case v3 = "v3" From f50a4c3f5450b0f701e678c802c2aa330f017351 Mon Sep 17 00:00:00 2001 From: Kyome22 Date: Thu, 25 Mar 2021 12:00:49 +0900 Subject: [PATCH 6/8] modify ci.yml --- .github/workflows/ci.yml | 3 ++- 1 file changed, 2 insertions(+), 1 deletion(-) diff --git a/.github/workflows/ci.yml b/.github/workflows/ci.yml index 20b31df..1e12993 100644 --- a/.github/workflows/ci.yml +++ b/.github/workflows/ci.yml @@ -1,13 +1,14 @@ name: CI on: + workflow_dispatch: push: branches: [ main, develop ] pull_request: branches: [ main, develop ] jobs: macos: - runs-on: macOS-latest + runs-on: macos-latest steps: - name: Checkout From 577708705461e8cbaea33b975e6cbf61adc3c925 Mon Sep 17 00:00:00 2001 From: Kyome22 Date: Thu, 25 Mar 2021 12:19:54 +0900 Subject: [PATCH 7/8] swift 5.2 to 5.3 --- .github/workflows/ci.yml | 5 ++++- 1 file changed, 4 insertions(+), 1 deletion(-) diff --git a/.github/workflows/ci.yml b/.github/workflows/ci.yml index 1e12993..21fbf53 100644 --- a/.github/workflows/ci.yml +++ b/.github/workflows/ci.yml @@ -15,12 +15,13 @@ jobs: 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 +29,8 @@ jobs: steps: - name: Checkout uses: actions/checkout@v1 + + - name: Build run: swift build - name: Test From d73b6a4020507045fa16e162908209590ae45594 Mon Sep 17 00:00:00 2001 From: "Takuto NAKAMURA (Kyome)" Date: Thu, 15 Dec 2022 00:04:32 +0900 Subject: [PATCH 8/8] Temporarily remove config file to avoid upper/lowercase issues. --- Sources/TwitterText/Config/v1.json | 8 -------- Sources/TwitterText/Config/v2.json | 29 ----------------------------- Sources/TwitterText/Config/v3.json | 30 ------------------------------ 3 files changed, 67 deletions(-) delete mode 100644 Sources/TwitterText/Config/v1.json delete mode 100644 Sources/TwitterText/Config/v2.json delete mode 100644 Sources/TwitterText/Config/v3.json diff --git a/Sources/TwitterText/Config/v1.json b/Sources/TwitterText/Config/v1.json deleted file mode 100644 index 7d5cc79..0000000 --- a/Sources/TwitterText/Config/v1.json +++ /dev/null @@ -1,8 +0,0 @@ -{ - "version": 1, - "maxWeightedTweetLength": 140, - "scale": 1, - "defaultWeight": 1, - "transformedURLLength": 23, - "ranges": [] -} diff --git a/Sources/TwitterText/Config/v2.json b/Sources/TwitterText/Config/v2.json deleted file mode 100644 index 7fa4955..0000000 --- a/Sources/TwitterText/Config/v2.json +++ /dev/null @@ -1,29 +0,0 @@ -{ - "version": 2, - "maxWeightedTweetLength": 280, - "scale": 100, - "defaultWeight": 200, - "transformedURLLength": 23, - "ranges": [ - { - "start": 0, - "end": 4351, - "weight": 100 - }, - { - "start": 8192, - "end": 8205, - "weight": 100 - }, - { - "start": 8208, - "end": 8223, - "weight": 100 - }, - { - "start": 8242, - "end": 8247, - "weight": 100 - } - ] -} diff --git a/Sources/TwitterText/Config/v3.json b/Sources/TwitterText/Config/v3.json deleted file mode 100644 index 358afac..0000000 --- a/Sources/TwitterText/Config/v3.json +++ /dev/null @@ -1,30 +0,0 @@ -{ - "version": 3, - "maxWeightedTweetLength": 280, - "scale": 100, - "defaultWeight": 200, - "emojiParsingEnabled": true, - "transformedURLLength": 23, - "ranges": [ - { - "start": 0, - "end": 4351, - "weight": 100 - }, - { - "start": 8192, - "end": 8205, - "weight": 100 - }, - { - "start": 8208, - "end": 8223, - "weight": 100 - }, - { - "start": 8242, - "end": 8247, - "weight": 100 - } - ] -}