-
Notifications
You must be signed in to change notification settings - Fork 0
Expand file tree
/
Copy pathzip-utils.test.ts
More file actions
37 lines (31 loc) · 957 Bytes
/
zip-utils.test.ts
File metadata and controls
37 lines (31 loc) · 957 Bytes
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
import JSZip from 'jszip'
import fs from 'node:fs'
import { it } from 'node:test'
import assert from 'node:assert'
import { memfsUnzipPrim } from './zip-utils'
it('filters', async () => {
const zip = await JSZip.loadAsync(fs.readFileSync('./fixtures/agda-data.zip'))
async function count(filter = (_: string) => true, debug = false) {
let dir = 0, files = 0
memfsUnzipPrim(zip, '', filter, (path, file) => {
if (debug) console.log('+', path)
if (file.dir) dir++
else files++
})
return [dir, files]
}
assert.deepEqual(await count(() => true, true), [12, 75])
assert.deepEqual(await count(() => false), [0, 0])
assert.deepEqual(await count(path => {
if (path === 'lib/prim/Agda/Builtin/Reflection/') {
return false
}
return true
}), [11, 71])
assert.deepEqual(await count(path => {
if (path === 'lib/prim/Agda/Builtin/') {
return false
}
return true
}), [4, 5])
})