|
1 | 1 | import { assert, assertEquals } from '@std/assert' |
2 | | -import type { FileIgnoreRules } from './ignore.ts' |
3 | | -import type { BIDSFile, FileTree } from '../types/filetree.ts' |
4 | | -import { filesToTree, pathsToTree } from './filetree.ts' |
| 2 | +import { FileIgnoreRules } from './ignore.ts' |
| 3 | +import { BIDSFile, type FileOpener, type FileTree } from '../types/filetree.ts' |
| 4 | +import { filesToTree } from './filetree.ts' |
| 5 | +import { asyncStreamFromString } from '../tests/utils.ts' |
| 6 | + |
| 7 | +class NullFileOpener implements FileOpener { |
| 8 | + size = 0 |
| 9 | + stream = () => asyncStreamFromString('') |
| 10 | + text = () => Promise.resolve('') |
| 11 | + readBytes = async (size: number, offset?: number) => new Uint8Array() |
| 12 | +} |
| 13 | + |
| 14 | +export function pathToFile(path: string, ignored: boolean = false): BIDSFile { |
| 15 | + const name = path.split('/').pop() as string |
| 16 | + return new BIDSFile(path, new NullFileOpener(), ignored) |
| 17 | +} |
| 18 | + |
| 19 | +export function pathsToTree(paths: string[], ignore?: string[]): FileTree { |
| 20 | + const ignoreRules = new FileIgnoreRules(ignore ?? []) |
| 21 | + return filesToTree(paths.map((path) => pathToFile(path, ignoreRules.test(path)))) |
| 22 | +} |
5 | 23 |
|
6 | 24 | Deno.test('FileTree generation', async (t) => { |
7 | 25 | await t.step('converts a basic list', async () => { |
|
0 commit comments