Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Added additional tests to bidsTests.spec #217

Merged
merged 4 commits into from
Nov 7, 2024
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
25 changes: 23 additions & 2 deletions parser/tokenizer.js
Original file line number Diff line number Diff line change
Expand Up @@ -11,6 +11,7 @@ const CHARACTERS = {
COMMA: ',',
COLON: ':',
SLASH: '/',
PLACEHOLDER: '#',
}

function getTrimmedBounds(originalString) {
Expand Down Expand Up @@ -231,11 +232,12 @@ export class HedStringTokenizer {
[CHARACTERS.CLOSING_GROUP, CHARACTERS.CLOSING_COLUMN].includes(this.state.lastDelimiter[0]) &&
trimmed.length > 0
) {
// A tag followed a group or column with no comma Ex: (x) yz
this.pushIssue('invalidTag', i, trimmed)
} else if (trimmed.length > 0) {
this.pushTag(i)
this.pushTag(i) // Tag has just finished
} else {
this.resetToken(i)
this.resetToken(i) // After a group or column
}
this.state.lastDelimiter = [CHARACTERS.COMMA, i]
}
Expand Down Expand Up @@ -341,6 +343,8 @@ export class HedStringTokenizer {
pushTag(i) {
if (this.state.currentToken.trim().length == 0) {
this.pushIssue('emptyTagFound', i)
} else if (this.checkForBadPlaceholderIssues(i)) {
this.pushInvalidTag('invalidPlaceholder', i, this.state.currentToken)
} else {
const bounds = getTrimmedBounds(this.state.currentToken)
this.state.currentGroupStack[this.state.groupDepth].push(
Expand All @@ -355,6 +359,23 @@ export class HedStringTokenizer {
}
}

checkForBadPlaceholderIssues() {
const tokenSplit = this.state.currentToken.split(CHARACTERS.PLACEHOLDER)
if (tokenSplit.length === 1) {
// No placeholders to worry about for this tag
return false
}
if (
tokenSplit.length > 2 ||
!tokenSplit[0].endsWith(CHARACTERS.SLASH) || // A placeholder must be after a slash
(tokenSplit[1].trim().length > 0 && tokenSplit[1][0] !== CHARACTERS.BLANK)
) {
// If units, blank after placeholder
return true
}
return false
}

closeGroup(i) {
const groupSpec = this.state.parenthesesStack.pop()
groupSpec.bounds[1] = i + 1
Expand Down
5 changes: 3 additions & 2 deletions tests/bidsTests.spec.js
Original file line number Diff line number Diff line change
Expand Up @@ -11,9 +11,10 @@ import { bidsTestData } from './testData/bidsTests.data'
import { shouldRun } from './testUtilities'

// Ability to select individual tests to run
const skipMap = new Map([['definition-tests', ['invalid-missing-definition-for-def', 'invalid-nested-definition']]])
//const skipMap = new Map([['definition-tests', ['invalid-missing-definition-for-def', 'invalid-nested-definition']]])
const skipMap = new Map()
const runAll = true
const runMap = new Map([['duplicate-tag-tests', ['invalid-nested-duplicate-json-reordered']]])
const runMap = new Map([['definition-tests', []]])

describe('BIDS validation', () => {
const schemaMap = new Map([
Expand Down
26 changes: 12 additions & 14 deletions tests/event.spec.js
Original file line number Diff line number Diff line change
Expand Up @@ -252,7 +252,7 @@ describe('HED string and event validation', () => {
})
})

describe('HED Tag Levels', () => {
describe.skip('HED Tag Levels', () => {
/**
* Tag level syntactic validation base function.
*
Expand Down Expand Up @@ -453,8 +453,8 @@ describe('HED string and event validation', () => {
})
})

// TODO: The testing of units should be in the stringParser
it('should not validate strings with short-to-long conversion errors', () => {
// TODO: REMOVE: The testing of units should be in the stringParser
it.skip('Test in string-parser should not validate strings with short-to-long conversion errors', () => {
const testStrings = {
// Duration/20 cm is an obviously invalid tag that should not be caught due to the first error.
red: 'Property/RGB-red, Duration/20 cm',
Expand Down Expand Up @@ -571,7 +571,7 @@ describe('HED string and event validation', () => {
}

// TODO: Already covered in stringParserTests -- units still to move down.
it.skip('REMOVE should exist in the schema or be an allowed extension', () => {
it.skip('(REMOVE) should exist in the schema or be an allowed extension', () => {
const testStrings = {
takesValue: 'Time-value/3 ms',
full: 'Left-side-of',
Expand Down Expand Up @@ -797,6 +797,7 @@ describe('HED string and event validation', () => {
)
}

// TODO: Equivalent tests now in bidsTests -- but only work for sidecar
it('should have syntactically valid definitions', () => {
const testStrings = {
nonDefinition: 'Car',
Expand Down Expand Up @@ -1068,7 +1069,8 @@ describe('HED string and event validation', () => {
)
}

it('should properly handle strings with placeholders', () => {
// TODO: Remove -- now in tokenizer tests
it('(REMOVE) should properly handle strings with placeholders', () => {
const testStrings = {
takesValue: 'RGB-red/#',
withUnit: 'Time-value/# ms',
Expand Down Expand Up @@ -1096,27 +1098,23 @@ describe('HED string and event validation', () => {
missingRequiredUnit: [],
wrongLocation: [
generateIssue('invalidPlaceholder', {
index: '16',
string: testStrings.wrongLocation,
tag: testStrings.wrongLocation,
}),
],
duplicatePlaceholder: [
generateIssue('invalidPlaceholder', {
tag: testStrings.duplicatePlaceholder,
}),
generateIssue('invalidPlaceholder', {
tag: testStrings.duplicatePlaceholder,
}),
generateIssue('invalidPlaceholder', {
tag: testStrings.duplicatePlaceholder,
}),
generateIssue('invalidTag', {
index: '8',
string: testStrings.duplicatePlaceholder,
tag: testStrings.duplicatePlaceholder,
}),
],
}
return validatorSemantic(testStrings, expectedIssues, true)
})

// TODO: Remove -- now in bidsTests as definition-tests
it('should have valid placeholders in definitions', () => {
const expectedPlaceholdersTestStrings = {
noPlaceholders: 'Car',
Expand Down
7 changes: 4 additions & 3 deletions tests/stringParserTests.spec.js
Original file line number Diff line number Diff line change
Expand Up @@ -3,17 +3,18 @@ const assert = chai.assert
import { beforeAll, describe, afterAll } from '@jest/globals'
import path from 'path'

import { BidsHedIssue } from '../bids/types/issues'
import { buildSchemas } from '../schema/init'
import { SchemaSpec, SchemasSpec } from '../schema/specs'

import { parseTestData } from './testData/stringParserTests.data'
import { shouldRun, getHedString } from './testUtilities'

// Ability to select individual tests to run
const skipMap = new Map()
const skipMap = new Map([
['placeholders-in-various-places', ['string-with-placeholder-not-allowed', 'place-holder-on-extension']],
])
const runAll = true
const runMap = new Map([['valid-mixed-groups', []]])
const runMap = new Map()

describe('Parse HED string tests', () => {
const schemaMap = new Map([
Expand Down
Loading
Loading