mirror of
https://github.com/GayPizzaSpecifications/darwin-apk.git
synced 2025-08-03 13:31:32 +00:00
Unit tests for APK version parsing & fix typo in parser
This commit is contained in:
@ -12,14 +12,21 @@ let package = Package(
|
||||
targets: [
|
||||
.target(
|
||||
name: "darwin-apk",
|
||||
path: "Sources/apk"),
|
||||
path: "Sources/apk",
|
||||
),
|
||||
.testTarget(
|
||||
name: "darwin-apk-tests",
|
||||
dependencies: [
|
||||
"darwin-apk",
|
||||
],
|
||||
),
|
||||
.executableTarget(
|
||||
name: "dpk",
|
||||
dependencies: [
|
||||
"darwin-apk",
|
||||
.product(name: "ArgumentParser", package: "swift-argument-parser"),
|
||||
],
|
||||
path: "Sources/dpk-cli"
|
||||
path: "Sources/dpk-cli",
|
||||
),
|
||||
]
|
||||
],
|
||||
)
|
||||
|
@ -16,7 +16,7 @@ internal struct ApkVersionReader {
|
||||
mutating func next() throws(Invalid) -> TokenPart {
|
||||
self.seen.formUnion(self.last)
|
||||
|
||||
switch string.first ?? UInt8(ascii: "0") {
|
||||
switch string.first ?? UInt8(ascii: "\0") {
|
||||
case UInt8(ascii: "a")...UInt8(ascii: "z"): // Letter suffix
|
||||
guard self.seen.contains(.initial),
|
||||
self.last.isDisjoint(with: [ .letter, .suffix, .suffixNumber, .commitHash, .revision ]) else {
|
||||
|
47
Tests/darwin-apk-tests/ApkVersionTests.swift
Normal file
47
Tests/darwin-apk-tests/ApkVersionTests.swift
Normal file
@ -0,0 +1,47 @@
|
||||
/*
|
||||
* darwin-apk © 2025 Gay Pizza Specifications
|
||||
* SPDX-License-Identifier: Apache-2.0
|
||||
*/
|
||||
|
||||
import Testing
|
||||
@testable import darwin_apk
|
||||
|
||||
@Test func testParseDependency() {
|
||||
for valid in [
|
||||
"bash",
|
||||
"libapparmor=4.1.0-r2",
|
||||
"python3~3.12",
|
||||
"so:libc.musl-x86_64.so.1",
|
||||
"!alsa-lib<1.2.14-r0",
|
||||
"!alsa-lib>1.2.14-r0",
|
||||
"!lld20-libs<20.1.2-r0",
|
||||
"!lld20-libs>20.1.2-r0",
|
||||
"!lld20<20.1.2-r0",
|
||||
"!lld20>20.1.2-r0",
|
||||
] {
|
||||
#expect(throws: Never.self, "Expected valid: \(valid)") {
|
||||
try ApkVersionRequirement(extract: valid[...])
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
@Test func testVersionValidation() {
|
||||
for valid in [
|
||||
"100",
|
||||
"1.0",
|
||||
"0-r1",
|
||||
"10.2.3-r100",
|
||||
"0.0.0_git20210122-r0",
|
||||
"0.20240527.191746-r2",
|
||||
"9100h-r4",
|
||||
] {
|
||||
#expect(ApkVersionCompare.validate(valid), "Should be valid: \(valid)")
|
||||
}
|
||||
for invalid in [
|
||||
"a",
|
||||
"0r-10",
|
||||
"10.2.3-100",
|
||||
] {
|
||||
#expect(!ApkVersionCompare.validate(invalid), "Should be invalid: \(invalid)")
|
||||
}
|
||||
}
|
Reference in New Issue
Block a user