Skip to content

Commit

Permalink
convert arrow, arrow unicode, colors, constants, language
Browse files Browse the repository at this point in the history
  • Loading branch information
StoneCypher committed Jan 15, 2021
1 parent a2b70f9 commit dd8b528
Show file tree
Hide file tree
Showing 8 changed files with 385 additions and 4 deletions.
3 changes: 1 addition & 2 deletions src/ts/tests/actions.js
Expand Up @@ -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');



Expand Down
2 changes: 1 addition & 1 deletion 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;


Expand Down
2 changes: 1 addition & 1 deletion 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');



Expand Down
86 changes: 86 additions & 0 deletions 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
122 changes: 122 additions & 0 deletions 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
64 changes: 64 additions & 0 deletions 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
72 changes: 72 additions & 0 deletions 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 };

0 comments on commit dd8b528

Please sign in to comment.