@@ -14,6 +14,40 @@ describe('state parser can parse...', () => {
1414 stateDiagram . parser . yy . clear ( ) ;
1515 } ) ;
1616
17+ describe ( 'invalid name between state and curly bracket' , ( ) => {
18+ describe ( 'valid syntax' , ( ) => {
19+ it ( 'should only accept 1 word' , ( ) => {
20+ const diagramText = `stateDiagram-v2
21+ state valid { X }` ;
22+
23+ stateDiagram . parser . parse ( diagramText ) ;
24+
25+ const states = stateDiagram . parser . yy . getStates ( ) ;
26+ expect ( states . get ( 'valid' ) ) . not . toBeUndefined ( ) ;
27+ } ) ;
28+ } ) ;
29+
30+ describe ( 'invalid syntax' , ( ) => {
31+ it ( 'should throw error with 2 words' , ( ) => {
32+ const diagramText = `stateDiagram-v2
33+ state invalid syntax { Y }` ;
34+
35+ expect ( ( ) => {
36+ stateDiagram . parser . parse ( diagramText ) ;
37+ } ) . toThrow ( 'Error: State name must be a single word.' ) ;
38+ } ) ;
39+
40+ it ( 'should also throw with more than 2 words' , ( ) => {
41+ const diagramText = `stateDiagram-v2
42+ state invalid syntax with more than 2 words { Z }` ;
43+
44+ expect ( ( ) => {
45+ stateDiagram . parser . parse ( diagramText ) ;
46+ } ) . toThrow ( 'Error: State name must be a single word.' ) ;
47+ } ) ;
48+ } ) ;
49+ } ) ;
50+
1751 describe ( 'states with id displayed as a (name)' , ( ) => {
1852 describe ( 'syntax 1: stateID as "name in quotes"' , ( ) => {
1953 it ( 'stateID as "some name"' , ( ) => {
0 commit comments