From 2a38d46fd901df29e6e2a55d3759adf9dde6796c Mon Sep 17 00:00:00 2001 From: Austin Fulbright Date: Mon, 5 Aug 2024 13:53:51 -0400 Subject: [PATCH] fixed the rest of the concerns, refactored portions of the gitGraphParser test to handle async actions --- .../mermaid/src/diagrams/git/gitGraphAst.ts | 72 +-- .../src/diagrams/git/gitGraphParser.spec.js | 199 +++---- .../src/diagrams/git/gitGraphParserV2.spec.js | 550 +++++++++--------- .../src/language/gitGraph/gitGraph.langium | 2 +- 4 files changed, 377 insertions(+), 446 deletions(-) diff --git a/packages/mermaid/src/diagrams/git/gitGraphAst.ts b/packages/mermaid/src/diagrams/git/gitGraphAst.ts index 3641853df7..008e7923f5 100644 --- a/packages/mermaid/src/diagrams/git/gitGraphAst.ts +++ b/packages/mermaid/src/diagrams/git/gitGraphAst.ts @@ -44,7 +44,6 @@ function getID() { return random({ length: 7 }); } - /** * @param list - list of items * @param fn - function to get the key @@ -88,7 +87,7 @@ export const commit = function (msg: string, id: string, type: number, tags?: st msg = common.sanitizeText(msg, config); tags = tags?.map((tag) => common.sanitizeText(tag, config)); const newCommit: Commit = { - id: id ? id : state.records.seq + '-' + getId(), + id: id ? id : state.records.seq + '-' + getID(), message: msg, seq: state.records.seq++, type: type ?? commitType.NORMAL, @@ -109,12 +108,12 @@ export const branch = function (name: string, order?: number) { throw new Error( `Trying to create an existing branch. (Help: Either use a new name if you want create a new branch or try using "checkout ${name}")` ); - } - - state.records.branches.set(name, state.records.head != null ? state.records.head.id : null); - state.records.branchConfig.set(name, { name, order }); - checkout(name); - log.debug('in createBranch'); + } + + state.records.branches.set(name, state.records.head != null ? state.records.head.id : null); + state.records.branchConfig.set(name, { name, order }); + checkout(name); + log.debug('in createBranch'); }; export const merge = ( @@ -123,9 +122,10 @@ export const merge = ( overrideType?: number, customTags?: string[] ): void => { - otherBranch = common.sanitizeText(otherBranch, getConfig()); + const config = getConfig(); + otherBranch = common.sanitizeText(otherBranch, config); if (customId) { - customId = common.sanitizeText(customId, getConfig()); + customId = common.sanitizeText(customId, config); } const currentBranchCheck: string | null | undefined = state.records.branches.get( state.records.currBranch @@ -150,7 +150,8 @@ export const merge = ( expected: ['branch abc'], }; throw error; - } else if (currentCommit === undefined || !currentCommit) { + } + if (currentCommit === undefined || !currentCommit) { const error: any = new Error( `Incorrect usage of "merge". Current branch (${state.records.currBranch})has no commits` ); @@ -162,7 +163,8 @@ export const merge = ( expected: ['commit'], }; throw error; - } else if (!state.records.branches.has(otherBranch)) { + } + if (!state.records.branches.has(otherBranch)) { const error: any = new Error( 'Incorrect usage of "merge". Branch to be merged (' + otherBranch + ') does not exist' ); @@ -174,7 +176,8 @@ export const merge = ( expected: [`branch ${otherBranch}`], }; throw error; - } else if (otherCommit === undefined || !otherCommit) { + } + if (otherCommit === undefined || !otherCommit) { const error: any = new Error( 'Incorrect usage of "merge". Branch to be merged (' + otherBranch + ') has no commits' ); @@ -186,7 +189,8 @@ export const merge = ( expected: ['"commit"'], }; throw error; - } else if (currentCommit === otherCommit) { + } + if (currentCommit === otherCommit) { const error: any = new Error('Incorrect usage of "merge". Both branches have same head'); error.hash = { text: `merge ${otherBranch}`, @@ -196,7 +200,8 @@ export const merge = ( expected: ['branch abc'], }; throw error; - } else if (customId && state.records.commits.has(customId)) { + } + if (customId && state.records.commits.has(customId)) { const error: any = new Error( 'Incorrect usage of "merge". Commit with id:' + customId + @@ -218,7 +223,7 @@ export const merge = ( const verifiedBranch: string = otherBranchCheck ? otherBranchCheck : ''; //figure out a cleaner way to do this const commit: Commit = { - id: customId ? customId : state.records.seq + '-' + getId(), + id: customId ? customId : state.records.seq + '-' + getID(), message: `merged branch ${otherBranch} into ${state.records.currBranch}`, seq: state.records.seq++, parents: [state.records.head == null ? null : state.records.head.id, verifiedBranch], @@ -242,12 +247,13 @@ export const cherryPick = function ( parentCommitId: string ) { log.debug('Entering cherryPick:', sourceId, targetId, tags); - sourceId = common.sanitizeText(sourceId, getConfig()); - targetId = common.sanitizeText(targetId, getConfig()); const config = getConfig(); + sourceId = common.sanitizeText(sourceId, config); + targetId = common.sanitizeText(targetId, config); + tags = tags?.map((tag) => common.sanitizeText(tag, config)); - parentCommitId = common.sanitizeText(parentCommitId, getConfig()); + parentCommitId = common.sanitizeText(parentCommitId, config); if (!sourceId || !state.records.commits.has(sourceId)) { const error: any = new Error( @@ -293,8 +299,6 @@ export const cherryPick = function ( error.hash = { text: `cherryPick ${sourceId} ${targetId}`, token: `cherryPick ${sourceId} ${targetId}`, - line: '1', - loc: { first_line: 1, last_line: 1, first_column: 1, last_column: 1 }, expected: ['cherry-pick abc'], }; throw error; @@ -307,8 +311,6 @@ export const cherryPick = function ( error.hash = { text: `cherryPick ${sourceId} ${targetId}`, token: `cherryPick ${sourceId} ${targetId}`, - line: '1', - loc: { first_line: 1, last_line: 1, first_column: 1, last_column: 1 }, expected: ['cherry-pick abc'], }; throw error; @@ -323,13 +325,12 @@ export const cherryPick = function ( text: `cherryPick ${sourceId} ${targetId}`, token: `cherryPick ${sourceId} ${targetId}`, line: '1', - loc: { first_line: 1, last_line: 1, first_column: 1, last_column: 1 }, expected: ['cherry-pick abc'], }; throw error; } const commit = { - id: state.records.seq + '-' + getId(), + id: state.records.seq + '-' + getID(), message: `cherry-picked ${sourceCommit?.message} into ${state.records.currBranch}`, seq: state.records.seq++, parents: [state.records.head == null ? null : state.records.head.id, sourceCommit.id], @@ -365,8 +366,6 @@ export const checkout = function (branch: string) { expected: [`branch ${branch}`], }; throw error; - //branches[branch] = head != null ? head.id : null; - //log.debug('in createBranch'); } else { state.records.currBranch = branch; const id = state.records.branches.get(state.records.currBranch); @@ -378,25 +377,6 @@ export const checkout = function (branch: string) { } }; -// export const reset = function (commitRef) { -// log.debug('in reset', commitRef); -// const ref = commitRef.split(':')[0]; -// let parentCount = parseInt(commitRef.split(':')[1]); -// let commit = ref === 'HEAD' ? head : commits.get(branches.get(ref)); -// log.debug(commit, parentCount); -// while (parentCount > 0) { -// commit = commits.get(commit.parent); -// parentCount--; -// if (!commit) { -// const err = 'Critical error - unique parent commit not found during reset'; -// log.error(err); -// throw err; -// } -// } -// head = commit; -// branches[curBranch] = commit.id; -// }; - /** * @param arr - array * @param key - key diff --git a/packages/mermaid/src/diagrams/git/gitGraphParser.spec.js b/packages/mermaid/src/diagrams/git/gitGraphParser.spec.js index d498577fe0..460d039aaa 100644 --- a/packages/mermaid/src/diagrams/git/gitGraphParser.spec.js +++ b/packages/mermaid/src/diagrams/git/gitGraphParser.spec.js @@ -1,129 +1,92 @@ -import gitGraphAst from './gitGraphAst.js'; -import { parser } from './parser/gitGraph.jison'; +import db from './gitGraphAst.js'; +import { parser } from './gitGraphParser.js'; describe('when parsing a gitGraph', function () { beforeEach(function () { - parser.yy = gitGraphAst; - parser.yy.clear(); + db.clear(); }); - it('should handle a gitGraph definition', function () { - const str = 'gitGraph:\n' + 'commit\n'; - parser.parse(str); - const commits = parser.yy.getCommits(); + it('should handle a gitGraph definition', async () => { + const str = `gitGraph:\n commit\n`; - expect(commits.size).toBe(1); - expect(parser.yy.getCurrentBranch()).toBe('main'); - expect(parser.yy.getDirection()).toBe('LR'); - expect(parser.yy.getBranches().size).toBe(1); - }); - - it('should handle a gitGraph definition with empty options', function () { - const str = 'gitGraph:\n' + 'options\n' + ' end\n' + 'commit\n'; - - parser.parse(str); - const commits = parser.yy.getCommits(); - - expect(parser.yy.getOptions()).toEqual({}); - expect(commits.size).toBe(1); - expect(parser.yy.getCurrentBranch()).toBe('main'); - expect(parser.yy.getDirection()).toBe('LR'); - expect(parser.yy.getBranches().size).toBe(1); - }); - - it('should handle a gitGraph definition with valid options', function () { - const str = 'gitGraph:\n' + 'options\n' + '{"key": "value"}\n' + 'end\n' + 'commit\n'; - - parser.parse(str); - const commits = parser.yy.getCommits(); - expect(parser.yy.getOptions().key).toBe('value'); - expect(commits.size).toBe(1); - expect(parser.yy.getCurrentBranch()).toBe('main'); - expect(parser.yy.getDirection()).toBe('LR'); - expect(parser.yy.getBranches().size).toBe(1); - }); - - it('should not fail on a gitGraph with malformed json', function () { - const str = 'gitGraph:\n' + 'options\n' + '{"key": "value"\n' + 'end\n' + 'commit\n'; + await parser.parse(str); + const commits = db.getCommits(); - parser.parse(str); - const commits = parser.yy.getCommits(); expect(commits.size).toBe(1); - expect(parser.yy.getCurrentBranch()).toBe('main'); - expect(parser.yy.getDirection()).toBe('LR'); - expect(parser.yy.getBranches().size).toBe(1); + expect(db.getCurrentBranch()).toBe('main'); + expect(db.getDirection()).toBe('LR'); + expect(db.getBranches().size).toBe(1); }); - it('should handle set direction top to bottom', function () { + it('should handle set direction top to bottom', async () => { const str = 'gitGraph TB:\n' + 'commit\n'; - parser.parse(str); - const commits = parser.yy.getCommits(); + await parser.parse(str); + const commits = db.getCommits(); expect(commits.size).toBe(1); - expect(parser.yy.getCurrentBranch()).toBe('main'); - expect(parser.yy.getDirection()).toBe('TB'); - expect(parser.yy.getBranches().size).toBe(1); + expect(db.getCurrentBranch()).toBe('main'); + expect(db.getDirection()).toBe('TB'); + expect(db.getBranches().size).toBe(1); }); - it('should handle set direction bottom to top', function () { + it('should handle set direction bottom to top', async () => { const str = 'gitGraph BT:\n' + 'commit\n'; - parser.parse(str); - const commits = parser.yy.getCommits(); + await parser.parse(str); + const commits = db.getCommits(); expect(commits.size).toBe(1); - expect(parser.yy.getCurrentBranch()).toBe('main'); - expect(parser.yy.getDirection()).toBe('BT'); - expect(parser.yy.getBranches().size).toBe(1); + expect(db.getCurrentBranch()).toBe('main'); + expect(db.getDirection()).toBe('BT'); + expect(db.getBranches().size).toBe(1); }); - it('should checkout a branch', function () { + it('should checkout a branch', async () => { const str = 'gitGraph:\n' + 'branch new\n' + 'checkout new\n'; - parser.parse(str); - const commits = parser.yy.getCommits(); + await parser.parse(str); + const commits = db.getCommits(); expect(commits.size).toBe(0); - expect(parser.yy.getCurrentBranch()).toBe('new'); + expect(db.getCurrentBranch()).toBe('new'); }); - it('should switch a branch', function () { + it('should switch a branch', async () => { const str = 'gitGraph:\n' + 'branch new\n' + 'switch new\n'; - parser.parse(str); - const commits = parser.yy.getCommits(); + await parser.parse(str); + const commits = db.getCommits(); expect(commits.size).toBe(0); - expect(parser.yy.getCurrentBranch()).toBe('new'); + expect(db.getCurrentBranch()).toBe('new'); }); - it('should add commits to checked out branch', function () { + it('should add commits to checked out branch', async () => { const str = 'gitGraph:\n' + 'branch new\n' + 'checkout new\n' + 'commit\n' + 'commit\n'; - parser.parse(str); - const commits = parser.yy.getCommits(); + await parser.parse(str); + const commits = db.getCommits(); expect(commits.size).toBe(2); - expect(parser.yy.getCurrentBranch()).toBe('new'); - const branchCommit = parser.yy.getBranches().get('new'); + expect(db.getCurrentBranch()).toBe('new'); + const branchCommit = db.getBranches().get('new'); expect(branchCommit).not.toBeNull(); expect(commits.get(branchCommit).parent).not.toBeNull(); }); - it('should handle commit with args', function () { + it('should handle commit with args', async () => { const str = 'gitGraph:\n' + 'commit "a commit"\n'; - parser.parse(str); - const commits = parser.yy.getCommits(); + await parser.parse(str); + const commits = db.getCommits(); expect(commits.size).toBe(1); const key = commits.keys().next().value; expect(commits.get(key).message).toBe('a commit'); - expect(parser.yy.getCurrentBranch()).toBe('main'); + expect(db.getCurrentBranch()).toBe('main'); }); - // Reset has been commented out in JISON - it.skip('should reset a branch', function () { + it.skip('should reset a branch', async () => { const str = 'gitGraph:\n' + 'commit\n' + @@ -133,16 +96,16 @@ describe('when parsing a gitGraph', function () { 'commit\n' + 'reset main\n'; - parser.parse(str); + await parser.parse(str); - const commits = parser.yy.getCommits(); + const commits = db.getCommits(); expect(commits.size).toBe(3); - expect(parser.yy.getCurrentBranch()).toBe('newbranch'); - expect(parser.yy.getBranches().get('newbranch')).toEqual(parser.yy.getBranches().get('main')); - expect(parser.yy.getHead().id).toEqual(parser.yy.getBranches().get('newbranch')); + expect(db.getCurrentBranch()).toBe('newbranch'); + expect(db.getBranches().get('newbranch')).toEqual(db.getBranches().get('main')); + expect(db.getHead().id).toEqual(db.getBranches().get('newbranch')); }); - it.skip('reset can take an argument', function () { + it.skip('reset can take an argument', async () => { const str = 'gitGraph:\n' + 'commit\n' + @@ -152,16 +115,16 @@ describe('when parsing a gitGraph', function () { 'commit\n' + 'reset main^\n'; - parser.parse(str); + await parser.parse(str); - const commits = parser.yy.getCommits(); + const commits = db.getCommits(); expect(commits.size).toBe(3); - expect(parser.yy.getCurrentBranch()).toBe('newbranch'); - const main = commits.get(parser.yy.getBranches().get('main')); - expect(parser.yy.getHead().id).toEqual(main.parent); + expect(db.getCurrentBranch()).toBe('newbranch'); + const main = commits.get(db.getBranches().get('main')); + expect(db.getHead().id).toEqual(main.parent); }); - it.skip('should handle fast forwardable merges', function () { + it.skip('should handle fast forwardable merges', async () => { const str = 'gitGraph:\n' + 'commit\n' + @@ -172,16 +135,16 @@ describe('when parsing a gitGraph', function () { 'checkout main\n' + 'merge newbranch\n'; - parser.parse(str); + await parser.parse(str); - const commits = parser.yy.getCommits(); + const commits = db.getCommits(); expect(commits.size).toBe(4); - expect(parser.yy.getCurrentBranch()).toBe('main'); - expect(parser.yy.getBranches().get('newbranch')).toEqual(parser.yy.getBranches().get('main')); - expect(parser.yy.getHead().id).toEqual(parser.yy.getBranches().get('newbranch')); + expect(db.getCurrentBranch()).toBe('main'); + expect(db.getBranches().get('newbranch')).toEqual(db.getBranches().get('main')); + expect(db.getHead().id).toEqual(db.getBranches().get('newbranch')); }); - it('should handle cases when merge is a noop', function () { + it('should handle cases when merge is a noop', async () => { const str = 'gitGraph:\n' + 'commit\n' + @@ -191,18 +154,16 @@ describe('when parsing a gitGraph', function () { 'commit\n' + 'merge main\n'; - parser.parse(str); + await parser.parse(str); - const commits = parser.yy.getCommits(); + const commits = db.getCommits(); expect(commits.size).toBe(4); - expect(parser.yy.getCurrentBranch()).toBe('newbranch'); - expect(parser.yy.getBranches().get('newbranch')).not.toEqual( - parser.yy.getBranches().get('main') - ); - expect(parser.yy.getHead().id).toEqual(parser.yy.getBranches().get('newbranch')); + expect(db.getCurrentBranch()).toBe('newbranch'); + expect(db.getBranches().get('newbranch')).not.toEqual(db.getBranches().get('main')); + expect(db.getHead().id).toEqual(db.getBranches().get('newbranch')); }); - it('should handle merge with 2 parents', function () { + it('should handle merge with 2 parents', async () => { const str = 'gitGraph:\n' + 'commit\n' + @@ -214,18 +175,16 @@ describe('when parsing a gitGraph', function () { 'commit\n' + 'merge newbranch\n'; - parser.parse(str); + await parser.parse(str); - const commits = parser.yy.getCommits(); + const commits = db.getCommits(); expect(commits.size).toBe(5); - expect(parser.yy.getCurrentBranch()).toBe('main'); - expect(parser.yy.getBranches().get('newbranch')).not.toEqual( - parser.yy.getBranches().get('main') - ); - expect(parser.yy.getHead().id).toEqual(parser.yy.getBranches().get('main')); + expect(db.getCurrentBranch()).toBe('main'); + expect(db.getBranches().get('newbranch')).not.toEqual(db.getBranches().get('main')); + expect(db.getHead().id).toEqual(db.getBranches().get('main')); }); - it.skip('should handle ff merge when history walk has two parents (merge commit)', function () { + it.skip('should handle ff merge when history walk has two parents (merge commit)', async () => { const str = 'gitGraph:\n' + 'commit\n' + @@ -240,18 +199,18 @@ describe('when parsing a gitGraph', function () { 'checkout newbranch\n' + 'merge main\n'; - parser.parse(str); + await parser.parse(str); - const commits = parser.yy.getCommits(); + const commits = db.getCommits(); expect(commits.size).toBe(7); - expect(parser.yy.getCurrentBranch()).toBe('newbranch'); - expect(parser.yy.getBranches().get('newbranch')).toEqual(parser.yy.getBranches().get('main')); - expect(parser.yy.getHead().id).toEqual(parser.yy.getBranches().get('main')); + expect(db.getCurrentBranch()).toBe('newbranch'); + expect(db.getBranches().get('newbranch')).toEqual(db.getBranches().get('main')); + expect(db.getHead().id).toEqual(db.getBranches().get('main')); - parser.yy.prettyPrint(); + db.prettyPrint(); }); - it('should generate an array of known branches', function () { + it('should generate an array of known branches', async () => { const str = 'gitGraph:\n' + 'commit\n' + @@ -261,8 +220,8 @@ describe('when parsing a gitGraph', function () { 'commit\n' + 'branch b2\n'; - parser.parse(str); - const branches = gitGraphAst.getBranchesAsObjArray(); + await parser.parse(str); + const branches = db.getBranchesAsObjArray(); expect(branches).toHaveLength(3); expect(branches[0]).toHaveProperty('name', 'main'); diff --git a/packages/mermaid/src/diagrams/git/gitGraphParserV2.spec.js b/packages/mermaid/src/diagrams/git/gitGraphParserV2.spec.js index 1fb64a5c43..e1e95551be 100644 --- a/packages/mermaid/src/diagrams/git/gitGraphParserV2.spec.js +++ b/packages/mermaid/src/diagrams/git/gitGraphParserV2.spec.js @@ -1,22 +1,21 @@ -import gitGraphAst from './gitGraphAst.js'; -import { parser } from './parser/gitGraph.jison'; +import db from './gitGraphAst.js'; +import { parser } from './gitGraphParser.js'; describe('when parsing a gitGraph', function () { beforeEach(function () { - parser.yy = gitGraphAst; - parser.yy.clear(); + db.clear(); }); - it('should handle a gitGraph commit with NO pararms, get auto-generated reandom ID', function () { + it('should handle a gitGraph commit with NO params, get auto-generated read-only ID', async () => { const str = `gitGraph: commit `; - parser.parse(str); - const commits = parser.yy.getCommits(); + await parser.parse(str); + const commits = db.getCommits(); //console.info(commits); expect(commits.size).toBe(1); - expect(parser.yy.getCurrentBranch()).toBe('main'); - expect(parser.yy.getDirection()).toBe('LR'); - expect(parser.yy.getBranches().size).toBe(1); + expect(db.getCurrentBranch()).toBe('main'); + expect(db.getDirection()).toBe('LR'); + expect(db.getBranches().size).toBe(1); const key = commits.keys().next().value; expect(commits.get(key).message).toBe(''); expect(commits.get(key).id).not.toBeNull(); @@ -24,16 +23,16 @@ describe('when parsing a gitGraph', function () { expect(commits.get(key).type).toBe(0); }); - it('should handle a gitGraph commit with custom commit id only', function () { + it('should handle a gitGraph commit with custom commit id only', async () => { const str = `gitGraph: commit id:"1111" `; - parser.parse(str); - const commits = parser.yy.getCommits(); + await parser.parse(str); + const commits = db.getCommits(); expect(commits.size).toBe(1); - expect(parser.yy.getCurrentBranch()).toBe('main'); - expect(parser.yy.getDirection()).toBe('LR'); - expect(parser.yy.getBranches().size).toBe(1); + expect(db.getCurrentBranch()).toBe('main'); + expect(db.getDirection()).toBe('LR'); + expect(db.getBranches().size).toBe(1); const key = commits.keys().next().value; expect(commits.get(key).message).toBe(''); expect(commits.get(key).id).toBe('1111'); @@ -41,17 +40,17 @@ describe('when parsing a gitGraph', function () { expect(commits.get(key).type).toBe(0); }); - it('should handle a gitGraph commit with custom commit tag only', function () { + it('should handle a gitGraph commit with custom commit tag only', async () => { const str = `gitGraph: commit tag:"test" `; - parser.parse(str); - const commits = parser.yy.getCommits(); + await parser.parse(str); + const commits = db.getCommits(); expect(commits.size).toBe(1); - expect(parser.yy.getCurrentBranch()).toBe('main'); - expect(parser.yy.getDirection()).toBe('LR'); - expect(parser.yy.getBranches().size).toBe(1); + expect(db.getCurrentBranch()).toBe('main'); + expect(db.getDirection()).toBe('LR'); + expect(db.getBranches().size).toBe(1); const key = commits.keys().next().value; expect(commits.get(key).message).toBe(''); expect(commits.get(key).id).not.toBeNull(); @@ -59,17 +58,17 @@ describe('when parsing a gitGraph', function () { expect(commits.get(key).type).toBe(0); }); - it('should handle a gitGraph commit with custom commit type HIGHLIGHT only', function () { + it('should handle a gitGraph commit with custom commit type HIGHLIGHT only', async () => { const str = `gitGraph: commit type: HIGHLIGHT `; - parser.parse(str); - const commits = parser.yy.getCommits(); + await parser.parse(str); + const commits = db.getCommits(); expect(commits.size).toBe(1); - expect(parser.yy.getCurrentBranch()).toBe('main'); - expect(parser.yy.getDirection()).toBe('LR'); - expect(parser.yy.getBranches().size).toBe(1); + expect(db.getCurrentBranch()).toBe('main'); + expect(db.getDirection()).toBe('LR'); + expect(db.getBranches().size).toBe(1); const key = commits.keys().next().value; expect(commits.get(key).message).toBe(''); expect(commits.get(key).id).not.toBeNull(); @@ -77,17 +76,17 @@ describe('when parsing a gitGraph', function () { expect(commits.get(key).type).toBe(2); }); - it('should handle a gitGraph commit with custom commit type REVERSE only', function () { + it('should handle a gitGraph commit with custom commit type REVERSE only', async () => { const str = `gitGraph: commit type: REVERSE `; - parser.parse(str); - const commits = parser.yy.getCommits(); + await parser.parse(str); + const commits = db.getCommits(); expect(commits.size).toBe(1); - expect(parser.yy.getCurrentBranch()).toBe('main'); - expect(parser.yy.getDirection()).toBe('LR'); - expect(parser.yy.getBranches().size).toBe(1); + expect(db.getCurrentBranch()).toBe('main'); + expect(db.getDirection()).toBe('LR'); + expect(db.getBranches().size).toBe(1); const key = commits.keys().next().value; expect(commits.get(key).message).toBe(''); expect(commits.get(key).id).not.toBeNull(); @@ -95,17 +94,17 @@ describe('when parsing a gitGraph', function () { expect(commits.get(key).type).toBe(1); }); - it('should handle a gitGraph commit with custom commit type NORMAL only', function () { + it('should handle a gitGraph commit with custom commit type NORMAL only', async () => { const str = `gitGraph: commit type: NORMAL `; - parser.parse(str); - const commits = parser.yy.getCommits(); + await parser.parse(str); + const commits = db.getCommits(); expect(commits.size).toBe(1); - expect(parser.yy.getCurrentBranch()).toBe('main'); - expect(parser.yy.getDirection()).toBe('LR'); - expect(parser.yy.getBranches().size).toBe(1); + expect(db.getCurrentBranch()).toBe('main'); + expect(db.getDirection()).toBe('LR'); + expect(db.getBranches().size).toBe(1); const key = commits.keys().next().value; expect(commits.get(key).message).toBe(''); expect(commits.get(key).id).not.toBeNull(); @@ -113,17 +112,17 @@ describe('when parsing a gitGraph', function () { expect(commits.get(key).type).toBe(0); }); - it('should handle a gitGraph commit with custom commit msg only', function () { + it('should handle a gitGraph commit with custom commit msg only', async () => { const str = `gitGraph: commit "test commit" `; - parser.parse(str); - const commits = parser.yy.getCommits(); + await parser.parse(str); + const commits = db.getCommits(); expect(commits.size).toBe(1); - expect(parser.yy.getCurrentBranch()).toBe('main'); - expect(parser.yy.getDirection()).toBe('LR'); - expect(parser.yy.getBranches().size).toBe(1); + expect(db.getCurrentBranch()).toBe('main'); + expect(db.getDirection()).toBe('LR'); + expect(db.getBranches().size).toBe(1); const key = commits.keys().next().value; expect(commits.get(key).message).toBe('test commit'); expect(commits.get(key).id).not.toBeNull(); @@ -131,17 +130,17 @@ describe('when parsing a gitGraph', function () { expect(commits.get(key).type).toBe(0); }); - it('should handle a gitGraph commit with custom commit "msg:" key only', function () { + it('should handle a gitGraph commit with custom commit "msg:" key only', async () => { const str = `gitGraph: commit msg: "test commit" `; - parser.parse(str); - const commits = parser.yy.getCommits(); + await parser.parse(str); + const commits = db.getCommits(); expect(commits.size).toBe(1); - expect(parser.yy.getCurrentBranch()).toBe('main'); - expect(parser.yy.getDirection()).toBe('LR'); - expect(parser.yy.getBranches().size).toBe(1); + expect(db.getCurrentBranch()).toBe('main'); + expect(db.getDirection()).toBe('LR'); + expect(db.getBranches().size).toBe(1); const key = commits.keys().next().value; expect(commits.get(key).message).toBe('test commit'); expect(commits.get(key).id).not.toBeNull(); @@ -149,17 +148,17 @@ describe('when parsing a gitGraph', function () { expect(commits.get(key).type).toBe(0); }); - it('should handle a gitGraph commit with custom commit id, tag only', function () { + it('should handle a gitGraph commit with custom commit id, tag only', async () => { const str = `gitGraph: commit id:"1111" tag: "test tag" `; - parser.parse(str); - const commits = parser.yy.getCommits(); + await parser.parse(str); + const commits = db.getCommits(); expect(commits.size).toBe(1); - expect(parser.yy.getCurrentBranch()).toBe('main'); - expect(parser.yy.getDirection()).toBe('LR'); - expect(parser.yy.getBranches().size).toBe(1); + expect(db.getCurrentBranch()).toBe('main'); + expect(db.getDirection()).toBe('LR'); + expect(db.getBranches().size).toBe(1); const key = commits.keys().next().value; expect(commits.get(key).message).toBe(''); expect(commits.get(key).id).toBe('1111'); @@ -167,17 +166,17 @@ describe('when parsing a gitGraph', function () { expect(commits.get(key).type).toBe(0); }); - it('should handle a gitGraph commit with custom commit type, tag only', function () { + it('should handle a gitGraph commit with custom commit type, tag only', async () => { const str = `gitGraph: commit type:HIGHLIGHT tag: "test tag" `; - parser.parse(str); - const commits = parser.yy.getCommits(); + await parser.parse(str); + const commits = db.getCommits(); expect(commits.size).toBe(1); - expect(parser.yy.getCurrentBranch()).toBe('main'); - expect(parser.yy.getDirection()).toBe('LR'); - expect(parser.yy.getBranches().size).toBe(1); + expect(db.getCurrentBranch()).toBe('main'); + expect(db.getDirection()).toBe('LR'); + expect(db.getBranches().size).toBe(1); const key = commits.keys().next().value; expect(commits.get(key).message).toBe(''); expect(commits.get(key).id).not.toBeNull(); @@ -185,17 +184,17 @@ describe('when parsing a gitGraph', function () { expect(commits.get(key).type).toBe(2); }); - it('should handle a gitGraph commit with custom commit tag and type only', function () { + it('should handle a gitGraph commit with custom commit tag and type only', async () => { const str = `gitGraph: commit tag: "test tag" type:HIGHLIGHT `; - parser.parse(str); - const commits = parser.yy.getCommits(); + await parser.parse(str); + const commits = db.getCommits(); expect(commits.size).toBe(1); - expect(parser.yy.getCurrentBranch()).toBe('main'); - expect(parser.yy.getDirection()).toBe('LR'); - expect(parser.yy.getBranches().size).toBe(1); + expect(db.getCurrentBranch()).toBe('main'); + expect(db.getDirection()).toBe('LR'); + expect(db.getBranches().size).toBe(1); const key = commits.keys().next().value; expect(commits.get(key).message).toBe(''); expect(commits.get(key).id).not.toBeNull(); @@ -203,17 +202,17 @@ describe('when parsing a gitGraph', function () { expect(commits.get(key).type).toBe(2); }); - it('should handle a gitGraph commit with custom commit id, type and tag only', function () { + it('should handle a gitGraph commit with custom commit id, type and tag only', async () => { const str = `gitGraph: commit id:"1111" type:REVERSE tag: "test tag" `; - parser.parse(str); - const commits = parser.yy.getCommits(); + await parser.parse(str); + const commits = db.getCommits(); expect(commits.size).toBe(1); - expect(parser.yy.getCurrentBranch()).toBe('main'); - expect(parser.yy.getDirection()).toBe('LR'); - expect(parser.yy.getBranches().size).toBe(1); + expect(db.getCurrentBranch()).toBe('main'); + expect(db.getDirection()).toBe('LR'); + expect(db.getBranches().size).toBe(1); const key = commits.keys().next().value; expect(commits.get(key).message).toBe(''); expect(commits.get(key).id).toBe('1111'); @@ -221,17 +220,17 @@ describe('when parsing a gitGraph', function () { expect(commits.get(key).type).toBe(1); }); - it('should handle a gitGraph commit with custom commit id, type, tag and msg', function () { + it('should handle a gitGraph commit with custom commit id, type, tag and msg', async () => { const str = `gitGraph: commit id:"1111" type:REVERSE tag: "test tag" msg:"test msg" `; - parser.parse(str); - const commits = parser.yy.getCommits(); + await parser.parse(str); + const commits = db.getCommits(); expect(commits.size).toBe(1); - expect(parser.yy.getCurrentBranch()).toBe('main'); - expect(parser.yy.getDirection()).toBe('LR'); - expect(parser.yy.getBranches().size).toBe(1); + expect(db.getCurrentBranch()).toBe('main'); + expect(db.getDirection()).toBe('LR'); + expect(db.getBranches().size).toBe(1); const key = commits.keys().next().value; expect(commits.get(key).message).toBe('test msg'); expect(commits.get(key).id).toBe('1111'); @@ -239,18 +238,18 @@ describe('when parsing a gitGraph', function () { expect(commits.get(key).type).toBe(1); }); - it('should handle a gitGraph commit with custom type,tag, msg, commit id,', function () { + it('should handle a gitGraph commit with custom type,tag, msg, commit id,', async () => { const str = `gitGraph: commit type:REVERSE tag: "test tag" msg: "test msg" id: "1111" `; - parser.parse(str); - const commits = parser.yy.getCommits(); + await parser.parse(str); + const commits = db.getCommits(); expect(commits.size).toBe(1); - expect(parser.yy.getCurrentBranch()).toBe('main'); - expect(parser.yy.getDirection()).toBe('LR'); - expect(parser.yy.getBranches().size).toBe(1); + expect(db.getCurrentBranch()).toBe('main'); + expect(db.getDirection()).toBe('LR'); + expect(db.getBranches().size).toBe(1); const key = commits.keys().next().value; expect(commits.get(key).message).toBe('test msg'); expect(commits.get(key).id).toBe('1111'); @@ -258,17 +257,17 @@ describe('when parsing a gitGraph', function () { expect(commits.get(key).type).toBe(1); }); - it('should handle a gitGraph commit with custom tag, msg, commit id, type,', function () { + it('should handle a gitGraph commit with custom tag, msg, commit id, type,', async () => { const str = `gitGraph: commit tag: "test tag" msg:"test msg" id:"1111" type:REVERSE `; - parser.parse(str); - const commits = parser.yy.getCommits(); + await parser.parse(str); + const commits = db.getCommits(); expect(commits.size).toBe(1); - expect(parser.yy.getCurrentBranch()).toBe('main'); - expect(parser.yy.getDirection()).toBe('LR'); - expect(parser.yy.getBranches().size).toBe(1); + expect(db.getCurrentBranch()).toBe('main'); + expect(db.getDirection()).toBe('LR'); + expect(db.getBranches().size).toBe(1); const key = commits.keys().next().value; expect(commits.get(key).message).toBe('test msg'); expect(commits.get(key).id).toBe('1111'); @@ -276,17 +275,17 @@ describe('when parsing a gitGraph', function () { expect(commits.get(key).type).toBe(1); }); - it('should handle a gitGraph commit with custom msg, commit id, type,tag', function () { + it('should handle a gitGraph commit with custom msg, commit id, type,tag', async () => { const str = `gitGraph: commit msg:"test msg" id:"1111" type:REVERSE tag: "test tag" `; - parser.parse(str); - const commits = parser.yy.getCommits(); + await parser.parse(str); + const commits = db.getCommits(); expect(commits.size).toBe(1); - expect(parser.yy.getCurrentBranch()).toBe('main'); - expect(parser.yy.getDirection()).toBe('LR'); - expect(parser.yy.getBranches().size).toBe(1); + expect(db.getCurrentBranch()).toBe('main'); + expect(db.getDirection()).toBe('LR'); + expect(db.getBranches().size).toBe(1); const key = commits.keys().next().value; expect(commits.get(key).message).toBe('test msg'); expect(commits.get(key).id).toBe('1111'); @@ -294,36 +293,36 @@ describe('when parsing a gitGraph', function () { expect(commits.get(key).type).toBe(1); }); - it('should handle 3 straight commits', function () { + it('should handle 3 straight commits', async () => { const str = `gitGraph: commit commit commit `; - parser.parse(str); - const commits = parser.yy.getCommits(); + await parser.parse(str); + const commits = db.getCommits(); expect(commits.size).toBe(3); - expect(parser.yy.getCurrentBranch()).toBe('main'); - expect(parser.yy.getDirection()).toBe('LR'); - expect(parser.yy.getBranches().size).toBe(1); + expect(db.getCurrentBranch()).toBe('main'); + expect(db.getDirection()).toBe('LR'); + expect(db.getBranches().size).toBe(1); }); - it('should handle new branch creation', function () { + it('should handle new branch creation', async () => { const str = `gitGraph: commit branch testBranch `; - parser.parse(str); - const commits = parser.yy.getCommits(); + await parser.parse(str); + const commits = db.getCommits(); expect(commits.size).toBe(1); - expect(parser.yy.getCurrentBranch()).toBe('testBranch'); - expect(parser.yy.getDirection()).toBe('LR'); - expect(parser.yy.getBranches().size).toBe(2); + expect(db.getCurrentBranch()).toBe('testBranch'); + expect(db.getDirection()).toBe('LR'); + expect(db.getBranches().size).toBe(2); }); - it('should allow quoted branch names', function () { + it('should allow quoted branch names', async () => { const str = `gitGraph: commit branch "branch" @@ -333,49 +332,49 @@ describe('when parsing a gitGraph', function () { merge "branch" `; - parser.parse(str); - const commits = parser.yy.getCommits(); + await parser.parse(str); + const commits = db.getCommits(); expect(commits.size).toBe(3); - expect(parser.yy.getCurrentBranch()).toBe('main'); - expect(parser.yy.getDirection()).toBe('LR'); - expect(parser.yy.getBranches().size).toBe(2); + expect(db.getCurrentBranch()).toBe('main'); + expect(db.getDirection()).toBe('LR'); + expect(db.getBranches().size).toBe(2); const [commit1, commit2, commit3] = commits.keys(); expect(commits.get(commit1).branch).toBe('main'); expect(commits.get(commit2).branch).toBe('branch'); expect(commits.get(commit3).branch).toBe('main'); - expect(parser.yy.getBranchesAsObjArray()).toStrictEqual([{ name: 'main' }, { name: 'branch' }]); + expect(db.getBranchesAsObjArray()).toStrictEqual([{ name: 'main' }, { name: 'branch' }]); }); - it('should allow _-./ characters in branch names', function () { + it('should allow _-./ characters in branch names', async () => { const str = `gitGraph: commit branch azAZ_-./test `; - parser.parse(str); - const commits = parser.yy.getCommits(); + await parser.parse(str); + const commits = db.getCommits(); expect(commits.size).toBe(1); - expect(parser.yy.getCurrentBranch()).toBe('azAZ_-./test'); - expect(parser.yy.getDirection()).toBe('LR'); - expect(parser.yy.getBranches().size).toBe(2); + expect(db.getCurrentBranch()).toBe('azAZ_-./test'); + expect(db.getDirection()).toBe('LR'); + expect(db.getBranches().size).toBe(2); }); - it('should allow branch names starting with numbers', function () { + it('should allow branch names starting with numbers', async () => { const str = `gitGraph: commit %% branch names starting with numbers are not recommended, but are supported by git branch 1.0.1 `; - parser.parse(str); - const commits = parser.yy.getCommits(); + await parser.parse(str); + const commits = db.getCommits(); expect(commits.size).toBe(1); - expect(parser.yy.getCurrentBranch()).toBe('1.0.1'); - expect(parser.yy.getDirection()).toBe('LR'); - expect(parser.yy.getBranches().size).toBe(2); + expect(db.getCurrentBranch()).toBe('1.0.1'); + expect(db.getDirection()).toBe('LR'); + expect(db.getBranches().size).toBe(2); }); - it('should allow branch names starting with unusual prefixes', function () { + it('should allow branch names starting with unusual prefixes', async () => { const str = `gitGraph: commit %% branch names starting with numbers are not recommended, but are supported by git @@ -388,13 +387,13 @@ describe('when parsing a gitGraph', function () { branch A `; - parser.parse(str); - const commits = parser.yy.getCommits(); + await parser.parse(str); + const commits = db.getCommits(); expect(commits.size).toBe(1); - expect(parser.yy.getCurrentBranch()).toBe('A'); - expect(parser.yy.getDirection()).toBe('LR'); - expect(parser.yy.getBranches().size).toBe(7); - expect([...parser.yy.getBranches().keys()]).toEqual( + expect(db.getCurrentBranch()).toBe('A'); + expect(db.getDirection()).toBe('LR'); + expect(db.getBranches().size).toBe(7); + expect([...db.getBranches().keys()]).toEqual( expect.arrayContaining([ 'branch01', 'checkout02', @@ -406,21 +405,21 @@ describe('when parsing a gitGraph', function () { ); }); - it('should handle new branch checkout', function () { + it('should handle new branch checkout', async () => { const str = `gitGraph: commit branch testBranch checkout testBranch `; - parser.parse(str); - const commits = parser.yy.getCommits(); + await parser.parse(str); + const commits = db.getCommits(); expect(commits.size).toBe(1); - expect(parser.yy.getCurrentBranch()).toBe('testBranch'); - expect(parser.yy.getDirection()).toBe('LR'); - expect(parser.yy.getBranches().size).toBe(2); + expect(db.getCurrentBranch()).toBe('testBranch'); + expect(db.getDirection()).toBe('LR'); + expect(db.getBranches().size).toBe(2); }); - it('should handle new branch checkout with order', function () { + it('should handle new branch checkout with order', async () => { const str = `gitGraph: commit branch test1 order: 3 @@ -428,19 +427,19 @@ describe('when parsing a gitGraph', function () { branch test3 order: 1 `; - parser.parse(str); - const commits = parser.yy.getCommits(); + await parser.parse(str); + const commits = db.getCommits(); expect(commits.size).toBe(1); - expect(parser.yy.getCurrentBranch()).toBe('test3'); - expect(parser.yy.getBranches().size).toBe(4); - expect(parser.yy.getBranchesAsObjArray()).toStrictEqual([ + expect(db.getCurrentBranch()).toBe('test3'); + expect(db.getBranches().size).toBe(4); + expect(db.getBranchesAsObjArray()).toStrictEqual([ { name: 'main' }, { name: 'test3' }, { name: 'test2' }, { name: 'test1' }, ]); }); - it('should handle new branch checkout with and without order', function () { + it('should handle new branch checkout with and without order', async () => { const str = `gitGraph: commit branch test1 order: 1 @@ -448,12 +447,12 @@ describe('when parsing a gitGraph', function () { branch test3 `; - parser.parse(str); - const commits = parser.yy.getCommits(); + await parser.parse(str); + const commits = db.getCommits(); expect(commits.size).toBe(1); - expect(parser.yy.getCurrentBranch()).toBe('test3'); - expect(parser.yy.getBranches().size).toBe(4); - expect(parser.yy.getBranchesAsObjArray()).toStrictEqual([ + expect(db.getCurrentBranch()).toBe('test3'); + expect(db.getBranches().size).toBe(4); + expect(db.getBranchesAsObjArray()).toStrictEqual([ { name: 'main' }, { name: 'test2' }, { name: 'test3' }, @@ -461,7 +460,7 @@ describe('when parsing a gitGraph', function () { ]); }); - it('should handle new branch checkout & commit', function () { + it('should handle new branch checkout & commit', async () => { const str = `gitGraph: commit branch testBranch @@ -469,12 +468,12 @@ describe('when parsing a gitGraph', function () { commit `; - parser.parse(str); - const commits = parser.yy.getCommits(); + await parser.parse(str); + const commits = db.getCommits(); expect(commits.size).toBe(2); - expect(parser.yy.getCurrentBranch()).toBe('testBranch'); - expect(parser.yy.getDirection()).toBe('LR'); - expect(parser.yy.getBranches().size).toBe(2); + expect(db.getCurrentBranch()).toBe('testBranch'); + expect(db.getDirection()).toBe('LR'); + expect(db.getBranches().size).toBe(2); const [commit1, commit2] = commits.keys(); expect(commits.get(commit1).branch).toBe('main'); expect(commits.get(commit1).parents).toStrictEqual([]); @@ -482,7 +481,7 @@ describe('when parsing a gitGraph', function () { expect(commits.get(commit2).parents).toStrictEqual([commit1]); }); - it('should handle new branch checkout & commit and merge', function () { + it('should handle new branch checkout & commit and merge', async () => { const str = `gitGraph: commit branch testBranch @@ -493,12 +492,12 @@ describe('when parsing a gitGraph', function () { merge testBranch `; - parser.parse(str); - const commits = parser.yy.getCommits(); + await parser.parse(str); + const commits = db.getCommits(); expect(commits.size).toBe(4); - expect(parser.yy.getCurrentBranch()).toBe('main'); - expect(parser.yy.getDirection()).toBe('LR'); - expect(parser.yy.getBranches().size).toBe(2); + expect(db.getCurrentBranch()).toBe('main'); + expect(db.getDirection()).toBe('LR'); + expect(db.getBranches().size).toBe(2); const [commit1, commit2, commit3, commit4] = commits.keys(); expect(commits.get(commit1).branch).toBe('main'); expect(commits.get(commit1).parents).toStrictEqual([]); @@ -511,28 +510,25 @@ describe('when parsing a gitGraph', function () { commits.get(commit1).id, commits.get(commit3).id, ]); - expect(parser.yy.getBranchesAsObjArray()).toStrictEqual([ - { name: 'main' }, - { name: 'testBranch' }, - ]); + expect(db.getBranchesAsObjArray()).toStrictEqual([{ name: 'main' }, { name: 'testBranch' }]); }); - it('should handle new branch switch', function () { + it('should handle new branch switch', async () => { const str = `gitGraph: commit branch testBranch switch testBranch `; - parser.parse(str); - const commits = parser.yy.getCommits(); + await parser.parse(str); + const commits = db.getCommits(); expect(commits.size).toBe(1); - expect(parser.yy.getCurrentBranch()).toBe('testBranch'); - expect(parser.yy.getDirection()).toBe('LR'); - expect(parser.yy.getBranches().size).toBe(2); + expect(db.getCurrentBranch()).toBe('testBranch'); + expect(db.getDirection()).toBe('LR'); + expect(db.getBranches().size).toBe(2); }); - it('should handle new branch switch & commit', function () { + it('should handle new branch switch & commit', async () => { const str = `gitGraph: commit branch testBranch @@ -540,12 +536,12 @@ describe('when parsing a gitGraph', function () { commit `; - parser.parse(str); - const commits = parser.yy.getCommits(); + await parser.parse(str); + const commits = db.getCommits(); expect(commits.size).toBe(2); - expect(parser.yy.getCurrentBranch()).toBe('testBranch'); - expect(parser.yy.getDirection()).toBe('LR'); - expect(parser.yy.getBranches().size).toBe(2); + expect(db.getCurrentBranch()).toBe('testBranch'); + expect(db.getDirection()).toBe('LR'); + expect(db.getBranches().size).toBe(2); const [commit1, commit2] = commits.keys(); expect(commits.get(commit1).branch).toBe('main'); expect(commits.get(commit1).parents).toStrictEqual([]); @@ -553,7 +549,7 @@ describe('when parsing a gitGraph', function () { expect(commits.get(commit2).parents).toStrictEqual([commit1]); }); - it('should handle new branch switch & commit and merge', function () { + it('should handle new branch switch & commit and merge', async () => { const str = `gitGraph: commit branch testBranch @@ -564,12 +560,12 @@ describe('when parsing a gitGraph', function () { merge testBranch `; - parser.parse(str); - const commits = parser.yy.getCommits(); + await parser.parse(str); + const commits = db.getCommits(); expect(commits.size).toBe(4); - expect(parser.yy.getCurrentBranch()).toBe('main'); - expect(parser.yy.getDirection()).toBe('LR'); - expect(parser.yy.getBranches().size).toBe(2); + expect(db.getCurrentBranch()).toBe('main'); + expect(db.getDirection()).toBe('LR'); + expect(db.getBranches().size).toBe(2); const [commit1, commit2, commit3, commit4] = commits.keys(); expect(commits.get(commit1).branch).toBe('main'); expect(commits.get(commit1).parents).toStrictEqual([]); @@ -582,13 +578,10 @@ describe('when parsing a gitGraph', function () { commits.get(commit1).id, commits.get(commit3).id, ]); - expect(parser.yy.getBranchesAsObjArray()).toStrictEqual([ - { name: 'main' }, - { name: 'testBranch' }, - ]); + expect(db.getBranchesAsObjArray()).toStrictEqual([{ name: 'main' }, { name: 'testBranch' }]); }); - it('should handle merge tags', function () { + it('should handle merge tags', async () => { const str = `gitGraph: commit branch testBranch @@ -598,12 +591,12 @@ describe('when parsing a gitGraph', function () { merge testBranch tag: "merge-tag" `; - parser.parse(str); - const commits = parser.yy.getCommits(); + await parser.parse(str); + const commits = db.getCommits(); expect(commits.size).toBe(3); - expect(parser.yy.getCurrentBranch()).toBe('main'); - expect(parser.yy.getDirection()).toBe('LR'); - expect(parser.yy.getBranches().size).toBe(2); + expect(db.getCurrentBranch()).toBe('main'); + expect(db.getDirection()).toBe('LR'); + expect(db.getBranches().size).toBe(2); const [commit1, commit2, commit3] = commits.keys(); expect(commits.get(commit1).branch).toBe('main'); expect(commits.get(commit1).parents).toStrictEqual([]); @@ -617,13 +610,10 @@ describe('when parsing a gitGraph', function () { commits.get(commit2).id, ]); expect(commits.get(commit3).tags).toStrictEqual(['merge-tag']); - expect(parser.yy.getBranchesAsObjArray()).toStrictEqual([ - { name: 'main' }, - { name: 'testBranch' }, - ]); + expect(db.getBranchesAsObjArray()).toStrictEqual([{ name: 'main' }, { name: 'testBranch' }]); }); - it('should handle merge with custom ids, tags and typr', function () { + it('should handle merge with custom ids, tags and type', async () => { const str = `gitGraph: commit branch testBranch @@ -646,11 +636,11 @@ describe('when parsing a gitGraph', function () { merge testBranch3 id: "6-666" `; - parser.parse(str); - const commits = parser.yy.getCommits(); + await parser.parse(str); + const commits = db.getCommits(); expect(commits.size).toBe(7); - expect(parser.yy.getCurrentBranch()).toBe('main'); - expect(parser.yy.getDirection()).toBe('LR'); + expect(db.getCurrentBranch()).toBe('main'); + expect(db.getDirection()).toBe('LR'); // The order of these commits is in alphabetical order of IDs const [ @@ -685,7 +675,7 @@ describe('when parsing a gitGraph', function () { expect(testBranch3Merge.parents).toStrictEqual([testBranch2Merge.id, testBranch3Commit.id]); expect(testBranch3Merge.id).toBe('6-666'); - expect(parser.yy.getBranchesAsObjArray()).toStrictEqual([ + expect(db.getBranchesAsObjArray()).toStrictEqual([ { name: 'main' }, { name: 'testBranch' }, { name: 'testBranch2' }, @@ -693,7 +683,7 @@ describe('when parsing a gitGraph', function () { ]); }); - it('should support cherry-picking commits', function () { + it('should support cherry-picking commits', async () => { const str = `gitGraph commit id: "ZERO" branch develop @@ -702,14 +692,14 @@ describe('when parsing a gitGraph', function () { cherry-pick id:"A" `; - parser.parse(str); - const commits = parser.yy.getCommits(); + await parser.parse(str); + const commits = db.getCommits(); const cherryPickCommitID = [...commits.keys()][2]; expect(commits.get(cherryPickCommitID).tags).toStrictEqual(['cherry-pick:A']); expect(commits.get(cherryPickCommitID).branch).toBe('main'); }); - it('should support cherry-picking commits with custom tag', function () { + it('should support cherry-picking commits with custom tag', async () => { const str = `gitGraph commit id: "ZERO" branch develop @@ -718,14 +708,14 @@ describe('when parsing a gitGraph', function () { cherry-pick id:"A" tag:"MyTag" `; - parser.parse(str); - const commits = parser.yy.getCommits(); + await parser.parse(str); + const commits = db.getCommits(); const cherryPickCommitID = [...commits.keys()][2]; expect(commits.get(cherryPickCommitID).tags).toStrictEqual(['MyTag']); expect(commits.get(cherryPickCommitID).branch).toBe('main'); }); - it('should support cherry-picking commits with no tag', function () { + it('should support cherry-picking commits with no tag', async () => { const str = `gitGraph commit id: "ZERO" branch develop @@ -734,14 +724,14 @@ describe('when parsing a gitGraph', function () { cherry-pick id:"A" tag:"" `; - parser.parse(str); - const commits = parser.yy.getCommits(); + await parser.parse(str); + const commits = db.getCommits(); const cherryPickCommitID = [...commits.keys()][2]; expect(commits.get(cherryPickCommitID).tags).toStrictEqual([]); expect(commits.get(cherryPickCommitID).branch).toBe('main'); }); - it('should support cherry-picking of merge commits', function () { + it('should support cherry-picking of merge commits', async () => { const str = `gitGraph commit id: "ZERO" branch feature @@ -755,14 +745,14 @@ describe('when parsing a gitGraph', function () { cherry-pick id: "M" parent:"B" `; - parser.parse(str); - const commits = parser.yy.getCommits(); + await parser.parse(str); + const commits = db.getCommits(); const cherryPickCommitID = [...commits.keys()][4]; expect(commits.get(cherryPickCommitID).tags).toStrictEqual(['cherry-pick:M|parent:B']); expect(commits.get(cherryPickCommitID).branch).toBe('release'); }); - it('should support cherry-picking of merge commits with tag', function () { + it('should support cherry-picking of merge commits with tag', async () => { const str = `gitGraph commit id: "ZERO" branch feature @@ -776,14 +766,14 @@ describe('when parsing a gitGraph', function () { cherry-pick id: "M" parent:"ZERO" tag: "v1.0" `; - parser.parse(str); - const commits = parser.yy.getCommits(); + await parser.parse(str); + const commits = db.getCommits(); const cherryPickCommitID = [...commits.keys()][4]; expect(commits.get(cherryPickCommitID).tags).toStrictEqual(['v1.0']); expect(commits.get(cherryPickCommitID).branch).toBe('release'); }); - it('should support cherry-picking of merge commits with additional commit', function () { + it('should support cherry-picking of merge commits with additional commit', async () => { const str = `gitGraph commit id: "ZERO" branch feature @@ -799,14 +789,14 @@ describe('when parsing a gitGraph', function () { commit id: "D" `; - parser.parse(str); - const commits = parser.yy.getCommits(); + await parser.parse(str); + const commits = db.getCommits(); const cherryPickCommitID = [...commits.keys()][5]; expect(commits.get(cherryPickCommitID).tags).toStrictEqual(['v2.1:ZERO']); expect(commits.get(cherryPickCommitID).branch).toBe('release'); }); - it('should support cherry-picking of merge commits with empty tag', function () { + it('should support cherry-picking of merge commits with empty tag', async () => { const str = `gitGraph commit id: "ZERO" branch feature @@ -823,8 +813,8 @@ describe('when parsing a gitGraph', function () { cherry-pick id:"M" tag:"" parent: "B" `; - parser.parse(str); - const commits = parser.yy.getCommits(); + await parser.parse(str); + const commits = db.getCommits(); const cherryPickCommitID = [...commits.keys()][5]; const cherryPickCommitID2 = [...commits.keys()][7]; expect(commits.get(cherryPickCommitID).tags).toStrictEqual([]); @@ -833,10 +823,11 @@ describe('when parsing a gitGraph', function () { }); it('should fail cherry-picking of merge commits if the parent of merge commits is not specified', function () { - expect(() => - parser - .parse( - `gitGraph + expect( + async () => + await parser + .parse( + `gitGraph commit id: "ZERO" branch feature branch release @@ -849,18 +840,19 @@ describe('when parsing a gitGraph', function () { commit id: "C" cherry-pick id:"M" ` - ) - .toThrow( - 'Incorrect usage of cherry-pick: If the source commit is a merge commit, an immediate parent commit must be specified.' - ) + ) + .toThrow( + 'Incorrect usage of cherry-pick: If the source commit is a merge commit, an immediate parent commit must be specified.' + ) ); }); it('should fail cherry-picking of merge commits when the parent provided is not an immediate parent of cherry picked commit', function () { - expect(() => - parser - .parse( - `gitGraph + expect( + async () => + await parser + .parse( + `gitGraph commit id: "ZERO" branch feature branch release @@ -873,14 +865,14 @@ describe('when parsing a gitGraph', function () { commit id: "C" cherry-pick id:"M" parent: "A" ` - ) - .toThrow( - 'Invalid operation: The specified parent commit is not an immediate parent of the cherry-picked commit.' - ) + ) + .toThrow( + 'Invalid operation: The specified parent commit is not an immediate parent of the cherry-picked commit.' + ) ); }); - it('should throw error when try to branch existing branch: main', function () { + it('should throw error when try to branch existing branch: main', async () => { const str = `gitGraph commit branch testBranch @@ -892,7 +884,7 @@ describe('when parsing a gitGraph', function () { `; try { - parser.parse(str); + await parser.parse(str); // Fail test if above expression doesn't throw anything. expect(true).toBe(false); } catch (e) { @@ -901,7 +893,7 @@ describe('when parsing a gitGraph', function () { ); } }); - it('should throw error when try to branch existing branch: testBranch', function () { + it('should throw error when try to branch existing branch: testBranch', async () => { const str = `gitGraph commit branch testBranch @@ -913,7 +905,7 @@ describe('when parsing a gitGraph', function () { `; try { - parser.parse(str); + await parser.parse(str); // Fail test if above expression doesn't throw anything. expect(true).toBe(false); } catch (e) { @@ -922,7 +914,7 @@ describe('when parsing a gitGraph', function () { ); } }); - it('should throw error when try to checkout unknown branch: testBranch', function () { + it('should throw error when try to checkout unknown branch: testBranch', async () => { const str = `gitGraph commit checkout testBranch @@ -934,7 +926,7 @@ describe('when parsing a gitGraph', function () { `; try { - parser.parse(str); + await parser.parse(str); // Fail test if above expression doesn't throw anything. expect(true).toBe(false); } catch (e) { @@ -943,7 +935,7 @@ describe('when parsing a gitGraph', function () { ); } }); - it('should throw error when trying to merge, when current branch has no commits', function () { + it('should throw error when trying to merge, when current branch has no commits', async () => { const str = `gitGraph merge testBranch commit @@ -956,14 +948,14 @@ describe('when parsing a gitGraph', function () { `; try { - parser.parse(str); + await parser.parse(str); // Fail test if above expression doesn't throw anything. expect(true).toBe(false); } catch (e) { expect(e.message).toBe('Incorrect usage of "merge". Current branch (main)has no commits'); } }); - it('should throw error when trying to merge unknown branch', function () { + it('should throw error when trying to merge unknown branch', async () => { const str = `gitGraph commit merge testBranch @@ -977,7 +969,7 @@ describe('when parsing a gitGraph', function () { `; try { - parser.parse(str); + await parser.parse(str); // Fail test if above expression doesn't throw anything. expect(true).toBe(false); } catch (e) { @@ -986,7 +978,7 @@ describe('when parsing a gitGraph', function () { ); } }); - it('should throw error when trying to merge branch to itself', function () { + it('should throw error when trying to merge branch to itself', async () => { const str = `gitGraph commit branch testBranch @@ -994,7 +986,7 @@ describe('when parsing a gitGraph', function () { `; try { - parser.parse(str); + await parser.parse(str); // Fail test if above expression doesn't throw anything. expect(true).toBe(false); } catch (e) { @@ -1002,7 +994,7 @@ describe('when parsing a gitGraph', function () { } }); - it('should throw error when using existing id as merge ID', function () { + it('should throw error when using existing id as merge ID', async () => { const str = `gitGraph commit id: "1-111" branch testBranch @@ -1013,7 +1005,7 @@ describe('when parsing a gitGraph', function () { `; try { - parser.parse(str); + await parser.parse(str); // Fail test if above expression doesn't throw anything. expect(true).toBe(false); } catch (e) { @@ -1022,7 +1014,7 @@ describe('when parsing a gitGraph', function () { ); } }); - it('should throw error when trying to merge branches having same heads', function () { + it('should throw error when trying to merge branches having same heads', async () => { const str = `gitGraph commit branch testBranch @@ -1031,14 +1023,14 @@ describe('when parsing a gitGraph', function () { `; try { - parser.parse(str); + await parser.parse(str); // Fail test if above expression doesn't throw anything. expect(true).toBe(false); } catch (e) { expect(e.message).toBe('Incorrect usage of "merge". Both branches have same head'); } }); - it('should throw error when trying to merge branch which has no commits', function () { + it('should throw error when trying to merge branch which has no commits', async () => { const str = `gitGraph branch test1 @@ -1048,7 +1040,7 @@ describe('when parsing a gitGraph', function () { `; try { - parser.parse(str); + await parser.parse(str); // Fail test if above expression doesn't throw anything. expect(true).toBe(false); } catch (e) { @@ -1058,17 +1050,17 @@ describe('when parsing a gitGraph', function () { } }); describe('accessibility', () => { - it('should handle a title and a description (accDescr)', () => { + it('should handle a title and a description (accDescr)', async () => { const str = `gitGraph: accTitle: This is a title accDescr: This is a description commit `; - parser.parse(str); - expect(parser.yy.getAccTitle()).toBe('This is a title'); - expect(parser.yy.getAccDescription()).toBe('This is a description'); + await parser.parse(str); + expect(db.getAccTitle()).toBe('This is a title'); + expect(db.getAccDescription()).toBe('This is a description'); }); - it('should handle a title and a multiline description (accDescr)', () => { + it('should handle a title and a multiline description (accDescr)', async () => { const str = `gitGraph: accTitle: This is a title accDescr { @@ -1077,15 +1069,15 @@ describe('when parsing a gitGraph', function () { } commit `; - parser.parse(str); - expect(parser.yy.getAccTitle()).toBe('This is a title'); - expect(parser.yy.getAccDescription()).toBe('This is a description\nusing multiple lines'); + await parser.parse(str); + expect(db.getAccTitle()).toBe('This is a title'); + expect(db.getAccDescription()).toBe('This is a description\nusing multiple lines'); }); }); describe('unsafe properties', () => { for (const prop of ['__proto__', 'constructor']) { - it(`should work with custom commit id or branch name ${prop}`, () => { + it(`should work with custom commit id or branch name ${prop}`, async () => { const str = `gitGraph commit id:"${prop}" branch ${prop} @@ -1094,13 +1086,13 @@ describe('when parsing a gitGraph', function () { checkout main merge ${prop} `; - parser.parse(str); - const commits = parser.yy.getCommits(); + await parser.parse(str); + const commits = db.getCommits(); expect(commits.size).toBe(3); expect(commits.keys().next().value).toBe(prop); - expect(parser.yy.getCurrentBranch()).toBe('main'); - expect(parser.yy.getBranches().size).toBe(2); - expect(parser.yy.getBranchesAsObjArray()[1].name).toBe(prop); + expect(db.getCurrentBranch()).toBe('main'); + expect(db.getBranches().size).toBe(2); + expect(db.getBranchesAsObjArray()[1].name).toBe(prop); }); } }); diff --git a/packages/parser/src/language/gitGraph/gitGraph.langium b/packages/parser/src/language/gitGraph/gitGraph.langium index 807f9382b7..1571ebba8a 100644 --- a/packages/parser/src/language/gitGraph/gitGraph.langium +++ b/packages/parser/src/language/gitGraph/gitGraph.langium @@ -26,7 +26,7 @@ hidden terminal SINGLE_LINE_COMMENT: /[\t ]*%%[^\n\r]*/; entry GitGraph: NEWLINE* - 'gitGraph' Direction? ':'? + ('gitGraph' | 'gitGraph' ':' | 'gitGraph:' | ('gitGraph' Direction ':')) NEWLINE* ( NEWLINE*