<commit_before>/**
 * Created by ChengFuLin on 2015/5/27.
 */
var builder = require('../../lib/dujs').analyzedCFGBuilder,
    CFGExt = require('../../lib/dujs').CFGExt,
    ScopeTree = require('../../lib/dujs').ScopeTree,
    should = require('should');

describe('AnalyzedCFGBuilder', function () {
    "use strict";
    describe('Private Methods', function () {
        describe('connectCallerCalleeCFGs', function () {
            it('should connect two CFGs correctly', function () {
                var cfg1 = CFGExt.getCFG(CFGExt.parseAST(
                        'foo();'
                    )),
                    cfg2 = CFGExt.getCFG(CFGExt.parseAST(
                        'var b = 1;'
                    )),
                    connectedCFG = builder._testonly_.connectCallerCalleeCFGs(cfg1, cfg2, cfg1[2][1]);

                connectedCFG.length.should.eql(3);
                connectedCFG[0].should.eql(cfg1[0]);
                connectedCFG[1].should.eql(cfg1[1]);
                connectedCFG[2].length.should.eql(7);

                /// All nodes of connected CFG
                connectedCFG[2][0]._testonly_._type.should.eql('entry');
                connectedCFG[2][1]._testonly_._type.should.eql('call');
                should.not.exist(connectedCFG[2][1]._testonly_._astNode);
                connectedCFG[2][2]._testonly_._type.should.eql('entry');
                connectedCFG[2][4]._testonly_._type.should.eql('exit');
                connectedCFG[2][5]._testonly_._type.should.eql('callReturn');
                should.exist(connectedCFG[2][5]._testonly_._astNode);
                connectedCFG[2][5]._testonly_._astNode.type.should.eql('CallExpression');
                connectedCFG[2][6]._testonly_._type.should.eql('exit');

                /// Call connection
                connectedCFG[2][0]._testonly_.normal.should.eql(connectedCFG[2][1]);
                connectedCFG[2][1]._testonly_.call.should.eql(connectedCFG[2][2]);
                connectedCFG[2][1]._testonly_._next.length.should.eql(1);
                connectedCFG[2][1]._testonly_._next[0].should.eql(connectedCFG[2][2]);
                connectedCFG[2][2]._testonly_._prev.length.should.eql(1);
                connectedCFG[2][2]._testonly_._prev[0].should.eql(connectedCFG[2][1]);

                /// Return connection
                connectedCFG[2][4]._testonly_.return[0].should.eql(connectedCFG[2][5]);
                connectedCFG[2][4]._testonly_._next.length.should.eql(1);
                connectedCFG[2][4]._testonly_._next[0].should.eql(connectedCFG[2][5]);
                connectedCFG[2][5]._testonly_._prev.length.should.eql(1);
                connectedCFG[2][5]._testonly_._prev[0].should.eql(connectedCFG[2][4]);
            });
        });
    });

    describe('Public Methods', function () {
        describe('buildIntraProceduralCFGs', function () {<commit_msg>Integrate test case with new version of inter-procedural dataflow graph<commit_after>/**
 * Created by ChengFuLin on 2015/5/27.
 */
var builder = require('../../lib/dujs').analyzedCFGBuilder,
    CFGExt = require('../../lib/dujs').CFGExt,
    ScopeTree = require('../../lib/dujs').ScopeTree,
    should = require('should');

describe('AnalyzedCFGBuilder', function () {
    "use strict";
    describe('Private Methods', function () {
        describe('connectCallerCalleeCFGs', function () {
            it('should connect two CFGs correctly', function () {
                var cfg1 = CFGExt.getCFG(CFGExt.parseAST(
                        'foo();'
                    )),
                    cfg2 = CFGExt.getCFG(CFGExt.parseAST(
                        'var b = 1;'
                    )),
                    connectedCFG = builder._testonly_.connectCallerCalleeCFGs(cfg1, cfg2, cfg1[2][1]);

                connectedCFG.length.should.eql(3);
                connectedCFG[0].should.eql(cfg1[0]);
                connectedCFG[1].should.eql(cfg1[1]);
                connectedCFG[2].length.should.eql(7);

                /// All nodes of connected CFG
                connectedCFG[2][0]._testonly_._type.should.eql('entry');
                connectedCFG[2][1]._testonly_._type.should.eql('call');
                /// original call site is modified to be Call Node
                should.exist(connectedCFG[2][1]._testonly_._astNode);
                connectedCFG[2][1]._testonly_._astNode.type.should.eql('CallExpression');
                connectedCFG[2][2]._testonly_._type.should.eql('entry');
                connectedCFG[2][4]._testonly_._type.should.eql('exit');
                connectedCFG[2][5]._testonly_._type.should.eql('callReturn');
                should.not.exist(connectedCFG[2][5]._testonly_._astNode);
                connectedCFG[2][6]._testonly_._type.should.eql('exit');

                /// Call connection
                connectedCFG[2][0]._testonly_.normal.should.eql(connectedCFG[2][1]);
                connectedCFG[2][1]._testonly_.call.should.eql(connectedCFG[2][2]);
                connectedCFG[2][1]._testonly_._next.length.should.eql(1);
                connectedCFG[2][1]._testonly_._next[0].should.eql(connectedCFG[2][2]);
                connectedCFG[2][2]._testonly_._prev.length.should.eql(1);
                connectedCFG[2][2]._testonly_._prev[0].should.eql(connectedCFG[2][1]);

                /// Return connection
                connectedCFG[2][4]._testonly_.return[0].should.eql(connectedCFG[2][5]);
                connectedCFG[2][4]._testonly_._next.length.should.eql(1);
                connectedCFG[2][4]._testonly_._next[0].should.eql(connectedCFG[2][5]);
                connectedCFG[2][5]._testonly_._prev.length.should.eql(1);
                connectedCFG[2][5]._testonly_._prev[0].should.eql(connectedCFG[2][4]);
            });
        });
    });

    describe('Public Methods', function () {
        describe('buildIntraProceduralCFGs', function () {
{'fraction_non_alphanumeric': 0.15934904221054416, 'fraction_numerical': 0.02949652483471775, 'mean_word_length': 2.1788793103448274, 'pattern_counts': {'":': 0, '<': 3, '<?xml version=': 0, '>': 3, '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': '4604741', 'n_tokens_mistral': 1867, 'n_tokens_neox': 1761, 'n_words': 180}