Skip to content

Commit

Permalink
Wrap parse(any, any) in parse(string, Object), fixes #543
Browse files Browse the repository at this point in the history
  • Loading branch information
StoneCypher committed Jan 16, 2021
1 parent d625d36 commit fa8385c
Show file tree
Hide file tree
Showing 4 changed files with 86 additions and 86 deletions.
12 changes: 10 additions & 2 deletions src/ts/jssm.ts
Expand Up @@ -215,6 +215,14 @@ function makeTransition<mDT>(



function wrap_parse(input: string, options?: Object) {
return parse(input, options || {});
}





function compile_rule_transition_step<mDT>(
acc : Array< JssmTransition<mDT> >,
from : string,
Expand Down Expand Up @@ -400,7 +408,7 @@ function compile<mDT>(tree: JssmParseTree): JssmGenericConfig<mDT> { // todo fl


function make<mDT>(plan: string): JssmGenericConfig<mDT> {
return compile(parse(plan, {}));
return compile(wrap_parse(plan));
}


Expand Down Expand Up @@ -1095,7 +1103,7 @@ export {
Machine,

make,
parse,
wrap_parse as parse,
compile,

sm,
Expand Down
3 changes: 1 addition & 2 deletions src/ts/tests/arrange.spec.ts
@@ -1,6 +1,5 @@

const jssm = require('../jssm'),
sm = jssm.sm;
import { sm } from '../jssm';



Expand Down
108 changes: 55 additions & 53 deletions src/ts/tests/arrow unicode.spec.ts
@@ -1,86 +1,88 @@
/* eslint-disable max-len */

const jssm = require('../jssm');
import * as jssm from '../jssm';





describe('arrow_direction', () => {
test.todo('Re-enable the unicode arrow blocks once we work that into the machine');

test('verify ←', () => expect(jssm.arrow_direction('←')).toBe('left'));
test('verify ⇐', () => expect(jssm.arrow_direction('⇐')).toBe('left'));
test('verify ↚', () => expect(jssm.arrow_direction('↚')).toBe('left'));
// describe('arrow_direction', () => {

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('left'));
// test('verify ', () => expect(jssm.arrow_direction('')).toBe('left'));
// test('verify ', () => expect(jssm.arrow_direction('')).toBe('left'));

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('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'));

});
// 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'));
// describe('arrow_left_kind', () => {

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('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('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('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('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'));
// 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'));
// describe('arrow_right_kind', () => {

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('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('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('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('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'));
// 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
// });

// // stochable
49 changes: 20 additions & 29 deletions src/ts/tests/stop light.spec.ts
@@ -1,45 +1,36 @@

/* eslint-disable max-len */

const jssm = require('../jssm');
import * as jssm from '../jssm';





describe('Simple stop light', () => {

const trs = [
{ name: 'SwitchToWarn', action: 'Proceed', from:'Green', to:'Yellow' },
{ name: 'SwitchToHalt', action: 'Proceed', from:'Yellow', to:'Red' },
{ name: 'SwitchToGo', action: 'Proceed', from:'Red', to:'Green' }
],
light = new jssm.Machine({
start_states : ['Red'],
transitions : trs
});
// const trs = [
// { name: 'SwitchToWarn', action: 'Proceed', from:'Green', to:'Yellow' },
// { name: 'SwitchToHalt', action: 'Proceed', from:'Yellow', to:'Red' },
// { name: 'SwitchToGo', action: 'Proceed', from:'Red', to:'Green' }
// ],
// light = new jssm.Machine({
// start_states : ['Red'],
// transitions : trs
// });

const light = jssm.sm`Red 'Proceed' -> Green 'Proceed' -> Yellow 'Proceed' -> Red;`;

const r_states = light.states();

test('has the right state count', () =>
expect(r_states.length).toBe(3));

trs.map(t => t.to).map(c =>
['Red', 'Yellow', 'Green'].map(c =>
test(`has state "${c}"`, () =>
expect(r_states.includes(c)).toBe(true))
);

const r_names = light.list_named_transitions();

test('has the right named transition count', () =>
expect(r_names.size).toBe(3));

trs.map(t => t.name)
.map(a =>
test(`has named transition "${a}"`, () =>
expect(r_names.has(a)).toBe(true))
);

describe('- `proceed` walkthrough', () => {

test('machine starts red', () => expect( light.state() ).toBe( "Red" ));
Expand Down Expand Up @@ -98,15 +89,15 @@ describe('Complex stop light', () => {

transitions:[

{ name:'turn_on', action:'power_on', from:'off', to:'red'},
{ name:'turn_on', kind: 'legal', forced_only: false, main_path: false, action:'power_on', from:'off', to:'red'},

{ action:'power_off', from:'red', to:'off' },
{ action:'power_off', from:'yellow', to:'off' },
{ action:'power_off', from:'green', to:'off' },
{ kind: 'legal', forced_only: false, main_path: false, action:'power_off', from:'red', to:'off' },
{ kind: 'legal', forced_only: false, main_path: false, action:'power_off', from:'yellow', to:'off' },
{ kind: 'legal', forced_only: false, main_path: false, action:'power_off', from:'green', to:'off' },

{ name:'switch_warn', action:'proceed', from:'green', to:'yellow' },
{ name:'switch_halt', action:'proceed', from:'yellow', to:'red' },
{ name:'switch_go', action:'proceed', from:'red', to:'green' }
{ name:'switch_warn', kind: 'legal', forced_only: false, main_path: false, action:'proceed', from:'green', to:'yellow' },
{ name:'switch_halt', kind: 'legal', forced_only: false, main_path: false, action:'proceed', from:'yellow', to:'red' },
{ name:'switch_go', kind: 'legal', forced_only: false, main_path: false, action:'proceed', from:'red', to:'green' }

]

Expand Down

0 comments on commit fa8385c

Please sign in to comment.