-
Notifications
You must be signed in to change notification settings - Fork 7
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
Merge pull request #218 from VisLab/update-tokenizer
Started on the parsedHedTag tests
- Loading branch information
Showing
6 changed files
with
252 additions
and
4 deletions.
There are no files selected for viewing
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,57 @@ | ||
{ | ||
"char_regex": { | ||
"alphanumeric": "[A-Za-z0-9]", | ||
"ampersand": "&", | ||
"ascii": "[\\x00-\\x7F]", | ||
"asterisk": "\\*", | ||
"at-sign": "@", | ||
"backslash": "\\", | ||
"blank": " ", | ||
"caret": "\\^", | ||
"colon": ":", | ||
"comma": ",", | ||
"date-time": "\\d{4}-\\d{2}-\\d{2}T\\d{2}:\\d{2}:\\d{2}(?:\\.\\d+)?(?:Z|[+-]\\d{2}:\\d{2})?", | ||
"dollar": "\\$", | ||
"digits": "[0-9]", | ||
"double-quote": "\"", | ||
"equals": "=", | ||
"exclamation": "!", | ||
"greater-than": ">", | ||
"hyphen": "-", | ||
"left-paren": "(", | ||
"less-than": "<", | ||
"letters": "[A-Za-z]", | ||
"lowercase": "[a-z]", | ||
"name": "[\\w\\-\\u0080-\\uFFFF]", | ||
"newline": "\\n", | ||
"nonascii": "[\\u0080-\\uFFFF]", | ||
"number-sign": "#", | ||
"numeric": "[0-9.\\-+^Ee]", | ||
"percent-sign": "%", | ||
"period": "\\.", | ||
"plus": "\\+", | ||
"printable": "[\\x20-\\x7E]", | ||
"question-mark": "\\?", | ||
"right-paren": "(", | ||
"semicolon": ";", | ||
"single-quote": "'", | ||
"forward-slash": "/", | ||
"tab": "\\t", | ||
"text": "[^\\x00-\\x1F\\x7F,{}]", | ||
"tilde": "~", | ||
"underscore": "_", | ||
"uppercase": "[A-Z]", | ||
"vertical-bar": "|" | ||
}, | ||
"class_chars": { | ||
"dateTimeClass": [], | ||
"nameClass": ["alphanumeric", "underscore", "hyphen", "nonascii"], | ||
"numericClass": [], | ||
"textClass": ["text"], | ||
"testClass": ["newline", "tab", "nonascii"] | ||
}, | ||
"class_words": { | ||
"dateTimeClass": "^\\d{4}-\\d{2}-\\d{2}T\\d{2}:\\d{2}:\\d{2}(?:\\.\\d+)?(?:Z|[+-]\\d{2}:\\d{2})?$", | ||
"numericClass": "^[+-]?(\\d+(\\.\\d*)?|\\.\\d+)([eE][+-]?\\d+)?$" | ||
} | ||
} |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,66 @@ | ||
import chai from 'chai' | ||
const assert = chai.assert | ||
import { beforeAll, describe, afterAll } from '@jest/globals' | ||
|
||
import ParsedHedTag from '../parser/parsedHedTag' | ||
import { shouldRun } from './testUtilities' | ||
import { parsedHedTagTests } from './testData/parsedHedTagTests.data' | ||
import { SchemaSpec, SchemasSpec } from '../schema/specs' | ||
import path from 'path' | ||
import { buildSchemas } from '../schema/init' | ||
import { SchemaTag } from '../schema/entries' | ||
|
||
// Ability to select individual tests to run | ||
const skipMap = new Map() | ||
const runAll = true | ||
const runMap = new Map([[]]) | ||
|
||
describe('TagSpec converter tests using JSON tests', () => { | ||
const schemaMap = new Map([ | ||
['8.2.0', undefined], | ||
['8.3.0', undefined], | ||
]) | ||
|
||
beforeAll(async () => { | ||
const spec2 = new SchemaSpec('', '8.2.0', '', path.join(__dirname, '../tests/data/HED8.2.0.xml')) | ||
const specs2 = new SchemasSpec().addSchemaSpec(spec2) | ||
const schemas2 = await buildSchemas(specs2) | ||
const spec3 = new SchemaSpec('', '8.3.0', '', path.join(__dirname, '../tests/data/HED8.3.0.xml')) | ||
const specs3 = new SchemasSpec().addSchemaSpec(spec3) | ||
const schemas3 = await buildSchemas(specs3) | ||
schemaMap.set('8.2.0', schemas2) | ||
schemaMap.set('8.3.0', schemas3) | ||
}) | ||
|
||
afterAll(() => {}) | ||
|
||
describe.each(parsedHedTagTests)('$name : $description', ({ name, tests }) => { | ||
const hedTagTest = function (test) { | ||
const status = test.errors.length > 0 ? 'Expect fail' : 'Expect pass' | ||
const header = `\n[${test.testname}](${status}): ${test.explanation}` | ||
|
||
const thisSchema = schemaMap.get(test.schemaVersion) | ||
assert.isDefined(thisSchema, `header: ${test.schemaVersion} is not available in test ${test.name}`) | ||
|
||
const tag = new ParsedHedTag(test.tagSpec, thisSchema) | ||
|
||
assert.strictEqual(tag.formattedTag, test.formattedTag) | ||
assert.strictEqual(tag.format(false), test.tagShort) | ||
assert.strictEqual(tag.format(true), test.tagLong) | ||
} | ||
|
||
beforeAll(async () => {}) | ||
|
||
afterAll(() => {}) | ||
|
||
if (tests && tests.length > 0) { | ||
test.each(tests)('$testname: $explanation for "$string"', (test) => { | ||
if (shouldRun(name, test.testname, runAll, runMap, skipMap)) { | ||
hedTagTest(test) | ||
} else { | ||
console.log(`----Skipping ${name}: ${test.testname}`) | ||
} | ||
}) | ||
} | ||
}) | ||
}) |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,45 @@ | ||
import { generateIssue } from '../../common/issues/issues' | ||
import { ColumnSpliceSpec, GroupSpec, TagSpec } from '../../parser/tokenizer' | ||
|
||
export const parsedHedTagTests = [ | ||
{ | ||
name: 'valid-tags', | ||
description: 'Valid placeholders in various places', | ||
warning: false, | ||
tests: [ | ||
{ | ||
testname: 'valid-tag-one-level', | ||
explanation: '"Item" is a top-level-tag.', | ||
schemaVersion: '8.3.0', | ||
fullString: 'Item', | ||
tagSpec: new TagSpec('Item', 0, 5, ''), | ||
tagLong: 'Item', | ||
tagShort: 'Item', | ||
formattedTag: 'item', | ||
errors: [], | ||
}, | ||
{ | ||
testname: 'valid-tag-with-blanks', | ||
explanation: '" Item " has surrounding blanks.', | ||
schemaVersion: '8.3.0', | ||
fullString: ' Item ', | ||
tagSpec: new TagSpec('Item', 1, 6, ''), | ||
tagLong: 'Item', | ||
tagShort: 'Item', | ||
formattedTag: 'item', | ||
errors: [], | ||
}, | ||
{ | ||
testname: 'valid-tag-with-blanks', | ||
explanation: '" Item " has surrounding blanks.', | ||
schemaVersion: '8.3.0', | ||
fullString: ' Item ', | ||
tagSpec: new TagSpec('Item', 1, 6, ''), | ||
tagLong: 'Item', | ||
tagShort: 'Item', | ||
formattedTag: 'item', | ||
errors: [], | ||
}, | ||
], | ||
}, | ||
] |