Skip to content
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
4 changes: 2 additions & 2 deletions lib/useCache.ts
Original file line number Diff line number Diff line change
Expand Up @@ -6,8 +6,8 @@ export default function() {
return { decode }
}

const bottleRegex = `^(.*)-(\\d+(\\.\\d+)*[:alpha:]?)\\+(.+?)\\+(.+?)\\.tar\\.[gx]z$`
const srcRegex = `^(.*)-(\\d+(\\.\\d+)*[:alpha:]?)\\.tar\\.[gx]z$`
const bottleRegex = `^(.*)-(\\d+(\\.\\d+)*[a-z]?)\\+(.+?)\\+(.+?)\\.tar\\.[gx]z$`
const srcRegex = `^(.*)-(\\d+(\\.\\d+)*[a-z]?)\\.tar\\.[gx]z$`

function decode(path: Path): Stowed | undefined {
const bottleMatch = path.basename().match(bottleRegex)
Expand Down
24 changes: 15 additions & 9 deletions tests/unit/useCache.test.ts
Original file line number Diff line number Diff line change
Expand Up @@ -6,16 +6,22 @@ import SemVer from "semver"
Deno.test("decode", async test => {
const cache = useCache()

const versions = ["1", "1a", "1.2", "1.2a", "1.2.3", "1.2.3a", "1.2.3.4", "1.2.3.4a"] as const
const versions = ["1", "9e" /* pattern of ijg.org */, "1.2", "3.3a" /* pattern of tmux */, "1.2.3", "1.2.3a", "1.2.3.4", "1.2.3.4a"] as const
const archs = ["x86-64", "aarch64"]
const platforms = ["linux", "darwin"]
for (const version of versions) {
await test.step(`type == bottle, version == ${version}`, () => {
const stowed = cache.decode(Path.root.join(`project∕foo-${version}+linux+x86-64.tar.gz`)) as any
assertEquals(stowed.pkg.project, "project/foo")
assertEquals(stowed.pkg.version, new SemVer(version, { tolerant: true }))
assertEquals(stowed.type, "bottle")
assertEquals(stowed.compression, "gz")
assertEquals(stowed.host, {arch: "x86-64", platform: "linux"})
})
for (const arch of archs) {
for (const platform of platforms) {
await test.step(`type == bottle, arch == ${arch}, platform == ${platform}, version == ${version}`, () => {
const stowed = cache.decode(Path.root.join(`project∕foo-${version}+${platform}+${arch}.tar.gz`)) as any
assertEquals(stowed.pkg.project, "project/foo")
assertEquals(stowed.pkg.version, new SemVer(version, { tolerant: true }))
assertEquals(stowed.type, "bottle")
assertEquals(stowed.compression, "gz")
assertEquals(stowed.host, {arch: arch, platform: platform})
})
}
}
}

for (const version of versions) {
Expand Down