Skip to content

Commit

Permalink
Merge pull request #15 from Kyome22/solve-config-path-and-access-control
Browse files Browse the repository at this point in the history
Solved config files path and updated access control of ConfigurationType and Entity
  • Loading branch information
nysander authored Dec 14, 2022
2 parents b7c5fe7 + d4e18ed commit b965940
Show file tree
Hide file tree
Showing 6 changed files with 24 additions and 19 deletions.
8 changes: 6 additions & 2 deletions .github/workflows/ci.yml
Original file line number Diff line number Diff line change
@@ -1,33 +1,37 @@
name: CI

on:
workflow_dispatch:
push:
branches: [ main, develop ]
pull_request:
branches: [ main, develop ]
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 }}

steps:
- name: Checkout
uses: actions/checkout@v1


- name: Build
run: swift build
- name: Test
Expand Down
6 changes: 3 additions & 3 deletions Sources/TwitterText/Configuration.swift
Original file line number Diff line number Diff line change
Expand Up @@ -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)
}

Expand Down
10 changes: 5 additions & 5 deletions Sources/TwitterText/ConfigurationType.swift
Original file line number Diff line number Diff line change
@@ -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"
}
2 changes: 1 addition & 1 deletion Sources/TwitterText/Parser.swift
Original file line number Diff line number Diff line change
Expand Up @@ -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)
Expand Down
1 change: 1 addition & 0 deletions Tests/TwitterTextTests/TwitterTextEmojiTests.swift
Original file line number Diff line number Diff line change
Expand Up @@ -64,4 +64,5 @@ final class TwitterTextEmojiTests: XCTestCase {
XCTAssertFalse("A".isEmoji)
XCTAssertFalse("Á".isEmoji)
}

}
16 changes: 8 additions & 8 deletions Tests/TwitterTextTests/TwitterTextTests.swift
Original file line number Diff line number Diff line change
Expand Up @@ -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()
Expand Down Expand Up @@ -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")
}

Expand All @@ -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")
}

Expand All @@ -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)
Expand Down Expand Up @@ -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
}
Expand Down

0 comments on commit b965940

Please sign in to comment.