mirror of
https://github.com/GayPizzaSpecifications/darwin-apk.git
synced 2025-08-03 05:30:54 +00:00
Actually test requirement parsing output (not just if it succeded)
This commit is contained in:
@ -5,7 +5,7 @@
|
|||||||
|
|
||||||
import Foundation
|
import Foundation
|
||||||
|
|
||||||
internal struct ApkVersionRequirement: Hashable {
|
internal struct ApkVersionRequirement: Sendable, Hashable {
|
||||||
let name: String
|
let name: String
|
||||||
let versionSpec: ApkVersionSpecification
|
let versionSpec: ApkVersionSpecification
|
||||||
|
|
||||||
|
@ -3,13 +3,13 @@
|
|||||||
* SPDX-License-Identifier: Apache-2.0
|
* SPDX-License-Identifier: Apache-2.0
|
||||||
*/
|
*/
|
||||||
|
|
||||||
enum ApkVersionSpecification: Equatable, Hashable {
|
enum ApkVersionSpecification: Equatable, Hashable, Sendable {
|
||||||
case any(invert: Bool)
|
case any(invert: Bool = false)
|
||||||
case constraint(invert: Bool, op: Operator, version: String)
|
case constraint(invert: Bool = false, op: Operator, version: String)
|
||||||
}
|
}
|
||||||
|
|
||||||
extension ApkVersionSpecification {
|
extension ApkVersionSpecification {
|
||||||
enum Operator: Equatable {
|
enum Operator: Equatable, Sendable {
|
||||||
case equals
|
case equals
|
||||||
case fuzzyEquals
|
case fuzzyEquals
|
||||||
case greater
|
case greater
|
||||||
|
@ -7,21 +7,33 @@ import Testing
|
|||||||
@testable import darwin_apk
|
@testable import darwin_apk
|
||||||
|
|
||||||
@Test func testParseDependency() {
|
@Test func testParseDependency() {
|
||||||
for valid in [
|
let tests: [String: ApkVersionRequirement] = [
|
||||||
"bash",
|
"bash":
|
||||||
"libapparmor=4.1.0-r2",
|
.init(name: "bash", spec: .any()),
|
||||||
"python3~3.12",
|
"!libdbus":
|
||||||
"so:libc.musl-x86_64.so.1",
|
.init(name: "libdbus", spec: .any(invert: true)),
|
||||||
"!alsa-lib<1.2.14-r0",
|
"libapparmor=4.1.0-r2":
|
||||||
"!alsa-lib>1.2.14-r0",
|
.init(name: "libapparmor", spec: .constraint(op: .equals, version: "4.1.0-r2")),
|
||||||
"!lld20-libs<20.1.2-r0",
|
"python3~3.12":
|
||||||
"!lld20-libs>20.1.2-r0",
|
.init(name: "python3", spec: .constraint(op: .fuzzyEquals, version: "3.12")),
|
||||||
"!lld20<20.1.2-r0",
|
"so:libc.musl-x86_64.so.1":
|
||||||
"!lld20>20.1.2-r0",
|
.init(name: "so:libc.musl-x86_64.so.1", spec: .any()),
|
||||||
] {
|
"!alsa-lib<1.2.14-r0":
|
||||||
#expect(throws: Never.self, "Expected valid: \(valid)") {
|
.init(name: "alsa-lib", spec: .constraint(invert: true, op: .less, version: "1.2.14-r0")),
|
||||||
try ApkVersionRequirement(extract: valid[...])
|
"!alsa-lib>1.2.14-r0":
|
||||||
}
|
.init(name: "alsa-lib", spec: .constraint(invert: true, op: .greater, version: "1.2.14-r0")),
|
||||||
|
"!lld20-libs<20.1.2-r0":
|
||||||
|
.init(name: "lld20-libs", spec: .constraint(invert: true, op: .less, version: "20.1.2-r0")),
|
||||||
|
"!lld20-libs>20.1.2-r0":
|
||||||
|
.init(name: "lld20-libs", spec: .constraint(invert: true, op: .greater, version: "20.1.2-r0")),
|
||||||
|
"!lld20<20.1.2-r0":
|
||||||
|
.init(name: "lld20", spec: .constraint(invert: true, op: .less, version: "20.1.2-r0")),
|
||||||
|
"!lld20>20.1.2-r0":
|
||||||
|
.init(name: "lld20", spec: .constraint(invert: true, op: .greater, version: "20.1.2-r0")),
|
||||||
|
]
|
||||||
|
for valid in tests {
|
||||||
|
#expect((try? ApkVersionRequirement(extract: valid.key[...])) == valid.value,
|
||||||
|
"Expect: \(valid.key) == \(valid.value)")
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
|
Reference in New Issue
Block a user