Skip to content

Commit 0c4c2c1

Browse files
committed
rf: Move test functions into test file
1 parent f0f3d26 commit 0c4c2c1

16 files changed

+36
-36
lines changed

src/files/filetree.test.ts

Lines changed: 21 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -1,7 +1,25 @@
11
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+
}
523

624
Deno.test('FileTree generation', async (t) => {
725
await t.step('converts a basic list', async () => {

src/files/filetree.ts

Lines changed: 1 addition & 19 deletions
Original file line numberDiff line numberDiff line change
@@ -1,25 +1,7 @@
11
import { parse, SEPARATOR_PATTERN } from '@std/path'
22
import * as posix from '@std/path/posix'
3-
import { BIDSFile, FileOpener, FileTree } from '../types/filetree.ts'
3+
import { BIDSFile, FileTree } from '../types/filetree.ts'
44
import { FileIgnoreRules } from './ignore.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-
}
235

246
export function filesToTree(fileList: BIDSFile[], ignore?: FileIgnoreRules): FileTree {
257
ignore = ignore ?? new FileIgnoreRules([])

src/files/inheritance.test.ts

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -1,6 +1,6 @@
11
import { assert, assertEquals, assertThrows } from '@std/assert'
22
import type { BIDSFile } from '../types/filetree.ts'
3-
import { pathsToTree } from './filetree.ts'
3+
import { pathsToTree } from './filetree.test.ts'
44
import { walkBack } from './inheritance.ts'
55

66
Deno.test('walkback inheritance tests', async (t) => {

src/files/json.test.ts

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -3,7 +3,7 @@ import type { BIDSFile } from '../types/filetree.ts'
33
import type { FileIgnoreRules } from './ignore.ts'
44
import { testAsyncFileAccess } from './access.test.ts'
55

6-
import { pathsToTree } from '../files/filetree.ts'
6+
import { pathsToTree } from '../files/filetree.test.ts'
77
import { loadJSON } from './json.ts'
88

99
function encodeUTF16(text: string) {

src/files/tsv.test.ts

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -5,7 +5,7 @@ import {
55
assertObjectMatch,
66
assertStrictEquals,
77
} from '@std/assert'
8-
import { pathToFile } from './filetree.ts'
8+
import { pathToFile } from './filetree.test.ts'
99
import { BIDSFileDeno } from './deno.ts'
1010
import { loadTSV, loadTSVGZ } from './tsv.ts'
1111
import { asyncStreamFromString } from '../tests/utils.ts'

src/issues/datasetIssues.test.ts

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -1,5 +1,5 @@
11
import { assert, assertEquals, assertThrows } from '@std/assert'
2-
import { pathsToTree } from '../files/filetree.ts'
2+
import { pathsToTree } from '../files/filetree.test.ts'
33
import { DatasetIssues } from './datasetIssues.ts'
44

55
Deno.test('DatasetIssues management class', async (t) => {

src/schema/datatypes.test.ts

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -1,7 +1,7 @@
11
import { assert, assertObjectMatch } from '@std/assert'
22
import { loadSchema } from '../setup/loadSchema.ts'
33
import { BIDSContext, BIDSContextDataset } from '../schema/context.ts'
4-
import { pathsToTree } from '../files/filetree.ts'
4+
import { pathsToTree } from '../files/filetree.test.ts'
55
import type { BIDSFile } from '../types/filetree.ts'
66

77
import { findDatatype, modalityTable } from './datatypes.ts'

src/schema/fixtures.test.ts

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -1,5 +1,5 @@
11
import type { BIDSFile, FileTree } from '../types/filetree.ts'
2-
import { pathsToTree } from '../files/filetree.ts'
2+
import { pathsToTree } from '../files/filetree.test.ts'
33
import { nullReadBytes } from '../tests/nullReadBytes.ts'
44

55
const anatJson = JSON.stringify({

src/schema/walk.test.ts

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -3,7 +3,7 @@ import { BIDSContext, BIDSContextDataset } from './context.ts'
33
import { walkFileTree } from './walk.ts'
44
import type { DatasetIssues } from '../issues/datasetIssues.ts'
55
import { simpleDataset, simpleDatasetFileCount } from '../tests/simple-dataset.ts'
6-
import { pathsToTree } from '../files/filetree.ts'
6+
import { pathsToTree } from '../files/filetree.test.ts'
77
import { loadSchema } from '../setup/loadSchema.ts'
88

99
Deno.test('file tree walking', async (t) => {

src/tests/regression.test.ts

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -1,5 +1,5 @@
11
import { assert } from '@std/assert'
2-
import { pathsToTree } from '../files/filetree.ts'
2+
import { pathsToTree } from '../files/filetree.test.ts'
33
import { validate } from '../validators/bids.ts'
44
import type { BIDSFile } from '../types/filetree.ts'
55
import { asyncStreamFromString } from './utils.ts'

0 commit comments

Comments
 (0)