mirror of
https://github.com/mermaid-js/mermaid.git
synced 2025-09-16 13:59:54 +02:00
Support EMPTYSTR in jison parser, add unit tests for git graph parser
This commit is contained in:
@@ -627,6 +627,38 @@ describe('when parsing a gitGraph', function () {
|
|||||||
expect(commits[cherryPickCommitID].branch).toBe('main');
|
expect(commits[cherryPickCommitID].branch).toBe('main');
|
||||||
});
|
});
|
||||||
|
|
||||||
|
it('should support cherry-picking commits with custom tag', function () {
|
||||||
|
const str = `gitGraph
|
||||||
|
commit id: "ZERO"
|
||||||
|
branch develop
|
||||||
|
commit id:"A"
|
||||||
|
checkout main
|
||||||
|
cherry-pick id:"A" tag:"MyTag"
|
||||||
|
`;
|
||||||
|
|
||||||
|
parser.parse(str);
|
||||||
|
const commits = parser.yy.getCommits();
|
||||||
|
const cherryPickCommitID = Object.keys(commits)[2];
|
||||||
|
expect(commits[cherryPickCommitID].tag).toBe('MyTag');
|
||||||
|
expect(commits[cherryPickCommitID].branch).toBe('main');
|
||||||
|
});
|
||||||
|
|
||||||
|
it('should support cherry-picking commits with no tag', function () {
|
||||||
|
const str = `gitGraph
|
||||||
|
commit id: "ZERO"
|
||||||
|
branch develop
|
||||||
|
commit id:"A"
|
||||||
|
checkout main
|
||||||
|
cherry-pick id:"A" tag:""
|
||||||
|
`;
|
||||||
|
|
||||||
|
parser.parse(str);
|
||||||
|
const commits = parser.yy.getCommits();
|
||||||
|
const cherryPickCommitID = Object.keys(commits)[2];
|
||||||
|
expect(commits[cherryPickCommitID].tag).toBe('');
|
||||||
|
expect(commits[cherryPickCommitID].branch).toBe('main');
|
||||||
|
});
|
||||||
|
|
||||||
it('should throw error when try to branch existing branch: main', function () {
|
it('should throw error when try to branch existing branch: main', function () {
|
||||||
const str = `gitGraph
|
const str = `gitGraph
|
||||||
commit
|
commit
|
||||||
|
@@ -57,6 +57,7 @@ checkout(?=\s|$) return 'CHECKOUT';
|
|||||||
"options"\r?\n this.begin("options"); //
|
"options"\r?\n this.begin("options"); //
|
||||||
<options>[ \r\n\t]+"end" this.popState(); // not used anymore in the renderer, fixed for backward compatibility
|
<options>[ \r\n\t]+"end" this.popState(); // not used anymore in the renderer, fixed for backward compatibility
|
||||||
<options>[\s\S]+(?=[ \r\n\t]+"end") return 'OPT'; //
|
<options>[\s\S]+(?=[ \r\n\t]+"end") return 'OPT'; //
|
||||||
|
["]["] return 'EMPTYSTR';
|
||||||
["] this.begin("string");
|
["] this.begin("string");
|
||||||
<string>["] this.popState();
|
<string>["] this.popState();
|
||||||
<string>[^"]* return 'STR';
|
<string>[^"]* return 'STR';
|
||||||
@@ -119,7 +120,9 @@ branchStatement
|
|||||||
cherryPickStatement
|
cherryPickStatement
|
||||||
: CHERRY_PICK COMMIT_ID STR {yy.cherryPick($3, '', undefined)}
|
: CHERRY_PICK COMMIT_ID STR {yy.cherryPick($3, '', undefined)}
|
||||||
| CHERRY_PICK COMMIT_ID STR COMMIT_TAG STR {yy.cherryPick($3, '', $5)}
|
| CHERRY_PICK COMMIT_ID STR COMMIT_TAG STR {yy.cherryPick($3, '', $5)}
|
||||||
|
| CHERRY_PICK COMMIT_ID STR COMMIT_TAG EMPTYSTR {yy.cherryPick($3, '', '')}
|
||||||
| CHERRY_PICK COMMIT_TAG STR COMMIT_ID STR {yy.cherryPick($5, '', $3)}
|
| CHERRY_PICK COMMIT_TAG STR COMMIT_ID STR {yy.cherryPick($5, '', $3)}
|
||||||
|
| CHERRY_PICK COMMIT_TAG EMPTYSTR COMMIT_ID STR {yy.cherryPick($3, '', '')}
|
||||||
;
|
;
|
||||||
|
|
||||||
mergeStatement
|
mergeStatement
|
||||||
|
Reference in New Issue
Block a user