Fix for issue #53

This commit is contained in:
knsv
2014-12-27 09:46:28 +01:00
parent 385e823c17
commit 26d0908b27
3 changed files with 299 additions and 171 deletions

View File

@@ -26,12 +26,13 @@
"." return 'DOT'; "." return 'DOT';
"<" return 'TAGSTART'; "<" return 'TAGSTART';
">" return 'TAGEND'; ">" return 'TAGEND';
"^" return 'UP' "^" return 'UP';
"v" return 'DOWN' "v" return 'DOWN';
\-\-[x] return 'ARROW_CROSS'; \-\-[x] return 'ARROW_CROSS';
\-\-\> return 'ARROW_POINT'; \-\-\> return 'ARROW_POINT';
\-\-[o] return 'ARROW_CIRCLE'; \-\-[o] return 'ARROW_CIRCLE';
\-\-\- return 'ARROW_OPEN'; \-\-\- return 'ARROW_OPEN';
\-\- return '--';
\- return 'MINUS'; \- return 'MINUS';
\+ return 'PLUS'; \+ return 'PLUS';
\% return 'PCT'; \% return 'PCT';
@@ -235,6 +236,12 @@ link: linkStatement arrowText
{$$ = $1;} {$$ = $1;}
| linkStatement SPACE | linkStatement SPACE
{$$ = $1;} {$$ = $1;}
| '--' SPACE text SPACE linkStatement
{$5.text = $3;$$ = $5;}
| '--' SPACE text SPACE linkStatement SPACE
{$5.text = $3;$$ = $5;}
| '--' text linkStatement SPACE
{$5.text = $3;$$ = $5;}
; ;
linkStatement: ARROW_POINT linkStatement: ARROW_POINT

File diff suppressed because one or more lines are too long

View File

@@ -249,7 +249,8 @@ describe('when parsing ',function(){
expect(edges[0].type).toBe('arrow_circle'); expect(edges[0].type).toBe('arrow_circle');
}); });
it('should handle text on edges without space',function(){ describe("it should handle text on edges",function(){
it('it should handle text without space',function(){
var res = flow.parser.parse('graph TD;A--x|textNoSpace|B;'); var res = flow.parser.parse('graph TD;A--x|textNoSpace|B;');
var vert = flow.parser.yy.getVertices(); var vert = flow.parser.yy.getVertices();
@@ -259,17 +260,7 @@ describe('when parsing ',function(){
expect(edges[0].type).toBe('arrow_cross'); expect(edges[0].type).toBe('arrow_cross');
}); });
it('should handle text on edges without space and space between vertices and link',function(){ it('should handle with space',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;'); var res = flow.parser.parse('graph TD;A--x|text including space|B;');
var vert = flow.parser.yy.getVertices(); var vert = flow.parser.yy.getVertices();
@@ -279,7 +270,7 @@ describe('when parsing ',function(){
expect(edges[0].type).toBe('arrow_cross'); expect(edges[0].type).toBe('arrow_cross');
}); });
it('should handle text on edges with space',function(){ it('it should handle text with /',function(){
var res = flow.parser.parse('graph TD;A--x|text with / should work|B;'); var res = flow.parser.parse('graph TD;A--x|text with / should work|B;');
var vert = flow.parser.yy.getVertices(); var vert = flow.parser.yy.getVertices();
@@ -289,7 +280,17 @@ describe('when parsing ',function(){
expect(edges[0].text).toBe('text with / should work'); expect(edges[0].text).toBe('text with / should work');
}); });
it('should handle text on edges with space CAPS',function(){ it('it should handle 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 space and CAPS',function(){
var res = flow.parser.parse('graph TD;A--x|text including CAPS space|B;'); var res = flow.parser.parse('graph TD;A--x|text including CAPS space|B;');
var vert = flow.parser.yy.getVertices(); var vert = flow.parser.yy.getVertices();
@@ -298,7 +299,8 @@ describe('when parsing ',function(){
expect(edges[0].type).toBe('arrow_cross'); expect(edges[0].type).toBe('arrow_cross');
}); });
it('should handle text on edges with space dir',function(){
it('should handle space and dir',function(){
var res = flow.parser.parse('graph TD;A--x|text including URL space|B;'); var res = flow.parser.parse('graph TD;A--x|text including URL space|B;');
var vert = flow.parser.yy.getVertices(); var vert = flow.parser.yy.getVertices();
@@ -310,7 +312,7 @@ describe('when parsing ',function(){
}); });
it('should handle text on edges with space dir',function(){ it('should handle space and dir (TD)',function(){
var res = flow.parser.parse('graph TD;A--x|text including R TD space|B;'); var res = flow.parser.parse('graph TD;A--x|text including R TD space|B;');
var vert = flow.parser.yy.getVertices(); var vert = flow.parser.yy.getVertices();
@@ -321,7 +323,7 @@ describe('when parsing ',function(){
expect(edges[0].text).toBe('text including R TD space'); expect(edges[0].text).toBe('text including R TD space');
}); });
it('should handle text on edges with graph keyword',function(){ it('should handle keywords',function(){
var res = flow.parser.parse('graph TD;A--x|text including graph space|B;'); var res = flow.parser.parse('graph TD;A--x|text including graph space|B;');
var vert = flow.parser.yy.getVertices(); var vert = flow.parser.yy.getVertices();
@@ -330,6 +332,110 @@ describe('when parsing ',function(){
expect(edges[0].text).toBe('text including graph space'); expect(edges[0].text).toBe('text including graph space');
}); });
});
describe("it should handle text on edges using the new notation",function(){
it('it should handle text without space',function(){
var res = flow.parser.parse('graph TD;A-- textNoSpace --xB;');
var vert = flow.parser.yy.getVertices();
var edges = flow.parser.yy.getEdges();
expect(edges[0].type).toBe('arrow_cross');
});
it('it should handle text with multiple leading space',function(){
var res = flow.parser.parse('graph TD;A-- textNoSpace --xB;');
var vert = flow.parser.yy.getVertices();
var edges = flow.parser.yy.getEdges();
expect(edges[0].type).toBe('arrow_cross');
});
it('should handle with space',function(){
var res = flow.parser.parse('graph TD;A-- text including space --xB;');
var vert = flow.parser.yy.getVertices();
var edges = flow.parser.yy.getEdges();
expect(edges[0].type).toBe('arrow_cross');
});
it('it should handle text with /',function(){
var res = flow.parser.parse('graph TD;A -- text with / should work --x B;');
var vert = flow.parser.yy.getVertices();
var edges = flow.parser.yy.getEdges();
expect(edges[0].text).toBe('text with / should work');
});
it('it should handle space and space between vertices and link',function(){
var res = flow.parser.parse('graph TD;A -- textNoSpace --x B;');
var vert = flow.parser.yy.getVertices();
var edges = flow.parser.yy.getEdges();
expect(edges[0].type).toBe('arrow_cross');
});
it('should handle space and CAPS',function(){
var res = flow.parser.parse('graph TD;A-- text including CAPS space --xB;');
var vert = flow.parser.yy.getVertices();
var edges = flow.parser.yy.getEdges();
expect(edges[0].type).toBe('arrow_cross');
});
it('should handle space and dir',function(){
var res = flow.parser.parse('graph TD;A-- text including URL space --xB;');
var vert = flow.parser.yy.getVertices();
var edges = flow.parser.yy.getEdges();
expect(edges[0].type).toBe('arrow_cross');
expect(edges[0].text).toBe('text including URL space');
});
it('should handle space and dir (TD)',function(){
var res = flow.parser.parse('graph TD;A-- text including R TD space --xB;');
var vert = flow.parser.yy.getVertices();
var edges = flow.parser.yy.getEdges();
expect(edges[0].type).toBe('arrow_cross');
expect(edges[0].text).toBe('text including R TD space');
});
it('should handle keywords',function(){
var res = flow.parser.parse('graph TD;A-- text including graph space --xB;');
var vert = flow.parser.yy.getVertices();
var edges = flow.parser.yy.getEdges();
expect(edges[0].text).toBe('text including graph space');
});
});
it('should handle multi-line text',function(){ it('should handle multi-line text',function(){
var res = flow.parser.parse('graph TD;A--o|text space|B;\n B-->|more text with space|C;'); var res = flow.parser.parse('graph TD;A--o|text space|B;\n B-->|more text with space|C;');
@@ -350,6 +456,7 @@ describe('when parsing ',function(){
expect(edges[1].text).toBe('more text with space'); expect(edges[1].text).toBe('more text with space');
}); });
it('should handle multiple edges',function(){ it('should handle multiple edges',function(){
var res = flow.parser.parse('graph TD;A---|This is the 123 s text|B;\nA---|This is the second edge|B;'); var res = flow.parser.parse('graph TD;A---|This is the 123 s text|B;\nA---|This is the second edge|B;');
var vert = flow.parser.yy.getVertices(); var vert = flow.parser.yy.getVertices();
@@ -435,8 +542,9 @@ describe('when parsing ',function(){
expect(edges[0].text).toBe(',.?!+-*'); expect(edges[0].text).toBe(',.?!+-*');
}); });
describe("it should handle text in vertices, ",function(){
it('should handle text in vertices with space',function(){ it('it should handle space',function(){
var res = flow.parser.parse('graph TD;A-->C(Chimpansen hoppar);'); var res = flow.parser.parse('graph TD;A-->C(Chimpansen hoppar);');
var vert = flow.parser.yy.getVertices(); var vert = flow.parser.yy.getVertices();
@@ -445,8 +553,7 @@ describe('when parsing ',function(){
expect(vert['C'].type).toBe('round'); expect(vert['C'].type).toBe('round');
expect(vert['C'].text).toBe('Chimpansen hoppar'); expect(vert['C'].text).toBe('Chimpansen hoppar');
}); });
it('it should handle åäö and minus',function(){
it('should handle text in vertices with åäö and minus',function(){
var res = flow.parser.parse('graph TD;A-->C{Chimpansen hoppar åäö-ÅÄÖ};'); var res = flow.parser.parse('graph TD;A-->C{Chimpansen hoppar åäö-ÅÄÖ};');
var vert = flow.parser.yy.getVertices(); var vert = flow.parser.yy.getVertices();
@@ -455,7 +562,8 @@ describe('when parsing ',function(){
expect(vert['C'].type).toBe('diamond'); expect(vert['C'].type).toBe('diamond');
expect(vert['C'].text).toBe('Chimpansen hoppar åäö-ÅÄÖ'); expect(vert['C'].text).toBe('Chimpansen hoppar åäö-ÅÄÖ');
}); });
it('should handle text in vertices with åäö, minus and space and br',function(){
it('it should handle with åäö, minus and space and br',function(){
var res = flow.parser.parse('graph TD;A-->C(Chimpansen hoppar åäö <br> - ÅÄÖ);'); var res = flow.parser.parse('graph TD;A-->C(Chimpansen hoppar åäö <br> - ÅÄÖ);');
var vert = flow.parser.yy.getVertices(); var vert = flow.parser.yy.getVertices();
@@ -464,7 +572,7 @@ describe('when parsing ',function(){
expect(vert['C'].type).toBe('round'); expect(vert['C'].type).toBe('round');
expect(vert['C'].text).toBe('Chimpansen hoppar åäö <br> - ÅÄÖ'); expect(vert['C'].text).toBe('Chimpansen hoppar åäö <br> - ÅÄÖ');
}); });
xit('should handle text in vertices with åäö, minus and space and br',function(){ xit('it should handle åäö, minus and space and br',function(){
var res = flow.parser.parse('graph TD; A[Object&#40;foo,bar&#41;]-->B(Thing);'); var res = flow.parser.parse('graph TD; A[Object&#40;foo,bar&#41;]-->B(Thing);');
var vert = flow.parser.yy.getVertices(); var vert = flow.parser.yy.getVertices();
@@ -473,21 +581,21 @@ describe('when parsing ',function(){
expect(vert['C'].type).toBe('round'); expect(vert['C'].type).toBe('round');
expect(vert['C'].text).toBe(' A[Object&#40;foo,bar&#41;]-->B(Thing);'); expect(vert['C'].text).toBe(' A[Object&#40;foo,bar&#41;]-->B(Thing);');
}); });
it('should handle text in vertices with unicode chars',function(){ it('it should handle unicode chars',function(){
var res = flow.parser.parse('graph TD;A-->C(Начало);'); var res = flow.parser.parse('graph TD;A-->C(Начало);');
var vert = flow.parser.yy.getVertices(); var vert = flow.parser.yy.getVertices();
expect(vert['C'].text).toBe('Начало'); expect(vert['C'].text).toBe('Начало');
}); });
it('should handle text in vertices with backslask',function(){ it('it should handle backslask',function(){
var res = flow.parser.parse('graph TD;A-->C(c:\\windows);'); var res = flow.parser.parse('graph TD;A-->C(c:\\windows);');
var vert = flow.parser.yy.getVertices(); var vert = flow.parser.yy.getVertices();
expect(vert['C'].text).toBe('c:\\windows'); expect(vert['C'].text).toBe('c:\\windows');
}); });
it('should handle text in vertices with CAPS',function(){ it('it should handle CAPS',function(){
var res = flow.parser.parse('graph TD;A-->C(some CAPS);'); var res = flow.parser.parse('graph TD;A-->C(some CAPS);');
var vert = flow.parser.yy.getVertices(); var vert = flow.parser.yy.getVertices();
@@ -496,7 +604,7 @@ describe('when parsing ',function(){
expect(vert['C'].type).toBe('round'); expect(vert['C'].type).toBe('round');
expect(vert['C'].text).toBe('some CAPS'); expect(vert['C'].text).toBe('some CAPS');
}); });
it('should handle text in vertices with directions',function(){ it('it should handle directions',function(){
var res = flow.parser.parse('graph TD;A-->C(some URL);'); var res = flow.parser.parse('graph TD;A-->C(some URL);');
var vert = flow.parser.yy.getVertices(); var vert = flow.parser.yy.getVertices();
@@ -505,6 +613,8 @@ describe('when parsing ',function(){
expect(vert['C'].type).toBe('round'); expect(vert['C'].type).toBe('round');
expect(vert['C'].text).toBe('some URL'); expect(vert['C'].text).toBe('some URL');
}); });
});
it('should handle a single node',function(){ it('should handle a single node',function(){
// Silly but syntactically correct // Silly but syntactically correct
var res = flow.parser.parse('graph TD;A;'); var res = flow.parser.parse('graph TD;A;');