<commit_before>var proxyquire = require('proxyquire');
/**
 * Created by knut on 14-11-18.
 */
//var proxyquire = require('proxyquire');
//var log = require('../../logger').create();

var sq = require('./parser/sequenceDiagram').parser;
var newD3;

var d3 = {
    select:function(){
        return new newD3();
    },
    selectAll:function(){
        return new newD3();
    }
};
//var sd = proxyquire('./sequenceRenderer', { './d3': d3 });
var sd = proxyquire('./sequenceRenderer', { '../../d3': d3 });

//
//
//var sd = require('./sequenceRenderer');

var str;
describe('when parsing a sequenceDiagram',function() {
    beforeEach(function () {
        sq.yy = require('./sequenceDb');
        sq.yy.clear();
        //parseError = function(err, hash) {
        //    log.debug('Syntax error:' + err);
        //    log.debug(hash);
        //};
        //sq.yy.parseError = parseError;
    });
    it('it should handle a sequenceDiagram defintion', function () {
        str = 'sequenceDiagram\n' +
        'Alice->Bob:Hello Bob, how are you?\n' +
        'Note right of Bob: Bob thinks\n' +
        'Bob-->Alice: I am good thanks!';

        sq.parse(str);
        var actors = sq.yy.getActors();
        expect(actors.Alice.description).toBe('Alice');
        actors.Bob.description = 'Bob';

        var messages = sq.yy.getMessages();

        expect(messages.length).toBe(3);
        expect(messages[0].from).toBe('Alice');
        expect(messages[2].from).toBe('Bob');
    });
    it('it should space in actor names', function () {
        str = 'sequenceDiagram\n' +
        'Alice->Bob:Hello Bob, how are - you?\n' +
        'Bob-->Alice: I am good thanks!';

        sq.parse(str);
        var actors = sq.yy.getActors();
        expect(actors.Alice.description).toBe('Alice');
        actors.Bob.description = 'Bob';

        var messages = sq.yy.getMessages();

        expect(messages.length).toBe(2);
        expect(messages[0].from).toBe('Alice');
        expect(messages[1].from).toBe('Bob');
    });
    it('it should handle in async messages', function () {
        var str = 'sequenceDiagram\n' +
        'Alice-xBob:Hello Bob, how are you?';

        sq.parse(str);
        var actors = sq.yy.getActors();
        expect(actors.Alice.description).toBe('Alice');
        expect(actors.Bob.description).toBe('Bob');

        var messages = sq.yy.getMessages();

        expect(messages.length).toBe(1);
        expect(messages[0].type).toBe(sq.yy.LINETYPE.SOLID_CROSS);
    });
    it('it should handle in async dotted messages', function () {
        var str = 'sequenceDiagram\n' +
        'Alice--xBob:Hello Bob, how are you?';
<commit_msg>Test for sequenceDiagram participant aliasing<commit_after>var proxyquire = require('proxyquire');
/**
 * Created by knut on 14-11-18.
 */
//var proxyquire = require('proxyquire');
//var log = require('../../logger').create();

var sq = require('./parser/sequenceDiagram').parser;
var newD3;

var d3 = {
    select:function(){
        return new newD3();
    },
    selectAll:function(){
        return new newD3();
    }
};
//var sd = proxyquire('./sequenceRenderer', { './d3': d3 });
var sd = proxyquire('./sequenceRenderer', { '../../d3': d3 });

//
//
//var sd = require('./sequenceRenderer');

var str;
describe('when parsing a sequenceDiagram',function() {
    beforeEach(function () {
        sq.yy = require('./sequenceDb');
        sq.yy.clear();
        //parseError = function(err, hash) {
        //    log.debug('Syntax error:' + err);
        //    log.debug(hash);
        //};
        //sq.yy.parseError = parseError;
    });
    it('it should handle a sequenceDiagram defintion', function () {
        str = 'sequenceDiagram\n' +
        'Alice->Bob:Hello Bob, how are you?\n' +
        'Note right of Bob: Bob thinks\n' +
        'Bob-->Alice: I am good thanks!';

        sq.parse(str);
        var actors = sq.yy.getActors();
        expect(actors.Alice.description).toBe('Alice');
        actors.Bob.description = 'Bob';

        var messages = sq.yy.getMessages();

        expect(messages.length).toBe(3);
        expect(messages[0].from).toBe('Alice');
        expect(messages[2].from).toBe('Bob');
    });
    it('it should space in actor names', function () {
        str = 'sequenceDiagram\n' +
        'Alice->Bob:Hello Bob, how are - you?\n' +
        'Bob-->Alice: I am good thanks!';

        sq.parse(str);
        var actors = sq.yy.getActors();
        expect(actors.Alice.description).toBe('Alice');
        actors.Bob.description = 'Bob';

        var messages = sq.yy.getMessages();

        expect(messages.length).toBe(2);
        expect(messages[0].from).toBe('Alice');
        expect(messages[1].from).toBe('Bob');
    });
    it('it should alias participants', function () {
        str = 'sequenceDiagram\n' +
            'participant A as Alice\n' +
            'participant B as Bob\n' +
            'A->B:Hello Bob, how are you?\n' +
            'B-->A: I am good thanks!';

        sq.parse(str);

        var actors = sq.yy.getActors();
        expect(Object.keys(actors)).toEqual(['A', 'B']);
        expect(actors.A.description).toBe('Alice');
        expect(actors.B.description).toBe('Bob');

        var messages = sq.yy.getMessages();
        expect(messages.length).toBe(2);
        expect(messages[0].from).toBe('A');
        expect(messages[1].from).toBe('B');
    });
    it('it should handle in async messages', function () {
        var str = 'sequenceDiagram\n' +
        'Alice-xBob:Hello Bob, how are you?';

        sq.parse(str);
        var actors = sq.yy.getActors();
        expect(actors.Alice.description).toBe('Alice');
        expect(actors.Bob.description).toBe('Bob');

        var messages = sq.yy.getMessages();

        expect(messages.length).toBe(1);
        expect(messages[0].type).toBe(sq.yy.LINETYPE.SOLID_CROSS);
    });
    it('it should handle in async dotted messages', function () {
        var str = 'sequenceDiagram\n' +
        'Alice--xBob:Hello Bob, how are you?';

{'fraction_non_alphanumeric': 0.1788442377947526, 'fraction_numerical': 0.007804716041182332, 'mean_word_length': 2.378014582164891, 'pattern_counts': {'":': 0, '<': 3, '<?xml version=': 0, '>': 13, 'https://': 0, 'lorem ipsum': 0, 'www.': 0, 'xml': 0}, 'pii_count': 0, 'substrings_counts': 0, 'word_list_counts': {'cursed_substrings.json': 0, 'profanity_word_list.json': 0, 'sexual_word_list.json': 0, 'zh_pornsignals.json': 0}}
{'dir': 'git-commits-cleaned', 'id': '821930', 'n_tokens_mistral': 1916, 'n_tokens_neox': 1841, 'n_words': 389}