diff --git a/src/ts/tests/actions.js b/src/ts/tests/actions.js index af8396a8..c1d25942 100644 --- a/src/ts/tests/actions.js +++ b/src/ts/tests/actions.js @@ -3,8 +3,7 @@ import {describe} from 'ava-spec'; -const jssm = require('../../../build/jssm.es5.cjs.js'), - sm = jssm.sm; +const jssm = require('../../../build/jssm.es5.cjs.js'); diff --git a/src/ts/tests/actions.spec.ts b/src/ts/tests/actions.spec.ts index 978ce463..cdf332c4 100644 --- a/src/ts/tests/actions.spec.ts +++ b/src/ts/tests/actions.spec.ts @@ -1,7 +1,7 @@ /* eslint-disable max-len */ -const jssm = require('../../../build/jssm.es5.cjs.js'), +const jssm = require('../jssm'), sm = jssm.sm; diff --git a/src/ts/tests/array_transitions.spec.ts b/src/ts/tests/array_transitions.spec.ts index b2161ad9..10a4ac97 100644 --- a/src/ts/tests/array_transitions.spec.ts +++ b/src/ts/tests/array_transitions.spec.ts @@ -1,7 +1,7 @@ /* eslint-disable max-len */ -const jssm = require('../../../build/jssm.es5.cjs.js'); +const jssm = require('../jssm'); diff --git a/src/ts/tests/arrow unicode.spec.ts b/src/ts/tests/arrow unicode.spec.ts new file mode 100644 index 00000000..0795fd6c --- /dev/null +++ b/src/ts/tests/arrow unicode.spec.ts @@ -0,0 +1,86 @@ + /* eslint-disable max-len */ + +const jssm = require('../../../build/jssm.es5.cjs.js'); + + + + + +describe('arrow_direction', () => { + + test('verify ←', () => expect(jssm.arrow_direction('←')).toBe('left')); + test('verify ⇐', () => expect(jssm.arrow_direction('⇐')).toBe('left')); + test('verify ↚', () => expect(jssm.arrow_direction('↚')).toBe('left')); + + test('verify →', () => expect(jssm.arrow_direction('→')).toBe('right')); + test('verify ⇒', () => expect(jssm.arrow_direction('⇒')).toBe('right')); + test('verify ↛', () => expect(jssm.arrow_direction('↛')).toBe('right')); + + test('verify ↔', () => expect(jssm.arrow_direction('↔')).toBe('both')); + test('verify ⇔', () => expect(jssm.arrow_direction('⇔')).toBe('both')); + test('verify ↮', () => expect(jssm.arrow_direction('↮')).toBe('both')); + + test('verify ←⇒', () => expect(jssm.arrow_direction('←⇒')).toBe('both')); + test('verify ⇐→', () => expect(jssm.arrow_direction('⇐→')).toBe('both')); + test('verify ←↛', () => expect(jssm.arrow_direction('←↛')).toBe('both')); + test('verify ↚→', () => expect(jssm.arrow_direction('↚→')).toBe('both')); + test('verify ⇐↛', () => expect(jssm.arrow_direction('⇐↛')).toBe('both')); + test('verify ↚⇒', () => expect(jssm.arrow_direction('↚⇒')).toBe('both')); + +}); + + + + + +describe('arrow_left_kind', () => { + + test('verify →', () => expect(jssm.arrow_left_kind('→')).toBe('none')); + test('verify ⇒', () => expect(jssm.arrow_left_kind('⇒')).toBe('none')); + test('verify ↛', () => expect(jssm.arrow_left_kind('↛')).toBe('none')); + + test('verify ←', () => expect(jssm.arrow_left_kind('←')).toBe('legal')); + test('verify ↔', () => expect(jssm.arrow_left_kind('↔')).toBe('legal')); + test('verify ←⇒', () => expect(jssm.arrow_left_kind('←⇒')).toBe('legal')); + test('verify ←↛', () => expect(jssm.arrow_left_kind('←↛')).toBe('legal')); + + test('verify ⇐', () => expect(jssm.arrow_left_kind('⇐')).toBe('main')); + test('verify ⇔', () => expect(jssm.arrow_left_kind('⇔')).toBe('main')); + test('verify ⇐→', () => expect(jssm.arrow_left_kind('⇐→')).toBe('main')); + test('verify ⇐↛', () => expect(jssm.arrow_left_kind('⇐↛')).toBe('main')); + + test('verify ↚', () => expect(jssm.arrow_left_kind('↚')).toBe('forced')); + test('verify ↮', () => expect(jssm.arrow_left_kind('↮')).toBe('forced')); + test('verify ↚→', () => expect(jssm.arrow_left_kind('↚→')).toBe('forced')); + test('verify ↚⇒', () => expect(jssm.arrow_left_kind('↚⇒')).toBe('forced')); + +}); + + + + + +describe('arrow_right_kind', () => { + + test('verify ←', () => expect(jssm.arrow_right_kind('←')).toBe('none')); + test('verify ⇐', () => expect(jssm.arrow_right_kind('⇐')).toBe('none')); + test('verify ↚', () => expect(jssm.arrow_right_kind('↚')).toBe('none')); + + test('verify →', () => expect(jssm.arrow_right_kind('→')).toBe('legal')); + test('verify ↔', () => expect(jssm.arrow_right_kind('↔')).toBe('legal')); + test('verify ⇐→', () => expect(jssm.arrow_right_kind('⇐→')).toBe('legal')); + test('verify ↚→', () => expect(jssm.arrow_right_kind('↚→')).toBe('legal')); + + test('verify ⇒', () => expect(jssm.arrow_right_kind('⇒')).toBe('main')); + test('verify ⇔', () => expect(jssm.arrow_right_kind('⇔')).toBe('main')); + test('verify ←⇒', () => expect(jssm.arrow_right_kind('←⇒')).toBe('main')); + test('verify ↚⇒', () => expect(jssm.arrow_right_kind('↚⇒')).toBe('main')); + + test('verify ↛', () => expect(jssm.arrow_right_kind('↛')).toBe('forced')); + test('verify ↮', () => expect(jssm.arrow_right_kind('↮')).toBe('forced')); + test('verify ←↛', () => expect(jssm.arrow_right_kind('←↛')).toBe('forced')); + test('verify ⇐↛', () => expect(jssm.arrow_right_kind('⇐↛')).toBe('forced')); + +}); + +// stochable diff --git a/src/ts/tests/arrow.spec.ts b/src/ts/tests/arrow.spec.ts new file mode 100644 index 00000000..c0cce844 --- /dev/null +++ b/src/ts/tests/arrow.spec.ts @@ -0,0 +1,122 @@ + +/* eslint-disable max-len */ + +const jssm = require('../jssm'); + + + + + +describe('arrow_direction', () => { + + const lefts = ['<-', '<=', '<~', '←', '⇐', '↚'], + rights = ['->', '=>', '~>', '→', '⇒', '↛'], + boths = ['<->', '<=>', '<~>', + '<-=>', '<-~>', '<=->', '<=~>', '<~->', '<~=>', + '←⇒', '←↛', '⇐→', '⇐↛', '↚→', '↚⇒', + '←=>', '←~>', '⇐->', '⇐~>', '↚->', '↚=>', + '<-⇒', '<-↛', '<=→', '<=↛', '<~→', '<~⇒' ], + + check = (lab, dir) => + it(lab, () => + expect( jssm.arrow_direction(lab) ).toBe(dir) ); + + lefts.map( e => check(e, 'left') ); + rights.map( e => check(e, 'right') ); + boths.map( e => check(e, 'both') ); + +/* + test('<-', () => expect(jssm.arrow_direction('<-') ).toBe('left') ); + test('<=', () => expect(jssm.arrow_direction('<=') ).toBe('left') ); + test('<~', () => expect(jssm.arrow_direction('<~') ).toBe('left') ); + + test('->', () => expect(jssm.arrow_direction('->') ).toBe('right') ); + test('=>', () => expect(jssm.arrow_direction('=>') ).toBe('right') ); + test('~>', () => expect(jssm.arrow_direction('~>') ).toBe('right') ); + + test('<->', () => expect(jssm.arrow_direction('<->') ).toBe('both') ); + test('<=>', () => expect(jssm.arrow_direction('<=>') ).toBe('both') ); + test('<~>', () => expect(jssm.arrow_direction('<~>') ).toBe('both') ); + + test('<-=>', () => expect(jssm.arrow_direction('<-=>') ).toBe('both') ); + test('<=->', () => expect(jssm.arrow_direction('<=->') ).toBe('both') ); + test('<-~>', () => expect(jssm.arrow_direction('<-~>') ).toBe('both') ); + test('<~->', () => expect(jssm.arrow_direction('<~->') ).toBe('both') ); + test('<=~>', () => expect(jssm.arrow_direction('<=~>') ).toBe('both') ); + test('<~=>', () => expect(jssm.arrow_direction('<~=>') ).toBe('both') ); +*/ + +}); + + + + + +describe('arrow_left_kind', () => { + + test('->', () => expect(jssm.arrow_left_kind('->') ).toBe('none') ); + test('=>', () => expect(jssm.arrow_left_kind('=>') ).toBe('none') ); + test('~>', () => expect(jssm.arrow_left_kind('~>') ).toBe('none') ); + + test('<-', () => expect(jssm.arrow_left_kind('<-') ).toBe('legal') ); + test('<->', () => expect(jssm.arrow_left_kind('<->') ).toBe('legal') ); + test('<-=>', () => expect(jssm.arrow_left_kind('<-=>') ).toBe('legal') ); + test('<-~>', () => expect(jssm.arrow_left_kind('<-~>') ).toBe('legal') ); + + test('<=', () => expect(jssm.arrow_left_kind('<=') ).toBe('main') ); + test('<=>', () => expect(jssm.arrow_left_kind('<=>') ).toBe('main') ); + test('<=->', () => expect(jssm.arrow_left_kind('<=->') ).toBe('main') ); + test('<=~>', () => expect(jssm.arrow_left_kind('<=~>') ).toBe('main') ); + + test('<~', () => expect(jssm.arrow_left_kind('<~') ).toBe('forced') ); + test('<~>', () => expect(jssm.arrow_left_kind('<~>') ).toBe('forced') ); + test('<~->', () => expect(jssm.arrow_left_kind('<~->') ).toBe('forced') ); + test('<~=>', () => expect(jssm.arrow_left_kind('<~=>') ).toBe('forced') ); + +}); + + + + + +describe('arrow_right_kind', () => { + + test('<-', () => expect(jssm.arrow_right_kind('<-') ).toBe('none') ); + test('<=', () => expect(jssm.arrow_right_kind('<=') ).toBe('none') ); + test('<~', () => expect(jssm.arrow_right_kind('<~') ).toBe('none') ); + + test('->', () => expect(jssm.arrow_right_kind('->') ).toBe('legal') ); + test('<->', () => expect(jssm.arrow_right_kind('<->') ).toBe('legal') ); + test('<=->', () => expect(jssm.arrow_right_kind('<=->') ).toBe('legal') ); + test('<~->', () => expect(jssm.arrow_right_kind('<~->') ).toBe('legal') ); + + test('=>', () => expect(jssm.arrow_right_kind('=>') ).toBe('main') ); + test('<=>', () => expect(jssm.arrow_right_kind('<=>') ).toBe('main') ); + test('<-=>', () => expect(jssm.arrow_right_kind('<-=>') ).toBe('main') ); + test('<~=>', () => expect(jssm.arrow_right_kind('<~=>') ).toBe('main') ); + + test('~>', () => expect(jssm.arrow_right_kind('~>') ).toBe('forced') ); + test('<~>', () => expect(jssm.arrow_right_kind('<~>') ).toBe('forced') ); + test('<-~>', () => expect(jssm.arrow_right_kind('<-~>') ).toBe('forced') ); + test('<=~>', () => expect(jssm.arrow_right_kind('<=~>') ).toBe('forced') ); + +}); + + + + + +describe('arrow error catchery', () => { + + test('unknown arrow direction throws', () => + expect( () => jssm.arrow_direction('boop') ).toThrow() ); + + test('unknown arrow left kind throws', () => + expect( () => jssm.arrow_left_kind('boop') ).toThrow() ); + + test('unknown arrow right kind throws', () => + expect( () => jssm.arrow_right_kind('boop') ).toThrow() ); + +}); + +// stochable diff --git a/src/ts/tests/colors.spec.ts b/src/ts/tests/colors.spec.ts new file mode 100644 index 00000000..b69fa49e --- /dev/null +++ b/src/ts/tests/colors.spec.ts @@ -0,0 +1,64 @@ + +import { NamedColors } from './constants.spec'; + + + + + +const jssm = require('../jssm'), + sm = jssm.sm; + + + + + +describe('Colors', () => { + +/* eslint-disable max-nested-callbacks */ + + const ColorSets = [ + { label: "Named colors", dataset: NamedColors }, + { label: "Direct colors", dataset: [ '#ABC', '#ABCF', '#AABBCC', '#AABBCCFF' ] } + ]; + + ColorSets.map( ({label, dataset}) => + + dataset.map(col => { + + // edge things + ['edge_color'].map(prop => + [col, col.toLowerCase()].map(repres => + test(`${label} - Color "${repres}" parses as ${prop}`, () => + + expect( () => { + const _foo = sm`machine_name: bob; a-> { ${prop}: ${repres}; } b;`; + }).not.toThrow() + + ) + ) + ); + + // state things + ['color', 'background-color', 'text-color', 'border-color'].map(prop => + [col, col.toLowerCase()].map(repres => + test(`${label} - Color "${repres}" parses as ${prop}`, () => + + expect( () => { + const _foo = sm`machine_name: bob; state a: { ${prop}: ${repres}; }; a -> b;`; + }).not.toThrow() + + ) + ) + ); + + }) + ); + +/* eslint-enable max-nested-callbacks */ + +}); + +// TODO FIXME COMEBACK tests for the other color types +// TODO FIXME COMEBACK check that the named colors are coming out sensibly + +// TODO FIXME COMEBACK STOCHABLE assert that #f00, #ff0000, #f00f, #ff0000ff, and red all parse as the same color diff --git a/src/ts/tests/constants.spec.ts b/src/ts/tests/constants.spec.ts new file mode 100644 index 00000000..2d818e3b --- /dev/null +++ b/src/ts/tests/constants.spec.ts @@ -0,0 +1,72 @@ + +/* constant lists for tests */ + + + + + +const Shapes = ["box", "polygon", "ellipse", "oval", "circle", "point", "egg", "triangle", "plaintext", "plain", + "diamond", "trapezium", "parallelogram", "house", "pentagon", "hexagon", "septagon", "octagon", "doublecircle", + "doubleoctagon", "tripleoctagon", "invtriangle", "invtrapezium", "invhouse", "Mdiamond", "Msquare", "Mcircle", "rect", + "rectangle", "square", "star", "none", "underline", "cylinder", "note", "tab", "folder", "box3d", "component", + "promoter", "cds", "terminator", "utr", "primersite", "restrictionsite", "fivepoverhang", "threepoverhang", + "noverhang", "assembly", "signature", "insulator", "ribosite", "rnastab", "proteasesite", "proteinstab", "rpromoter", + "rarrow", "larrow", "lpromoter", "record"]; + + + + + +const NamedColors = ["AliceBlue", "AntiqueWhite", "Aqua", "Aquamarine", "Azure", "Beige", "Bisque", "Black", + "BlanchedAlmond", "Blue", "BlueViolet", "Brown", "BurlyWood", "CadetBlue", "Chartreuse", "Chocolate", "Coral", + "CornflowerBlue", "Cornsilk", "Crimson", "Cyan", "DarkBlue", "DarkCyan", "DarkGoldenRod", "DarkGray", "DarkGrey", + "DarkGreen", "DarkKhaki", "DarkMagenta", "DarkOliveGreen", "Darkorange", "DarkOrchid", "DarkRed", "DarkSalmon", + "DarkSeaGreen", "DarkSlateBlue", "DarkSlateGray", "DarkSlateGrey", "DarkTurquoise", "DarkViolet", "DeepPink", + "DeepSkyBlue", "DimGray", "DimGrey", "DodgerBlue", "FireBrick", "FloralWhite", "ForestGreen", "Fuchsia", "Gainsboro", + "GhostWhite", "Gold", "GoldenRod", "Gray", "Grey", "Green", "GreenYellow", "HoneyDew", "HotPink", "IndianRed", + "Indigo", "Ivory", "Khaki", "Lavender", "LavenderBlush", "LawnGreen", "LemonChiffon", "LightBlue", "LightCoral", + "LightCyan", "LightGoldenRodYellow", "LightGray", "LightGrey", "LightGreen", "LightPink", "LightSalmon", + "LightSeaGreen", "LightSkyBlue", "LightSlateGray", "LightSlateGrey", "LightSteelBlue", "LightYellow", "Lime", + "LimeGreen", "Linen", "Magenta", "Maroon", "MediumAquaMarine", "MediumBlue", "MediumOrchid", "MediumPurple", + "MediumSeaGreen", "MediumSlateBlue", "MediumSpringGreen", "MediumTurquoise", "MediumVioletRed", "MidnightBlue", + "MintCream", "MistyRose", "Moccasin", "NavajoWhite", "Navy", "OldLace", "Olive", "OliveDrab", "Orange", "OrangeRed", + "Orchid", "PaleGoldenRod", "PaleGreen", "PaleTurquoise", "PaleVioletRed", "PapayaWhip", "PeachPuff", "Peru", "Pink", + "Plum", "PowderBlue", "Purple", "Red", "RosyBrown", "RoyalBlue", "SaddleBrown", "Salmon", "SandyBrown", "SeaGreen", + "SeaShell", "Sienna", "Silver", "SkyBlue", "SlateBlue", "SlateGray", "SlateGrey", "Snow", "SpringGreen", "SteelBlue", + "Tan", "Teal", "Thistle", "Tomato", "Turquoise", "Violet", "Wheat", "White", "WhiteSmoke", "Yellow", "YellowGreen"]; + + + + + +const Themes = ["default", "ocean", "none", "modern"]; + +const FlowDirections = ['up','down','left','right']; + + + + + +// for coverage, and because ava throws on no-test files in its test directory + +describe('Constants', () => { + + test('Test shapes list isn\'t empty', () => + expect( Shapes.length > 1 ).toBe(true) ); + + test('Test named colors list isn\'t empty', () => + expect( NamedColors.length > 1 ).toBe(true) ); + + test('Test themes list isn\'t empty', () => + expect( Themes.length > 1 ).toBe(true) ); + + test('Test flow directions list isn\'t empty', () => + expect( FlowDirections.length > 1 ).toBe(true) ); + +}); + + + + + +export { NamedColors, Shapes, Themes, FlowDirections }; diff --git a/src/ts/tests/language.spec.ts b/src/ts/tests/language.spec.ts new file mode 100644 index 00000000..a66418b6 --- /dev/null +++ b/src/ts/tests/language.spec.ts @@ -0,0 +1,38 @@ + +/* eslint-disable max-len */ + +const glob = require('glob'); + +const jssm = require('../jssm'), + sm = jssm.sm, + + language_files = glob.sync('./src/ts/tests/language_data/*.json', {}) // for some reason glob is project-relative + .map(rel => rel.replace('/src/ts/tests', '')); // instead of execution relative like i'd expect + + + + + +describe('base data walk/1', () => { + + language_files.map( (language_file, i) => { + + const testData = require(language_file), + testTokens = testData.cases; + + const foreignTarget = sm([`${testData.native_name} -> ${testData.english_name} -> ${testTokens.join(' -> ')};`]); + + describe(`language ${i} "${testData.english_name}" contains all states`, () => { + + testTokens.map(tok => + test(tok, () => + expect( foreignTarget.states().includes(tok) ).toBe(true) + ) + ); + + }); + + }); + + +});