|
1 | 1 | import { assert, assertEquals } from '@std/assert' |
2 | 2 | import { filenameIdentify } from './filenameIdentify.ts' |
3 | 3 | import { filenameValidate } from './filenameValidate.ts' |
4 | | -import { BIDSContext } from '../schema/context.ts' |
| 4 | +import { BIDSContext, BIDSContextDataset } from '../schema/context.ts' |
5 | 5 | import { loadSchema } from '../setup/loadSchema.ts' |
6 | 6 | import type { GenericSchema, Schema } from '../types/schema.ts' |
7 | 7 | import type { DatasetIssues } from '../issues/datasetIssues.ts' |
8 | | -import { pathToFile } from '../files/filetree.ts' |
| 8 | +import type { BIDSFile } from '../types/filetree.ts' |
| 9 | +import { pathsToTree } from '../files/filetree.ts' |
9 | 10 |
|
10 | | -const schema = await loadSchema() as unknown as GenericSchema |
| 11 | +const schema = await loadSchema() |
11 | 12 |
|
12 | | -function validatePath(path: string): DatasetIssues { |
13 | | - const context = new BIDSContext(pathToFile(path)) |
14 | | - filenameIdentify(schema, context) |
15 | | - filenameValidate(schema, context) |
16 | | - return context.dataset.issues |
| 13 | +function makeContext(path: string): BIDSContext { |
| 14 | + const tree = pathsToTree([path]) |
| 15 | + const dataset = new BIDSContextDataset({ schema, tree }) |
| 16 | + return new BIDSContext(tree.get(path) as BIDSFile, dataset) |
17 | 17 | } |
18 | 18 |
|
19 | 19 | Deno.test('test valid paths', async (t) => { |
@@ -54,11 +54,13 @@ Deno.test('test valid paths', async (t) => { |
54 | 54 | ] |
55 | 55 | for (const filename of validFiles) { |
56 | 56 | await t.step(filename, async () => { |
57 | | - const issues = validatePath(filename) |
| 57 | + const context = makeContext(filename) |
| 58 | + await filenameIdentify(schema, context) |
| 59 | + await filenameValidate(schema as unknown as GenericSchema, context) |
58 | 60 | assertEquals( |
59 | | - issues.get({ location: filename }).length, |
| 61 | + context.dataset.issues.get({ location: filename }).length, |
60 | 62 | 0, |
61 | | - Deno.inspect(issues), |
| 63 | + Deno.inspect(context.dataset.issues), |
62 | 64 | ) |
63 | 65 | }) |
64 | 66 | } |
@@ -111,9 +113,9 @@ Deno.test('test invalid paths', async (t) => { |
111 | 113 | ] |
112 | 114 | for (const filename of invalidFiles) { |
113 | 115 | await t.step(filename, async () => { |
114 | | - const context = new BIDSContext(pathToFile(filename)) |
| 116 | + const context = makeContext(filename) |
115 | 117 | await filenameIdentify(schema, context) |
116 | | - await filenameValidate(schema, context) |
| 118 | + await filenameValidate(schema as unknown as GenericSchema, context) |
117 | 119 | assert( |
118 | 120 | context.dataset.issues.get({ |
119 | 121 | location: context.file.path, |
|
0 commit comments