2016-03-26 22:16:47 +05:30
|
|
|
var parser = require('./parser/gitGraph').parser;
|
|
|
|
var ast = require("./gitGraphAst.js");
|
|
|
|
describe('when parsing a gitGraph',function() {
|
2016-03-27 11:00:44 +05:30
|
|
|
"use strict";
|
2016-03-26 22:16:47 +05:30
|
|
|
beforeEach(function () {
|
|
|
|
parser.yy = ast;
|
2016-03-27 11:22:30 +05:30
|
|
|
parser.yy.clear();
|
2016-03-26 22:16:47 +05:30
|
|
|
});
|
|
|
|
it('should handle a gitGraph defintion', function () {
|
2016-03-27 11:00:44 +05:30
|
|
|
var str = 'gitGraph:\n' +
|
|
|
|
'commit\n';
|
2016-03-26 22:16:47 +05:30
|
|
|
|
|
|
|
parser.parse(str);
|
|
|
|
var commits = parser.yy.getCommits();
|
|
|
|
console.log(commits);
|
|
|
|
|
|
|
|
expect(Object.keys(commits).length).toBe(1);
|
|
|
|
expect(parser.yy.getCurrentBranch()).toBe("master");
|
2016-03-27 11:00:44 +05:30
|
|
|
expect(parser.yy.getDirection()).toBe("LR");
|
2016-03-26 22:16:47 +05:30
|
|
|
expect(Object.keys(parser.yy.getBranches()).length).toBe(1);
|
|
|
|
});
|
2016-03-27 11:00:44 +05:30
|
|
|
|
|
|
|
it('should handle set direction', function () {
|
|
|
|
var str = 'gitGraph TB:\n' +
|
|
|
|
'commit\n';
|
|
|
|
|
|
|
|
parser.parse(str);
|
|
|
|
var commits = parser.yy.getCommits();
|
|
|
|
console.log(commits);
|
|
|
|
|
|
|
|
expect(Object.keys(commits).length).toBe(1);
|
|
|
|
expect(parser.yy.getCurrentBranch()).toBe("master");
|
|
|
|
expect(parser.yy.getDirection()).toBe("TB");
|
|
|
|
expect(Object.keys(parser.yy.getBranches()).length).toBe(1);
|
|
|
|
});
|
2016-03-27 11:12:47 +05:30
|
|
|
|
2016-03-27 11:00:44 +05:30
|
|
|
it('should checkout a branch', function () {
|
|
|
|
var str = 'gitGraph:\n' +
|
|
|
|
'branch new\n' +
|
|
|
|
'checkout new\n'
|
|
|
|
|
|
|
|
parser.parse(str);
|
|
|
|
var commits = parser.yy.getCommits();
|
|
|
|
|
|
|
|
expect(Object.keys(commits).length).toBe(0);
|
|
|
|
expect(parser.yy.getCurrentBranch()).toBe("new");
|
|
|
|
});
|
|
|
|
|
2016-03-27 11:12:47 +05:30
|
|
|
it('should add commits to checked out branch', function () {
|
|
|
|
var str = 'gitGraph:\n' +
|
|
|
|
'branch new\n' +
|
|
|
|
'checkout new\n' +
|
|
|
|
'commit\n'+
|
|
|
|
'commit\n'
|
|
|
|
|
|
|
|
parser.parse(str);
|
|
|
|
var commits = parser.yy.getCommits();
|
|
|
|
|
|
|
|
expect(Object.keys(commits).length).toBe(2);
|
|
|
|
expect(parser.yy.getCurrentBranch()).toBe("new");
|
|
|
|
var branchCommit = parser.yy.getBranches()['new'];
|
|
|
|
expect(branchCommit).not.toBeNull();
|
|
|
|
expect(commits[branchCommit].parent).not.toBeNull();
|
|
|
|
});
|
2016-03-27 11:00:44 +05:30
|
|
|
it('should handle commit with args', function () {
|
|
|
|
var str = 'gitGraph:\n' +
|
|
|
|
'commit "a commit"\n';
|
|
|
|
|
|
|
|
parser.parse(str);
|
|
|
|
var commits = parser.yy.getCommits();
|
|
|
|
console.log(commits);
|
|
|
|
|
|
|
|
expect(Object.keys(commits).length).toBe(1);
|
|
|
|
var key = Object.keys(commits)[0];
|
|
|
|
expect(commits[key].message).toBe("a commit");
|
|
|
|
expect(parser.yy.getCurrentBranch()).toBe("master");
|
|
|
|
});
|
|
|
|
|
2016-03-27 14:45:26 +05:30
|
|
|
it('it should reset a branch', function () {
|
2016-03-27 11:00:44 +05:30
|
|
|
var str = 'gitGraph:\n' +
|
2016-03-26 22:16:47 +05:30
|
|
|
'commit\n' +
|
|
|
|
'commit\n' +
|
|
|
|
'branch newbranch\n' +
|
2016-03-27 14:45:26 +05:30
|
|
|
'checkout newbranch\n' +
|
2016-03-26 22:16:47 +05:30
|
|
|
'commit\n' +
|
2016-03-27 14:45:26 +05:30
|
|
|
'reset master\n';
|
2016-03-26 22:16:47 +05:30
|
|
|
|
2016-03-27 16:13:07 +05:30
|
|
|
parser.parse(str);
|
2016-03-26 22:16:47 +05:30
|
|
|
|
2016-03-27 16:13:07 +05:30
|
|
|
var commits = parser.yy.getCommits();
|
2016-03-27 14:45:26 +05:30
|
|
|
expect(Object.keys(commits).length).toBe(3);
|
|
|
|
expect(parser.yy.getCurrentBranch()).toBe("newbranch");
|
|
|
|
expect(parser.yy.getBranches()["newbranch"]).toEqual(parser.yy.getBranches()["master"]);
|
|
|
|
expect(parser.yy.getHead().id).toEqual(parser.yy.getBranches()["newbranch"]);
|
2016-03-26 22:16:47 +05:30
|
|
|
});
|
2016-03-27 11:00:44 +05:30
|
|
|
|
2016-03-27 16:13:07 +05:30
|
|
|
it('it should handle fast forwardable merges', function () {
|
|
|
|
var str = 'gitGraph:\n' +
|
|
|
|
'commit\n' +
|
|
|
|
'branch newbranch\n' +
|
|
|
|
'checkout newbranch\n' +
|
|
|
|
'commit\n' +
|
|
|
|
'commit\n' +
|
|
|
|
'checkout master\n'+
|
|
|
|
'merge newbranch\n';
|
|
|
|
|
|
|
|
parser.parse(str);
|
|
|
|
|
|
|
|
var commits = parser.yy.getCommits();
|
|
|
|
console.log(commits);
|
|
|
|
expect(Object.keys(commits).length).toBe(3);
|
|
|
|
expect(parser.yy.getCurrentBranch()).toBe("master");
|
|
|
|
expect(parser.yy.getBranches()["newbranch"]).toEqual(parser.yy.getBranches()["master"]);
|
|
|
|
expect(parser.yy.getHead().id).toEqual(parser.yy.getBranches()["newbranch"]);
|
|
|
|
});
|
|
|
|
|
2016-03-27 17:35:29 +05:30
|
|
|
it('it should handle cases when merge is a noop', function () {
|
|
|
|
var str = 'gitGraph:\n' +
|
|
|
|
'commit\n' +
|
|
|
|
'branch newbranch\n' +
|
|
|
|
'checkout newbranch\n' +
|
|
|
|
'commit\n' +
|
|
|
|
'commit\n' +
|
|
|
|
'merge master\n';
|
|
|
|
|
|
|
|
parser.parse(str);
|
|
|
|
|
|
|
|
var commits = parser.yy.getCommits();
|
|
|
|
console.log(commits);
|
|
|
|
expect(Object.keys(commits).length).toBe(3);
|
|
|
|
expect(parser.yy.getCurrentBranch()).toBe("newbranch");
|
|
|
|
expect(parser.yy.getBranches()["newbranch"]).not.toEqual(parser.yy.getBranches()["master"]);
|
|
|
|
expect(parser.yy.getHead().id).toEqual(parser.yy.getBranches()["newbranch"]);
|
|
|
|
});
|
2016-03-26 22:16:47 +05:30
|
|
|
});
|