mirror of
https://github.com/mermaid-js/mermaid.git
synced 2025-11-17 19:24:10 +01:00
Merge branch '1252_gitgraph_reinvented' of github.com:mermaid-js/mermaid into 1252_gitgraph_reinvented
This commit is contained in:
@@ -1,9 +1,9 @@
|
|||||||
import { imgSnapshotTest } from '../../helpers/util.js';
|
import { imgSnapshotTest } from '../../helpers/util.js';
|
||||||
|
|
||||||
describe('Git Graph diagram', () => {
|
describe('Git Graph diagram', () => {
|
||||||
it('1: should render a simple gitgraph with commit on master branch', () => {
|
it('1: should render a simple gitgraph with commit on main branch', () => {
|
||||||
imgSnapshotTest(
|
imgSnapshotTest(
|
||||||
`gitgraph
|
`gitGraph
|
||||||
commit
|
commit
|
||||||
commit
|
commit
|
||||||
commit
|
commit
|
||||||
@@ -11,9 +11,9 @@ describe('Git Graph diagram', () => {
|
|||||||
{}
|
{}
|
||||||
);
|
);
|
||||||
});
|
});
|
||||||
it('2: should render a simple gitgraph with commit on master branch with Id', () => {
|
it('2: should render a simple gitgraph with commit on main branch with Id', () => {
|
||||||
imgSnapshotTest(
|
imgSnapshotTest(
|
||||||
`gitgraph
|
`gitGraph
|
||||||
commit id: "One"
|
commit id: "One"
|
||||||
commit id: "Two"
|
commit id: "Two"
|
||||||
commit id: "Three"
|
commit id: "Three"
|
||||||
@@ -21,9 +21,9 @@ describe('Git Graph diagram', () => {
|
|||||||
{}
|
{}
|
||||||
);
|
);
|
||||||
});
|
});
|
||||||
it('3: should render a simple gitgraph with different commitTypes on master branch ', () => {
|
it('3: should render a simple gitgraph with different commitTypes on main branch ', () => {
|
||||||
imgSnapshotTest(
|
imgSnapshotTest(
|
||||||
`gitgraph
|
`gitGraph
|
||||||
commit id: "Normal Commit"
|
commit id: "Normal Commit"
|
||||||
commit id: "Reverse Commit" commitType: REVERSE
|
commit id: "Reverse Commit" commitType: REVERSE
|
||||||
commit id: "Hightlight Commit" commitType: HIGHLIGHT
|
commit id: "Hightlight Commit" commitType: HIGHLIGHT
|
||||||
@@ -31,9 +31,9 @@ describe('Git Graph diagram', () => {
|
|||||||
{}
|
{}
|
||||||
);
|
);
|
||||||
});
|
});
|
||||||
it('4: should render a simple gitgraph with tags commitTypes on master branch ', () => {
|
it('4: should render a simple gitgraph with tags commitTypes on main branch ', () => {
|
||||||
imgSnapshotTest(
|
imgSnapshotTest(
|
||||||
`gitgraph
|
`gitGraph
|
||||||
commit id: "Normal Commit with tag" teg: "v1.0.0"
|
commit id: "Normal Commit with tag" teg: "v1.0.0"
|
||||||
commit id: "Reverse Commit with tag" commitType: REVERSE tag: "RC_1"
|
commit id: "Reverse Commit with tag" commitType: REVERSE tag: "RC_1"
|
||||||
commit id: "Hightlight Commit" commitType: HIGHLIGHT tag: "8.8.4"
|
commit id: "Hightlight Commit" commitType: HIGHLIGHT tag: "8.8.4"
|
||||||
@@ -43,14 +43,14 @@ describe('Git Graph diagram', () => {
|
|||||||
});
|
});
|
||||||
it('5: should render a simple gitgraph with two branches', () => {
|
it('5: should render a simple gitgraph with two branches', () => {
|
||||||
imgSnapshotTest(
|
imgSnapshotTest(
|
||||||
`gitgraph
|
`gitGraph
|
||||||
commit
|
commit
|
||||||
commit
|
commit
|
||||||
branch develop
|
branch develop
|
||||||
checkout develop
|
checkout develop
|
||||||
commit
|
commit
|
||||||
commit
|
commit
|
||||||
checkout master
|
checkout main
|
||||||
commit
|
commit
|
||||||
commit
|
commit
|
||||||
`,
|
`,
|
||||||
@@ -59,14 +59,14 @@ describe('Git Graph diagram', () => {
|
|||||||
});
|
});
|
||||||
it('6: should render a simple gitgraph with two branches and merge commit', () => {
|
it('6: should render a simple gitgraph with two branches and merge commit', () => {
|
||||||
imgSnapshotTest(
|
imgSnapshotTest(
|
||||||
`gitgraph
|
`gitGraph
|
||||||
commit
|
commit
|
||||||
commit
|
commit
|
||||||
branch develop
|
branch develop
|
||||||
checkout develop
|
checkout develop
|
||||||
commit
|
commit
|
||||||
commit
|
commit
|
||||||
checkout master
|
checkout main
|
||||||
merge develop
|
merge develop
|
||||||
commit
|
commit
|
||||||
commit
|
commit
|
||||||
@@ -76,27 +76,27 @@ describe('Git Graph diagram', () => {
|
|||||||
});
|
});
|
||||||
it('7: should render a simple gitgraph with three branches and merge commit', () => {
|
it('7: should render a simple gitgraph with three branches and merge commit', () => {
|
||||||
imgSnapshotTest(
|
imgSnapshotTest(
|
||||||
`gitgraph
|
`gitGraph
|
||||||
commit
|
commit
|
||||||
commit
|
commit
|
||||||
branch nice_feature
|
branch nice_feature
|
||||||
checkout nice_feature
|
checkout nice_feature
|
||||||
commit
|
commit
|
||||||
checkout master
|
checkout main
|
||||||
commit
|
commit
|
||||||
checkout nice_feature
|
checkout nice_feature
|
||||||
branch very_nice_feature
|
branch very_nice_feature
|
||||||
checkout very_nice_feature
|
checkout very_nice_feature
|
||||||
commit
|
commit
|
||||||
checkout master
|
checkout main
|
||||||
commit
|
commit
|
||||||
checkout nice_feature
|
checkout nice_feature
|
||||||
commit
|
commit
|
||||||
checkout master
|
checkout main
|
||||||
merge nice_feature
|
merge nice_feature
|
||||||
checkout very_nice_feature
|
checkout very_nice_feature
|
||||||
commit
|
commit
|
||||||
checkout master
|
checkout main
|
||||||
commit
|
commit
|
||||||
`,
|
`,
|
||||||
{}
|
{}
|
||||||
|
|||||||
@@ -2,8 +2,8 @@ import { log } from '../../logger';
|
|||||||
import { random } from '../../utils';
|
import { random } from '../../utils';
|
||||||
let commits = {};
|
let commits = {};
|
||||||
let head = null;
|
let head = null;
|
||||||
let branches = { master: head };
|
let branches = { main: head };
|
||||||
let curBranch = 'master';
|
let curBranch = 'main';
|
||||||
let direction = 'LR';
|
let direction = 'LR';
|
||||||
let seq = 0;
|
let seq = 0;
|
||||||
|
|
||||||
@@ -101,13 +101,85 @@ export const commit = function (msg, id, type, tag) {
|
|||||||
export const branch = function (name) {
|
export const branch = function (name) {
|
||||||
if (!branches[name]) {
|
if (!branches[name]) {
|
||||||
branches[name] = head != null ? head.id : null;
|
branches[name] = head != null ? head.id : null;
|
||||||
|
checkout(name);
|
||||||
log.debug('in createBranch');
|
log.debug('in createBranch');
|
||||||
|
} else {
|
||||||
|
let error = 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 +
|
||||||
|
'")'
|
||||||
|
);
|
||||||
|
error.hash = {
|
||||||
|
text: 'branch ' + name,
|
||||||
|
token: 'branch ' + name,
|
||||||
|
line: '1',
|
||||||
|
loc: { first_line: 1, last_line: 1, first_column: 1, last_column: 1 },
|
||||||
|
expected: ['"checkout ' + name + '"'],
|
||||||
|
};
|
||||||
|
throw error;
|
||||||
}
|
}
|
||||||
};
|
};
|
||||||
|
|
||||||
export const merge = function (otherBranch) {
|
export const merge = function (otherBranch) {
|
||||||
const currentCommit = commits[branches[curBranch]];
|
const currentCommit = commits[branches[curBranch]];
|
||||||
const otherCommit = commits[branches[otherBranch]];
|
const otherCommit = commits[branches[otherBranch]];
|
||||||
|
if (curBranch === otherBranch) {
|
||||||
|
let error = new Error('Incorrect usage of "merge". Cannot merge a branch to itself');
|
||||||
|
error.hash = {
|
||||||
|
text: 'merge ' + otherBranch,
|
||||||
|
token: 'merge ' + otherBranch,
|
||||||
|
line: '1',
|
||||||
|
loc: { first_line: 1, last_line: 1, first_column: 1, last_column: 1 },
|
||||||
|
expected: ['branch abc'],
|
||||||
|
};
|
||||||
|
throw error;
|
||||||
|
} else if (!currentCommit) {
|
||||||
|
let error = new Error(
|
||||||
|
'Incorrect usage of "merge". Current branch (' + curBranch + ')has no commits'
|
||||||
|
);
|
||||||
|
error.hash = {
|
||||||
|
text: 'merge ' + otherBranch,
|
||||||
|
token: 'merge ' + otherBranch,
|
||||||
|
line: '1',
|
||||||
|
loc: { first_line: 1, last_line: 1, first_column: 1, last_column: 1 },
|
||||||
|
expected: ['commit'],
|
||||||
|
};
|
||||||
|
throw error;
|
||||||
|
} else if (!branches[otherBranch]) {
|
||||||
|
let error = new Error(
|
||||||
|
'Incorrect usage of "merge". Branch to be merged (' + otherBranch + ') does not exist'
|
||||||
|
);
|
||||||
|
error.hash = {
|
||||||
|
text: 'merge ' + otherBranch,
|
||||||
|
token: 'merge ' + otherBranch,
|
||||||
|
line: '1',
|
||||||
|
loc: { first_line: 1, last_line: 1, first_column: 1, last_column: 1 },
|
||||||
|
expected: ['branch ' + otherBranch],
|
||||||
|
};
|
||||||
|
throw error;
|
||||||
|
} else if (!otherCommit) {
|
||||||
|
let error = new Error(
|
||||||
|
'Incorrect usage of "merge". Branch to be merged (' + otherBranch + ') has no commits'
|
||||||
|
);
|
||||||
|
error.hash = {
|
||||||
|
text: 'merge ' + otherBranch,
|
||||||
|
token: 'merge ' + otherBranch,
|
||||||
|
line: '1',
|
||||||
|
loc: { first_line: 1, last_line: 1, first_column: 1, last_column: 1 },
|
||||||
|
expected: ['"commit"'],
|
||||||
|
};
|
||||||
|
throw error;
|
||||||
|
} else if (currentCommit === otherCommit) {
|
||||||
|
let error = new Error('Incorrect usage of "merge". Both branches have same head');
|
||||||
|
error.hash = {
|
||||||
|
text: 'merge ' + otherBranch,
|
||||||
|
token: 'merge ' + otherBranch,
|
||||||
|
line: '1',
|
||||||
|
loc: { first_line: 1, last_line: 1, first_column: 1, last_column: 1 },
|
||||||
|
expected: ['branch abc'],
|
||||||
|
};
|
||||||
|
throw error;
|
||||||
|
}
|
||||||
// if (isReachableFrom(currentCommit, otherCommit)) {
|
// if (isReachableFrom(currentCommit, otherCommit)) {
|
||||||
// log.debug('Already merged');
|
// log.debug('Already merged');
|
||||||
// return;
|
// return;
|
||||||
@@ -136,12 +208,24 @@ export const merge = function (otherBranch) {
|
|||||||
export const checkout = function (branch) {
|
export const checkout = function (branch) {
|
||||||
log.debug('in checkout');
|
log.debug('in checkout');
|
||||||
if (!branches[branch]) {
|
if (!branches[branch]) {
|
||||||
branches[branch] = head != null ? head.id : null;
|
let error = new Error(
|
||||||
log.debug('in createBranch');
|
'Trying to checkout branch which is not yet created. (Help try using "branch ' + branch + '")'
|
||||||
}
|
);
|
||||||
|
error.hash = {
|
||||||
|
text: 'checkout ' + branch,
|
||||||
|
token: 'checkout ' + branch,
|
||||||
|
line: '1',
|
||||||
|
loc: { first_line: 1, last_line: 1, first_column: 1, last_column: 1 },
|
||||||
|
expected: ['"branch ' + branch + '"'],
|
||||||
|
};
|
||||||
|
throw error;
|
||||||
|
//branches[branch] = head != null ? head.id : null;
|
||||||
|
//log.debug('in createBranch');
|
||||||
|
} else {
|
||||||
curBranch = branch;
|
curBranch = branch;
|
||||||
const id = branches[curBranch];
|
const id = branches[curBranch];
|
||||||
head = commits[id];
|
head = commits[id];
|
||||||
|
}
|
||||||
};
|
};
|
||||||
|
|
||||||
// export const reset = function (commitRef) {
|
// export const reset = function (commitRef) {
|
||||||
@@ -219,8 +303,8 @@ export const prettyPrint = function () {
|
|||||||
export const clear = function () {
|
export const clear = function () {
|
||||||
commits = {};
|
commits = {};
|
||||||
head = null;
|
head = null;
|
||||||
branches = { master: head };
|
branches = { main: head };
|
||||||
curBranch = 'master';
|
curBranch = 'main';
|
||||||
seq = 0;
|
seq = 0;
|
||||||
};
|
};
|
||||||
|
|
||||||
|
|||||||
@@ -8,18 +8,17 @@ import { logger } from '../../logger';
|
|||||||
|
|
||||||
//jest.mock('crypto-random-string');
|
//jest.mock('crypto-random-string');
|
||||||
|
|
||||||
describe('when parsing a gitGraph', function() {
|
describe('when parsing a gitGraph', function () {
|
||||||
let randomNumber;
|
let randomNumber;
|
||||||
beforeEach(function() {
|
beforeEach(function () {
|
||||||
parser.yy = gitGraphAst;
|
parser.yy = gitGraphAst;
|
||||||
parser.yy.clear();
|
parser.yy.clear();
|
||||||
randomNumber = 0;
|
randomNumber = 0;
|
||||||
|
|
||||||
});
|
});
|
||||||
// afterEach(function() {
|
// afterEach(function() {
|
||||||
// cryptoRandomString.mockReset();
|
// cryptoRandomString.mockReset();
|
||||||
// });
|
// });
|
||||||
it('should handle a gitGraph commit with NO pararms, get auto-genrated reandom ID', function() {
|
it('should handle a gitGraph commit with NO pararms, get auto-genrated reandom ID', function () {
|
||||||
const str = `gitGraph:
|
const str = `gitGraph:
|
||||||
commit
|
commit
|
||||||
`;
|
`;
|
||||||
@@ -37,7 +36,7 @@ describe('when parsing a gitGraph', function() {
|
|||||||
expect(commits[key].type).toBe(0);
|
expect(commits[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', function () {
|
||||||
const str = `gitGraph:
|
const str = `gitGraph:
|
||||||
commit id:"1111"
|
commit id:"1111"
|
||||||
`;
|
`;
|
||||||
@@ -55,7 +54,7 @@ describe('when parsing a gitGraph', function() {
|
|||||||
expect(commits[key].type).toBe(0);
|
expect(commits[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', function () {
|
||||||
const str = `gitGraph:
|
const str = `gitGraph:
|
||||||
commit tag:"test"
|
commit tag:"test"
|
||||||
`;
|
`;
|
||||||
@@ -73,7 +72,7 @@ describe('when parsing a gitGraph', function() {
|
|||||||
expect(commits[key].type).toBe(0);
|
expect(commits[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', function () {
|
||||||
const str = `gitGraph:
|
const str = `gitGraph:
|
||||||
commit type: HIGHLIGHT
|
commit type: HIGHLIGHT
|
||||||
`;
|
`;
|
||||||
@@ -91,7 +90,7 @@ describe('when parsing a gitGraph', function() {
|
|||||||
expect(commits[key].type).toBe(2);
|
expect(commits[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', function () {
|
||||||
const str = `gitGraph:
|
const str = `gitGraph:
|
||||||
commit type: REVERSE
|
commit type: REVERSE
|
||||||
`;
|
`;
|
||||||
@@ -109,7 +108,7 @@ describe('when parsing a gitGraph', function() {
|
|||||||
expect(commits[key].type).toBe(1);
|
expect(commits[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', function () {
|
||||||
const str = `gitGraph:
|
const str = `gitGraph:
|
||||||
commit type: NORMAL
|
commit type: NORMAL
|
||||||
`;
|
`;
|
||||||
@@ -127,7 +126,7 @@ describe('when parsing a gitGraph', function() {
|
|||||||
expect(commits[key].type).toBe(0);
|
expect(commits[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', function () {
|
||||||
const str = `gitGraph:
|
const str = `gitGraph:
|
||||||
commit "test commit"
|
commit "test commit"
|
||||||
`;
|
`;
|
||||||
@@ -145,7 +144,25 @@ describe('when parsing a gitGraph', function() {
|
|||||||
expect(commits[key].type).toBe(0);
|
expect(commits[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 "msg:" key only', function () {
|
||||||
|
const str = `gitGraph:
|
||||||
|
commit msg: "test commit"
|
||||||
|
`;
|
||||||
|
|
||||||
|
parser.parse(str);
|
||||||
|
const commits = parser.yy.getCommits();
|
||||||
|
expect(Object.keys(commits).length).toBe(1);
|
||||||
|
expect(parser.yy.getCurrentBranch()).toBe('master');
|
||||||
|
expect(parser.yy.getDirection()).toBe('LR');
|
||||||
|
expect(Object.keys(parser.yy.getBranches()).length).toBe(1);
|
||||||
|
const key = Object.keys(commits)[0];
|
||||||
|
expect(commits[key].message).toBe('test commit');
|
||||||
|
expect(commits[key].id).not.toBeNull();
|
||||||
|
expect(commits[key].tag).toBe('');
|
||||||
|
expect(commits[key].type).toBe(0);
|
||||||
|
});
|
||||||
|
|
||||||
|
it('should handle a gitGraph commit with custom commit id, tag only', function () {
|
||||||
const str = `gitGraph:
|
const str = `gitGraph:
|
||||||
commit id:"1111" tag: "test tag"
|
commit id:"1111" tag: "test tag"
|
||||||
`;
|
`;
|
||||||
@@ -163,7 +180,7 @@ describe('when parsing a gitGraph', function() {
|
|||||||
expect(commits[key].type).toBe(0);
|
expect(commits[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', function () {
|
||||||
const str = `gitGraph:
|
const str = `gitGraph:
|
||||||
commit type:HIGHLIGHT tag: "test tag"
|
commit type:HIGHLIGHT tag: "test tag"
|
||||||
`;
|
`;
|
||||||
@@ -181,7 +198,7 @@ describe('when parsing a gitGraph', function() {
|
|||||||
expect(commits[key].type).toBe(2);
|
expect(commits[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', function () {
|
||||||
const str = `gitGraph:
|
const str = `gitGraph:
|
||||||
commit tag: "test tag" type:HIGHLIGHT
|
commit tag: "test tag" type:HIGHLIGHT
|
||||||
`;
|
`;
|
||||||
@@ -199,7 +216,7 @@ describe('when parsing a gitGraph', function() {
|
|||||||
expect(commits[key].type).toBe(2);
|
expect(commits[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', function () {
|
||||||
const str = `gitGraph:
|
const str = `gitGraph:
|
||||||
commit id:"1111" type:REVERSE tag: "test tag"
|
commit id:"1111" type:REVERSE tag: "test tag"
|
||||||
`;
|
`;
|
||||||
@@ -217,6 +234,180 @@ describe('when parsing a gitGraph', function() {
|
|||||||
expect(commits[key].type).toBe(1);
|
expect(commits[key].type).toBe(1);
|
||||||
});
|
});
|
||||||
|
|
||||||
|
it('should handle a gitGraph commit with custom commit id, type, tag and msg', function () {
|
||||||
|
const str = `gitGraph:
|
||||||
|
commit id:"1111" type:REVERSE tag: "test tag" msg:"test msg"
|
||||||
|
`;
|
||||||
|
|
||||||
|
parser.parse(str);
|
||||||
|
const commits = parser.yy.getCommits();
|
||||||
|
expect(Object.keys(commits).length).toBe(1);
|
||||||
|
expect(parser.yy.getCurrentBranch()).toBe('master');
|
||||||
|
expect(parser.yy.getDirection()).toBe('LR');
|
||||||
|
expect(Object.keys(parser.yy.getBranches()).length).toBe(1);
|
||||||
|
const key = Object.keys(commits)[0];
|
||||||
|
expect(commits[key].message).toBe('test msg');
|
||||||
|
expect(commits[key].id).toBe('1111');
|
||||||
|
expect(commits[key].tag).toBe('test tag');
|
||||||
|
expect(commits[key].type).toBe(1);
|
||||||
|
});
|
||||||
|
|
||||||
|
it('should handle a gitGraph commit with custom type,tag, msg, commit id,', function () {
|
||||||
|
const str = `gitGraph:
|
||||||
|
commit type:REVERSE tag: "test tag" msg: "test msg" id: "1111"
|
||||||
|
|
||||||
|
`;
|
||||||
|
|
||||||
|
parser.parse(str);
|
||||||
|
const commits = parser.yy.getCommits();
|
||||||
|
expect(Object.keys(commits).length).toBe(1);
|
||||||
|
expect(parser.yy.getCurrentBranch()).toBe('master');
|
||||||
|
expect(parser.yy.getDirection()).toBe('LR');
|
||||||
|
expect(Object.keys(parser.yy.getBranches()).length).toBe(1);
|
||||||
|
const key = Object.keys(commits)[0];
|
||||||
|
expect(commits[key].message).toBe('test msg');
|
||||||
|
expect(commits[key].id).toBe('1111');
|
||||||
|
expect(commits[key].tag).toBe('test tag');
|
||||||
|
expect(commits[key].type).toBe(1);
|
||||||
|
});
|
||||||
|
|
||||||
|
it('should handle a gitGraph commit with custom tag, msg, commit id, type,', function () {
|
||||||
|
const str = `gitGraph:
|
||||||
|
commit tag: "test tag" msg:"test msg" id:"1111" type:REVERSE
|
||||||
|
`;
|
||||||
|
|
||||||
|
parser.parse(str);
|
||||||
|
const commits = parser.yy.getCommits();
|
||||||
|
expect(Object.keys(commits).length).toBe(1);
|
||||||
|
expect(parser.yy.getCurrentBranch()).toBe('master');
|
||||||
|
expect(parser.yy.getDirection()).toBe('LR');
|
||||||
|
expect(Object.keys(parser.yy.getBranches()).length).toBe(1);
|
||||||
|
const key = Object.keys(commits)[0];
|
||||||
|
expect(commits[key].message).toBe('test msg');
|
||||||
|
expect(commits[key].id).toBe('1111');
|
||||||
|
expect(commits[key].tag).toBe('test tag');
|
||||||
|
expect(commits[key].type).toBe(1);
|
||||||
|
});
|
||||||
|
|
||||||
|
it('should handle a gitGraph commit with custom msg, commit id, type,tag', function () {
|
||||||
|
const str = `gitGraph:
|
||||||
|
commit msg:"test msg" id:"1111" type:REVERSE tag: "test tag"
|
||||||
|
`;
|
||||||
|
|
||||||
|
parser.parse(str);
|
||||||
|
const commits = parser.yy.getCommits();
|
||||||
|
expect(Object.keys(commits).length).toBe(1);
|
||||||
|
expect(parser.yy.getCurrentBranch()).toBe('master');
|
||||||
|
expect(parser.yy.getDirection()).toBe('LR');
|
||||||
|
expect(Object.keys(parser.yy.getBranches()).length).toBe(1);
|
||||||
|
const key = Object.keys(commits)[0];
|
||||||
|
expect(commits[key].message).toBe('test msg');
|
||||||
|
expect(commits[key].id).toBe('1111');
|
||||||
|
expect(commits[key].tag).toBe('test tag');
|
||||||
|
expect(commits[key].type).toBe(1);
|
||||||
|
});
|
||||||
|
|
||||||
|
it('should handle 3 straight commits', function () {
|
||||||
|
const str = `gitGraph:
|
||||||
|
commit
|
||||||
|
commit
|
||||||
|
commit
|
||||||
|
`;
|
||||||
|
|
||||||
|
parser.parse(str);
|
||||||
|
const commits = parser.yy.getCommits();
|
||||||
|
expect(Object.keys(commits).length).toBe(3);
|
||||||
|
expect(parser.yy.getCurrentBranch()).toBe('master');
|
||||||
|
expect(parser.yy.getDirection()).toBe('LR');
|
||||||
|
expect(Object.keys(parser.yy.getBranches()).length).toBe(1);
|
||||||
|
});
|
||||||
|
|
||||||
|
it('should handle new branch creation', function () {
|
||||||
|
const str = `gitGraph:
|
||||||
|
commit
|
||||||
|
branch testBranch
|
||||||
|
`;
|
||||||
|
|
||||||
|
parser.parse(str);
|
||||||
|
const commits = parser.yy.getCommits();
|
||||||
|
expect(Object.keys(commits).length).toBe(1);
|
||||||
|
expect(parser.yy.getCurrentBranch()).toBe('master');
|
||||||
|
expect(parser.yy.getDirection()).toBe('LR');
|
||||||
|
expect(Object.keys(parser.yy.getBranches()).length).toBe(2);
|
||||||
|
});
|
||||||
|
|
||||||
|
it('should handle new branch checkout', function () {
|
||||||
|
const str = `gitGraph:
|
||||||
|
commit
|
||||||
|
branch testBranch
|
||||||
|
checkout testBranch
|
||||||
|
`;
|
||||||
|
|
||||||
|
parser.parse(str);
|
||||||
|
const commits = parser.yy.getCommits();
|
||||||
|
expect(Object.keys(commits).length).toBe(1);
|
||||||
|
expect(parser.yy.getCurrentBranch()).toBe('testBranch');
|
||||||
|
expect(parser.yy.getDirection()).toBe('LR');
|
||||||
|
expect(Object.keys(parser.yy.getBranches()).length).toBe(2);
|
||||||
|
});
|
||||||
|
|
||||||
|
it('should handle new branch checkout & commit', function () {
|
||||||
|
const str = `gitGraph:
|
||||||
|
commit
|
||||||
|
branch testBranch
|
||||||
|
checkout testBranch
|
||||||
|
commit
|
||||||
|
`;
|
||||||
|
|
||||||
|
parser.parse(str);
|
||||||
|
const commits = parser.yy.getCommits();
|
||||||
|
expect(Object.keys(commits).length).toBe(2);
|
||||||
|
expect(parser.yy.getCurrentBranch()).toBe('testBranch');
|
||||||
|
expect(parser.yy.getDirection()).toBe('LR');
|
||||||
|
expect(Object.keys(parser.yy.getBranches()).length).toBe(2);
|
||||||
|
const commit1 = Object.keys(commits)[0];
|
||||||
|
const commit2 = Object.keys(commits)[1];
|
||||||
|
expect(commits[commit1].branch).toBe('master');
|
||||||
|
expect(commits[commit1].parents).toStrictEqual([]);
|
||||||
|
expect(commits[commit2].branch).toBe('testBranch');
|
||||||
|
expect(commits[commit2].parents).toStrictEqual([commit1]);
|
||||||
|
});
|
||||||
|
|
||||||
|
it('should handle new branch checkout & commit and merge', function () {
|
||||||
|
const str = `gitGraph:
|
||||||
|
commit
|
||||||
|
branch testBranch
|
||||||
|
checkout testBranch
|
||||||
|
commit
|
||||||
|
commit
|
||||||
|
checkout master
|
||||||
|
merge testBranch
|
||||||
|
`;
|
||||||
|
|
||||||
|
parser.parse(str);
|
||||||
|
const commits = parser.yy.getCommits();
|
||||||
|
expect(Object.keys(commits).length).toBe(4);
|
||||||
|
expect(parser.yy.getCurrentBranch()).toBe('master');
|
||||||
|
expect(parser.yy.getDirection()).toBe('LR');
|
||||||
|
expect(Object.keys(parser.yy.getBranches()).length).toBe(2);
|
||||||
|
const commit1 = Object.keys(commits)[0];
|
||||||
|
const commit2 = Object.keys(commits)[1];
|
||||||
|
const commit3 = Object.keys(commits)[2];
|
||||||
|
const commit4 = Object.keys(commits)[3];
|
||||||
|
expect(commits[commit1].branch).toBe('master');
|
||||||
|
console.log(commits);
|
||||||
|
|
||||||
|
console.log(commits[commit1].parents);
|
||||||
|
expect(commits[commit1].parents).toStrictEqual([]);
|
||||||
|
expect(commits[commit2].branch).toBe('testBranch');
|
||||||
|
expect(commits[commit2].parents).toStrictEqual([commits[commit1].id]);
|
||||||
|
expect(commits[commit3].branch).toBe('testBranch');
|
||||||
|
expect(commits[commit3].parents).toStrictEqual([commits[commit2].id]);
|
||||||
|
expect(commits[commit4].branch).toBe('master');
|
||||||
|
expect(commits[commit4].parents).toStrictEqual([commits[commit1].id, commits[commit3].id]);
|
||||||
|
expect(parser.yy.getBranchesAsObjArray()).toStrictEqual([
|
||||||
|
{ name: 'master' },
|
||||||
|
{ name: 'testBranch' },
|
||||||
|
]);
|
||||||
|
});
|
||||||
});
|
});
|
||||||
|
|||||||
@@ -240,7 +240,7 @@ const findLane = (y1, y2, _depth) => {
|
|||||||
lanes.push(candidate);
|
lanes.push(candidate);
|
||||||
return candidate;
|
return candidate;
|
||||||
}
|
}
|
||||||
const diff = math.abs(y1 - y2);
|
const diff = Math.abs(y1 - y2);
|
||||||
return findLane(y1, y2-(diff/5), depth);
|
return findLane(y1, y2-(diff/5), depth);
|
||||||
}
|
}
|
||||||
|
|
||||||
|
|||||||
@@ -52,7 +52,8 @@
|
|||||||
%% /* language grammar */
|
%% /* language grammar */
|
||||||
|
|
||||||
start
|
start
|
||||||
: GG ':' document EOF{ return $3; }
|
: GG document EOF{ return $3; }
|
||||||
|
| GG ':' document EOF{ return $3; }
|
||||||
| GG DIR ':' document EOF {yy.setDirection($2); return $4;}
|
| GG DIR ':' document EOF {yy.setDirection($2); return $4;}
|
||||||
;
|
;
|
||||||
|
|
||||||
@@ -71,7 +72,7 @@ body
|
|||||||
| body line {$1.push($2); $$=$1;}
|
| body line {$1.push($2); $$=$1;}
|
||||||
;
|
;
|
||||||
line
|
line
|
||||||
: statement NL{$$ =$1}
|
: statement {$$ =$1}
|
||||||
| NL
|
| NL
|
||||||
;
|
;
|
||||||
|
|
||||||
|
|||||||
Reference in New Issue
Block a user