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;
|
|
|
|
parser.yy.reset();
|
|
|
|
});
|
|
|
|
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-26 22:16:47 +05:30
|
|
|
it('should handle branch statement', 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' +
|
|
|
|
'commit\n' +
|
|
|
|
'commit\n';
|
|
|
|
|
2016-03-27 11:00:44 +05:30
|
|
|
console.log(parser.parse(str));
|
2016-03-26 22:16:47 +05:30
|
|
|
var commits = parser.yy.getCommits();
|
|
|
|
console.log(commits);
|
|
|
|
|
|
|
|
expect(Object.keys(commits).length).toBe(4);
|
|
|
|
expect(parser.yy.getCurrentBranch()).toBe("master");
|
|
|
|
expect(Object.keys(parser.yy.getBranches())).toContain('newbranch');
|
|
|
|
expect(Object.keys(parser.yy.getBranches()).length).toBe(2);
|
|
|
|
});
|
2016-03-27 11:00:44 +05:30
|
|
|
|
2016-03-26 22:16:47 +05:30
|
|
|
});
|