Skip to content
This repository has been archived by the owner on Jun 1, 2024. It is now read-only.

Commit

Permalink
fix: iOS 16 beta workaround for removeSubrange (#44)
Browse files Browse the repository at this point in the history
* fix: iOS 16 beta workaround for removeSubrange

Signed-off-by: Daniel Tes Carrasque <daniel@zup.com.br>

* fix license header

Signed-off-by: Daniel Tes Carrasque <daniel@zup.com.br>
  • Loading branch information
dantes-git authored Jun 15, 2022
1 parent c6be63f commit efdc947
Show file tree
Hide file tree
Showing 2 changed files with 16 additions and 6 deletions.
2 changes: 1 addition & 1 deletion Sources/Beagle/BeagleTests/Common/Util/Snapshot.swift
Original file line number Diff line number Diff line change
Expand Up @@ -19,7 +19,7 @@ import Beagle
import SnapshotTesting

private let imageDiffPrecision: Float = 0.99
private let diffTool = "code"
private let diffTool = "code --diff"

enum ImageSize {
case standard
Expand Down
20 changes: 15 additions & 5 deletions Sources/Beagle/Sources/ContextExpression/Expression/Parser.swift
Original file line number Diff line number Diff line change
@@ -1,5 +1,5 @@
/*
* Copyright 2020 ZUP IT SERVICOS EM TECNOLOGIA E INOVACAO SA
* Copyright 2020, 2022 ZUP IT SERVICOS EM TECNOLOGIA E INOVACAO SA
*
* Licensed under the Apache License, Version 2.0 (the "License");
* you may not use this file except in compliance with the License.
Expand Down Expand Up @@ -69,10 +69,20 @@ func literal(string: String) -> Parser<Void> {
}

func prefix(with regex: String) -> Parser<String> {
return Parser<String> { str in
guard let range = str.range(of: regex, options: [.regularExpression, .anchored]) else { return nil }
let prefix = str[range]
str.removeSubrange(range)
return Parser<String> { substring in
guard let rangeOfSubstring = substring.range(of: regex, options: [.regularExpression, .anchored]) else { return nil }
let prefix = substring[rangeOfSubstring]

// TODO: Remove this workaround when removeSubrange is fixed by Apple
if #available(iOS 16.0, *) {
var string = String(substring)
guard let rangeOfString = string.range(of: regex, options: [.regularExpression, .anchored]) else { return nil }
string.removeSubrange(rangeOfString)
substring = string[...]
} else {
substring.removeSubrange(rangeOfSubstring)
}

return String(prefix)
}
}
Expand Down

0 comments on commit efdc947

Please sign in to comment.