Skip to content

Commit

Permalink
Reapply all the changes made to satisfy GH Actions
Browse files Browse the repository at this point in the history
This reverts commit 052763b.

Signed-off-by: Henrik Panhans <[email protected]>
  • Loading branch information
henrik-dmg committed Mar 11, 2024
1 parent e4f193b commit 8c2949e
Show file tree
Hide file tree
Showing 5 changed files with 32 additions and 44 deletions.
2 changes: 1 addition & 1 deletion Package.swift
Original file line number Diff line number Diff line change
@@ -1,4 +1,4 @@
// swift-tools-version:5.7
// swift-tools-version:5.9
// The swift-tools-version declares the minimum version of Swift required to build this package.

import PackageDescription
Expand Down
7 changes: 3 additions & 4 deletions Sources/SwiftFrameCore/Config/ConfigData.swift
Original file line number Diff line number Diff line change
Expand Up @@ -67,11 +67,10 @@ struct ConfigData: Decodable, ConfigValidateable {
// MARK: - Processing

mutating func process() throws {
let regex: NSRegularExpression?
if let localesRegex, !localesRegex.isEmpty {
regex = try NSRegularExpression(pattern: localesRegex)
let regex: Regex<AnyRegexOutput>? = if let localesRegex, !localesRegex.isEmpty {
try Regex(localesRegex)
} else {
regex = nil
nil
}

deviceData = try deviceData.map { try $0.makeProcessedData(localesRegex: regex) }
Expand Down
2 changes: 1 addition & 1 deletion Sources/SwiftFrameCore/Config/DeviceData.swift
Original file line number Diff line number Diff line change
Expand Up @@ -57,7 +57,7 @@ struct DeviceData: Decodable, ConfigValidateable {

// MARK: - Methods

func makeProcessedData(localesRegex: NSRegularExpression?) throws -> DeviceData {
func makeProcessedData(localesRegex: Regex<AnyRegexOutput>?) throws -> DeviceData {
guard let templateImage = ImageLoader.loadRepresentation(at: templateImagePath.absoluteURL) else {
throw NSError(description: "Error while loading template image at path \(templateImagePath.absoluteString)")
}
Expand Down
15 changes: 3 additions & 12 deletions Sources/SwiftFrameCore/Extensions/Collection+Extensions.swift
Original file line number Diff line number Diff line change
@@ -1,24 +1,15 @@
import Foundation

extension Array where Element == URL {
extension [URL] {

func filterByFileOrFoldername(regex: NSRegularExpression?) throws -> Self {
func filterByFileOrFoldername(regex: Regex<AnyRegexOutput>?) throws -> Self {
guard let regex else {
return self
}
return self.filter { url in
let lastComponent = url.deletingPathExtension().lastPathComponent
return regex.matches(lastComponent)
return !lastComponent.matches(of: regex).isEmpty
}
}

}

extension NSRegularExpression {

func matches(_ string: String) -> Bool {
let range = NSRange(location: 0, length: (string as NSString).length)
return firstMatch(in: string, options: [], range: range) != nil
}

}
50 changes: 24 additions & 26 deletions Tests/SwiftFrameTests/RegexMatchTests.swift
Original file line number Diff line number Diff line change
Expand Up @@ -4,52 +4,50 @@ import XCTest

class RegexMatchTests: XCTestCase {

static let urls: [URL] = {
[
URL(fileURLWithPath: "strings/en.strings"),
URL(fileURLWithPath: "strings/de.strings"),
URL(fileURLWithPath: "strings/fr.strings"),
URL(fileURLWithPath: "strings/ru.strings")
]
}()
private let urls: [URL] = [
URL(fileURLWithPath: "strings/en.strings"),
URL(fileURLWithPath: "strings/de.strings"),
URL(fileURLWithPath: "strings/fr.strings"),
URL(fileURLWithPath: "strings/ru.strings")
]

func testAllURLs() throws {
let urls = try RegexMatchTests.urls.filterByFileOrFoldername(regex: nil)
XCTAssertEqual(urls, RegexMatchTests.urls)
let filteredURLs = try urls.filterByFileOrFoldername(regex: nil)
XCTAssertEqual(filteredURLs, urls)
}

func testFranceFilteredOut() throws {
let regex = try NSRegularExpression(pattern: "^(?!fr$)\\w*$", options: .caseInsensitive)
let urls = try RegexMatchTests.urls.filterByFileOrFoldername(regex: regex)
let regex = try Regex("^(?!fr$)\\w*$")
let filteredURLs = try urls.filterByFileOrFoldername(regex: regex)

guard ky_assertEqual(urls.count, 3) else {
guard ky_assertEqual(filteredURLs.count, 3) else {
return
}
XCTAssertTrue(urls[0].absoluteString.hasSuffix("en.strings"))
XCTAssertTrue(urls[1].absoluteString.hasSuffix("de.strings"))
XCTAssertTrue(urls[2].absoluteString.hasSuffix("ru.strings"))
XCTAssertTrue(filteredURLs[0].absoluteString.hasSuffix("en.strings"))
XCTAssertTrue(filteredURLs[1].absoluteString.hasSuffix("de.strings"))
XCTAssertTrue(filteredURLs[2].absoluteString.hasSuffix("ru.strings"))
}

func testFranceAndRussiaFilteredOut() throws {
let regex = try NSRegularExpression(pattern: "^(?!fr|ru$)\\w*$", options: .caseInsensitive)
let urls = try RegexMatchTests.urls.filterByFileOrFoldername(regex: regex)
let regex = try Regex("^(?!fr|ru$)\\w*$")
let filteredURLs = try urls.filterByFileOrFoldername(regex: regex)

guard ky_assertEqual(urls.count, 2) else {
guard ky_assertEqual(filteredURLs.count, 2) else {
return
}
XCTAssertTrue(urls[0].absoluteString.hasSuffix("en.strings"))
XCTAssertTrue(urls[1].absoluteString.hasSuffix("de.strings"))
XCTAssertTrue(filteredURLs[0].absoluteString.hasSuffix("en.strings"))
XCTAssertTrue(filteredURLs[1].absoluteString.hasSuffix("de.strings"))
}

func testOnlyRussiaAndFrance() throws {
let regex = try NSRegularExpression(pattern: "ru|fr", options: .caseInsensitive)
let urls = try RegexMatchTests.urls.filterByFileOrFoldername(regex: regex)
let regex = try Regex("ru|fr")
let filteredURLs = try urls.filterByFileOrFoldername(regex: regex)

guard ky_assertEqual(urls.count, 2) else {
guard ky_assertEqual(filteredURLs.count, 2) else {
return
}
XCTAssertEqual(urls[0].lastPathComponent, "fr.strings")
XCTAssertEqual(urls[1].lastPathComponent, "ru.strings")
XCTAssertEqual(filteredURLs[0].lastPathComponent, "fr.strings")
XCTAssertEqual(filteredURLs[1].lastPathComponent, "ru.strings")
}

}
Expand Down

0 comments on commit 8c2949e

Please sign in to comment.