flow.jison is modified to include a single spaces between vertices and link to improve readablity for issue #38. There should not be any space between vertex and its text and link and its text. flow.spec.js is modified to include three new tests for testing new graphs.

This commit is contained in:
Vijay Jain
2014-12-13 17:09:03 +05:30
parent 3f3e23b419
commit d4451ef8a1
3 changed files with 119 additions and 46 deletions

View File

@@ -168,18 +168,30 @@ verticeStatement:
vertex: alphaNum SQS text SQE
{$$ = $1;yy.addVertex($1,$3,'square');}
| alphaNum SQS text SQE SPACE
{$$ = $1;yy.addVertex($1,$3,'square');}
| alphaNum PS PS text PE PE
{$$ = $1;yy.addVertex($1,$4,'circle');}
| alphaNum PS PS text PE PE SPACE
{$$ = $1;yy.addVertex($1,$4,'circle');}
| alphaNum PS text PE
{$$ = $1;yy.addVertex($1,$3,'round');}
| alphaNum PS text PE SPACE
{$$ = $1;yy.addVertex($1,$3,'round');}
| alphaNum DIAMOND_START text DIAMOND_STOP
{$$ = $1;yy.addVertex($1,$3,'diamond');}
| alphaNum DIAMOND_START text DIAMOND_STOP SPACE
{$$ = $1;yy.addVertex($1,$3,'diamond');}
| alphaNum TAGEND text SQE
{$$ = $1;yy.addVertex($1,$3,'odd');}
| alphaNum TAGEND text SQE SPACE
{$$ = $1;yy.addVertex($1,$3,'odd');}
| alphaNum TAGSTART text TAGEND
{$$ = $1;yy.addVertex($1,$3,'diamond');}
| alphaNum
{$$ = $1;yy.addVertex($1);}
| alphaNum SPACE
{$$ = $1;yy.addVertex($1);}
;
alphaNum
@@ -218,9 +230,13 @@ alphaNumToken
;
link: linkStatement arrowText
{$1.text = $2;$$ = $1;}
| linkStatement arrowText SPACE
{$1.text = $2;$$ = $1;}
| linkStatement
{$$ = $1;}
| linkStatement SPACE
{$$ = $1;}
;
linkStatement: ARROW_POINT

File diff suppressed because one or more lines are too long

View File

@@ -30,6 +30,22 @@ describe('when parsing ',function(){
expect(edges[0].text).toBe('');
});
it('should handle a nodes and edges and a space between link and node',function(){
var res = flow.parser.parse('graph TD;A --> B;');
var vert = flow.parser.yy.getVertices();
var edges = flow.parser.yy.getEdges();
expect(vert['A'].id).toBe('A');
expect(vert['B'].id).toBe('B');
expect(edges.length).toBe(1);
expect(edges[0].start).toBe('A');
expect(edges[0].end).toBe('B');
expect(edges[0].type).toBe('arrow');
expect(edges[0].text).toBe('');
});
it('should handle a comments',function(){
var res = flow.parser.parse('graph TD;\n%% CComment\n A-->B;');
@@ -134,6 +150,16 @@ describe('when parsing ',function(){
expect(edges[0].type).toBe('arrow_cross');
});
it('should handle text on edges without space and space between vertices and link',function(){
var res = flow.parser.parse('graph TD;A --x|textNoSpace| B;');
var vert = flow.parser.yy.getVertices();
var edges = flow.parser.yy.getEdges();
expect(edges[0].type).toBe('arrow_cross');
});
it('should handle text on edges with space',function(){
var res = flow.parser.parse('graph TD;A--x|text including space|B;');
@@ -218,6 +244,16 @@ describe('when parsing ',function(){
expect(vert['A'].text).toBe('chimpansen hoppar');
});
it('should handle text in vertices with space with spaces between vertices and link',function(){
var res = flow.parser.parse('graph TD;A[chimpansen hoppar] --> C;');
var vert = flow.parser.yy.getVertices();
var edges = flow.parser.yy.getEdges();
expect(vert['A'].type).toBe('square');
expect(vert['A'].text).toBe('chimpansen hoppar');
});
it('should handle text in circle vertices with space',function(){
var res = flow.parser.parse('graph TD;A((chimpansen hoppar))-->C;');