Skip to content

Commit

Permalink
test(expressions): Test file-relative existence check
Browse files Browse the repository at this point in the history
  • Loading branch information
effigies committed Aug 3, 2024
1 parent b14f20e commit 5ece19e
Showing 1 changed file with 9 additions and 4 deletions.
13 changes: 9 additions & 4 deletions bids-validator/src/schema/expressionLanguage.test.ts
Original file line number Diff line number Diff line change
Expand Up @@ -91,8 +91,9 @@ Deno.test('test expression functions', async (t) => {
assert(count(['a', 'b', 'a', 'b'], 'a') === 2)
assert(count(['a', 'b', 'a', 'b'], 'c') === 0)
})

const exists = expressionFunctions.exists.bind(context)
await t.step('exists(..., "dataset") function', () => {
const exists = expressionFunctions.exists.bind(context)
assert(exists([], 'dataset') === 0)
assert(
exists(['sub-01/ses-01/anat/sub-01_ses-01_T1w.nii.gz'], 'dataset') === 1,
Expand All @@ -105,7 +106,6 @@ Deno.test('test expression functions', async (t) => {
)
})
await t.step('exists(..., "subject") function', () => {
const exists = expressionFunctions.exists.bind(context)
assert(exists([], 'subject') === 0)
assert(exists(['ses-01/anat/sub-01_ses-01_T1w.nii.gz'], 'subject') === 1)
assert(
Expand All @@ -115,15 +115,19 @@ Deno.test('test expression functions', async (t) => {
) === 1,
)
})
await t.step('exists(..., "file") function', () => {
assert(exists([], 'file') === 0)
assert(exists(['sub-01_ses-01_T1w.nii.gz'], 'file') === 1)
assert(exists(['sub-01_ses-01_T1w.nii.gz', 'sub-01_ses-01_T1w.json'], 'file') === 2)
assert(exists(['sub-01_ses-01_T1w.nii.gz', 'ses-01_T1w.json'], 'file') === 1)
})
await t.step('exists(..., "stimuli") function', () => {
const exists = expressionFunctions.exists.bind(context)
assert(exists([], 'stimuli') === 0)
assert(exists(['stimfile1.png'], 'stimuli') === 1)
assert(exists(['stimfile1.png', 'stimfile2.png'], 'stimuli') === 2)
assert(exists(['X.png', 'Y.png'], 'stimuli') === 0)
})
await t.step('exists(..., "bids-uri") function', () => {
const exists = expressionFunctions.exists.bind(context)
assert(exists([], 'subject') === 0)
assert(
exists(
Expand All @@ -140,6 +144,7 @@ Deno.test('test expression functions', async (t) => {
// Not yet implemented; currently returns length of array
// assert(exists(['bids::sub-01/ses-01/anat/sub-01_ses-01_T1w.nii.gz', 'bids::T2w.json'], 'bids-uri') === 1)
})

await t.step('substr function', () => {
const substr = expressionFunctions.substr
assert(substr('abc', 0, 1) === 'a')
Expand Down

0 comments on commit 5ece19e

Please sign in to comment.