Skip to content

Commit

Permalink
Updated tests for curly brace recursion
Browse files Browse the repository at this point in the history
  • Loading branch information
VisLab committed Oct 27, 2024
1 parent 194717b commit aa3884e
Show file tree
Hide file tree
Showing 13 changed files with 632 additions and 317 deletions.
35 changes: 27 additions & 8 deletions parser/columnSplicer.js
Original file line number Diff line number Diff line change
Expand Up @@ -111,25 +111,36 @@ export class ColumnSplicer {
*/
_spliceTemplate(columnTemplate) {
const columnName = columnTemplate.originalTag
const replacementString = this.columnReplacements.get(columnName)
if (replacementString === undefined) {
this.issues.push(generateIssue('undefinedCurlyBraces', { column: columnName }))
return []

// HED column handled specially
if (columnName === 'HED') {
return this._spliceHedColumnTemplate()
}

// Not the HED column so treat as usual
const replacementString = this.columnReplacements.get(columnName)

// Handle null or undefined replacement strings
if (replacementString === null) {
return null
}
if (columnName === 'HED') {
return this._spliceHedColumnTemplate()
if (replacementString === undefined) {
this.issues.push(generateIssue('undefinedCurlyBraces', { column: columnName }))
return []
}

// Handle recursive curly braces
if (replacementString.columnSplices.length > 0) {
this.issues.push(generateIssue('recursiveCurlyBraces', { column: columnName }))
return []
}
const tagsHavePlaceholder = replacementString.tags.some((tag) => tag.originalTagName === '#')
if (tagsHavePlaceholder) {

// Handle value templates with placeholder
if (replacementString.tags.some((tag) => tag.originalTagName === '#')) {
return this._spliceValueTemplate(columnTemplate)
}

// Default case
return replacementString.parseTree
}

Expand All @@ -142,6 +153,14 @@ export class ColumnSplicer {
_spliceHedColumnTemplate() {
const columnName = 'HED'
const replacementString = this.columnValues.get(columnName)
if (replacementString === null || replacementString === 'n/a' || replacementString === '') {
return null
}

if (replacementString === undefined) {
this.issues.push(generateIssue('undefinedCurlyBraces', { column: columnName }))
return []
}
return this._reparseAndSpliceString(replacementString)
}

Expand Down
280 changes: 0 additions & 280 deletions tests/bidsTests.data.js

This file was deleted.

16 changes: 5 additions & 11 deletions tests/bidsTests.spec.js
Original file line number Diff line number Diff line change
Expand Up @@ -6,22 +6,20 @@ import path from 'path'
import { BidsHedIssue } from '../bids/types/issues'
import { buildSchemas } from '../validator/schema/init'
import { SchemaSpec, SchemasSpec } from '../common/schema/types'
import { BidsDataset, BidsEventFile, BidsHedTsvValidator, BidsSidecar, BidsTsvFile } from '../bids'
import { generateIssue, IssueError } from '../common/issues/issues'
import { BidsHedTsvValidator, BidsSidecar, BidsTsvFile } from '../bids'

import { bidsTestData } from './bidsTests.data'
import { bidsTestData } from './testData/bidsTests.data'
import parseTSV from '../bids/tsvParser'
const fs = require('fs')

//const displayLog = process.env.DISPLAY_LOG === 'true'
const displayLog = true
const skippedTests = new Map()

// Ability to select individual tests to run
const runAll = false
let onlyRun = new Map()
if (!runAll) {
onlyRun = new Map([['curly-brace-tests', ['invalid-HED-curly-brace-but-tsv-has-no-HED-column']]])
onlyRun = new Map([['duplicate-tag-tests', ['invalid-duplicate-groups-first-level-tsv']]])
}

function shouldRun(name, testname) {
Expand All @@ -31,11 +29,7 @@ function shouldRun(name, testname) {
const cases = onlyRun.get(name)
if (cases.length === 0) return true

if (cases.includes(testname)) {
return true
} else {
return false
}
return !!cases.includes(testname)
}

// Return an array of hedCode values extracted from an issues list.
Expand Down Expand Up @@ -84,7 +78,7 @@ describe('BIDS validation', () => {
}
})

describe.each(bidsTestData)('$name : $description', ({ name, description, tests }) => {
describe.each(bidsTestData)('$name : $description', ({ name, tests }) => {
let itemLog

const assertErrors = function (test, type, expectedErrors, issues, iLog) {
Expand Down
2 changes: 1 addition & 1 deletion tests/eventTests.spec.js
Original file line number Diff line number Diff line change
Expand Up @@ -14,7 +14,7 @@ import { BidsHedTsvParser } from '../bids/validator/bidsHedTsvValidator'
import { buildSchemas } from '../validator/schema/init'
import { BidsEventFile, BidsHedTsvValidator, BidsSidecar, BidsTsvFile } from '../bids'

import { eventTestData } from './eventTests.data'
import { eventTestData } from './testData/eventTests.data'
import parseTSV from '../bids/tsvParser'
const fs = require('fs')

Expand Down
Loading

0 comments on commit aa3884e

Please sign in to comment.