diff --git a/bids-validator/src/schema/applyRules.test.ts b/bids-validator/src/schema/applyRules.test.ts index 74d7528f1..df4b58b84 100644 --- a/bids-validator/src/schema/applyRules.test.ts +++ b/bids-validator/src/schema/applyRules.test.ts @@ -1,7 +1,7 @@ // @ts-nocheck import { assert, assertEquals, assertObjectMatch } from '../deps/asserts.ts' import { loadSchema } from '../setup/loadSchema.ts' -import { applyRules, evalCheck } from './applyRules.ts' +import { applyRules, evalCheck, evalColumns } from './applyRules.ts' import { DatasetIssues } from '../issues/datasetIssues.ts' const ruleContextData = [ @@ -45,6 +45,24 @@ const schemaDefs = { }, }, }, + tabular_data: { + modality_agnostic: { + Scans: { + selectors: ['suffix == "scans"', 'extension == ".tsv"'], + initial_columns: ['filename'], + columns: { + filename: { + level: 'required', + description_addendum: + 'There MUST be exactly one row for each file.', + }, + acq_time__scans: 'optional', + }, + index_columns: ['filename'], + additional_columns: 'allowed', + }, + }, + }, }, } @@ -107,3 +125,23 @@ Deno.test( assert(context.issues.hasIssue({ key: 'CHECK_ERROR' })) }, ) + +Deno.test('check column contents', async (t) => { + const schema = await loadSchema() + + await t.step('check invalid datetime (scans.tsv:acq_time)', () => { + const context = { + path: '/sub-01/sub-01_scans.tsv', + extension: '.tsv', + sidecar: {}, + columns: { + filename: ['func/sub-01_task-rest_bold.nii.gz'], + acq_time: ['1900-01-01T00:00:78'], + }, + issues: new DatasetIssues(), + } + const rule = schemaDefs.rules.tabular_data.modality_agnostic.Scans + evalColumns(rule, context, schema, 'rules.tabular_data.modality_agnostic.Scans') + assert(context.issues.hasIssue({ key: 'TSV_VALUE_INCORRECT_TYPE_NONREQUIRED' })) + }) +}) diff --git a/bids-validator/src/schema/applyRules.ts b/bids-validator/src/schema/applyRules.ts index 91e0664fa..5df36c52f 100644 --- a/bids-validator/src/schema/applyRules.ts +++ b/bids-validator/src/schema/applyRules.ts @@ -220,7 +220,7 @@ function sidecarDefinedTypeCheck( * otherwise we type check each value in the column according to the type * specified in the schema rule (or sidecar type information if applicable). */ -function evalColumns( +export function evalColumns( rule: GenericRule, context: BIDSContext, schema: GenericSchema,