mirror of
https://github.com/mermaid-js/mermaid.git
synced 2024-08-28 21:16:07 +02:00
+ parsing specs that actually check results
This commit is contained in:
parent
d666981599
commit
ae7fd777a7
1 changed files with 84 additions and 0 deletions
|
@ -12,6 +12,72 @@ describe('state parser can parse...', () => {
|
|||
stateDiagram.parser.yy.clear();
|
||||
});
|
||||
|
||||
describe('states with id displayed as a (name)', () => {
|
||||
describe('syntax 1: stateID as "name in quotes"', () => {
|
||||
it('stateID as "some name"', () => {
|
||||
const diagramText = `stateDiagram-v2
|
||||
state "Small State 1" as namedState1`;
|
||||
stateDiagram.parser.parse(diagramText);
|
||||
stateDiagram.parser.yy.extract(stateDiagram.parser.yy.getRootDocV2());
|
||||
|
||||
const states = stateDiagram.parser.yy.getStates();
|
||||
expect(states['namedState1']).not.toBeUndefined();
|
||||
expect(states['namedState1'].descriptions.join(' ')).toEqual('Small State 1');
|
||||
});
|
||||
});
|
||||
|
||||
describe('syntax 2: stateID: "name in quotes" [colon after the id]', () => {
|
||||
it('space before and after the colon', () => {
|
||||
const diagramText = `stateDiagram-v2
|
||||
namedState1 : Small State 1`;
|
||||
stateDiagram.parser.parse(diagramText);
|
||||
stateDiagram.parser.yy.extract(stateDiagram.parser.yy.getRootDocV2());
|
||||
|
||||
const states = stateDiagram.parser.yy.getStates();
|
||||
expect(states['namedState1']).not.toBeUndefined();
|
||||
expect(states['namedState1'].descriptions.join(' ')).toEqual('Small State 1');
|
||||
});
|
||||
|
||||
it('no spaces before and after the colon', () => {
|
||||
const diagramText = `stateDiagram-v2
|
||||
namedState1:Small State 1`;
|
||||
stateDiagram.parser.parse(diagramText);
|
||||
stateDiagram.parser.yy.extract(stateDiagram.parser.yy.getRootDocV2());
|
||||
|
||||
const states = stateDiagram.parser.yy.getStates();
|
||||
expect(states['namedState1']).not.toBeUndefined();
|
||||
expect(states['namedState1'].descriptions.join(' ')).toEqual('Small State 1');
|
||||
});
|
||||
});
|
||||
});
|
||||
|
||||
describe('can handle "as" in a state name', () => {
|
||||
it('assemble, assemblies, state assemble, state assemblies', function () {
|
||||
const diagramText = `stateDiagram-v2
|
||||
assemble
|
||||
assemblies
|
||||
state assemble
|
||||
state assemblies
|
||||
`;
|
||||
stateDiagram.parser.parse(diagramText);
|
||||
stateDiagram.parser.yy.extract(stateDiagram.parser.yy.getRootDocV2());
|
||||
const states = stateDiagram.parser.yy.getStates();
|
||||
expect(states['assemble']).not.toBeUndefined();
|
||||
expect(states['assemblies']).not.toBeUndefined();
|
||||
});
|
||||
|
||||
it('state "as" as as', function () {
|
||||
const diagramText = `stateDiagram-v2
|
||||
state "as" as as
|
||||
`;
|
||||
stateDiagram.parser.parse(diagramText);
|
||||
stateDiagram.parser.yy.extract(stateDiagram.parser.yy.getRootDocV2());
|
||||
const states = stateDiagram.parser.yy.getStates();
|
||||
expect(states['as']).not.toBeUndefined();
|
||||
expect(states['as'].descriptions.join(' ')).toEqual('as');
|
||||
});
|
||||
});
|
||||
|
||||
describe('groups (clusters/containers)', () => {
|
||||
it('state "Group Name" as stateIdentifier', () => {
|
||||
const diagramText = `stateDiagram-v2
|
||||
|
@ -45,5 +111,23 @@ describe('state parser can parse...', () => {
|
|||
expect(relationships[1].id1).toEqual('namedState2');
|
||||
expect(relationships[1].id2).toEqual('bigState2');
|
||||
});
|
||||
|
||||
it('group has a state with stateID AS "state name" and state2ID: "another state name"', () => {
|
||||
const diagramText = `stateDiagram-v2
|
||||
state "Big State 1" as bigState1 {
|
||||
state "inner state 1" as inner1
|
||||
inner2: inner state 2
|
||||
inner1 --> inner2
|
||||
}`;
|
||||
stateDiagram.parser.parse(diagramText);
|
||||
stateDiagram.parser.yy.extract(stateDiagram.parser.yy.getRootDocV2());
|
||||
|
||||
const states = stateDiagram.parser.yy.getStates();
|
||||
expect(states['bigState1']).not.toBeUndefined();
|
||||
expect(states['bigState1'].doc[0].id).toEqual('inner1');
|
||||
expect(states['bigState1'].doc[0].description).toEqual('inner state 1');
|
||||
expect(states['bigState1'].doc[1].id).toEqual('inner2');
|
||||
expect(states['bigState1'].doc[1].description).toEqual('inner state 2');
|
||||
});
|
||||
});
|
||||
});
|
||||
|
|
Loading…
Reference in a new issue