<commit_before>var request = require('request');
var assert = require('assert');
var _ = require('underscore');
var echo = console.log;

var testbed = {
    uri:'http://nodejs.org/api/http.json',
    matches:{
        source:'doc/api/http.markdown',
        modules:[{ 
            textRaw:'HTTP', 
            name:'http',
            stability:3,
            stabilityText:'Stable',
            desc: '_IGNORE_',
            properties:[
                {
                    textRaw: '`STATUS_CODES` {Object} ',
                    name:'STATUS_CODES',
                    desc:'_IGNORE_'
                },
                {
                    textRaw:'http.globalAgent',
                    name:'globalAgent',
                    desc:'_IGNORE_'
                },
                {
                    textRaw:'http.IncomingMessage',
                    name:'IncomingMessage',
                    desc:'_IGNORE_',
                    events:[{
                        textRaw:"Event: 'close'",
                        type: 'event',
                        name: 'close',
                        desc: '_IGNORE_',
                        params:[]
                    }],
                    properties:[
                    {
                        textRaw: 'message.httpVersion',
                        name: 'httpVersion',
                        desc: '_IGNORE_',
                    },
                    {
                        textRaw: 'message.headers',
                        name: 'headers',
                        desc: '_IGNORE_',
                    },
                    {
                        textRaw: 'message.trailers',
                        name: 'trailers',
                        desc: '_IGNORE_',
                    },
                    {
                        textRaw: 'message.method',
                        name: 'method', 
                        desc: '_IGNORE_',
                    },
                    {
                        textRaw: 'message.url',
                        name: 'url',
                        desc: '_IGNORE_',
                    },
                    {
                        textRaw: 'message.statusCode',
                        name: 'statusCode',
                        desc: '_IGNORE_' 
                    },
                    {
                        textRaw: 'message.socket',
                        name: 'socket',
                        desc: '_IGNORE_',
                    }
                    ],
                    methods:[
                    {
                        textRaw: 'message.setTimeout(msecs, callback)',
                        type: 'method',
                        name: 'setTimeout',
                    }
                    ]
                }
            ],
        }]
    }
};

function nextMatch(matches) {
    this.stack = [];
    var that = this;
    inpsect(matches);
    function inpsect(object,key){
        if (object == undefined) return;
        if (_.isObject(object)){
            _.each(object, function(value,key){
                inpsect(value,key);
            });
        }else{
            //echo("key=",key, "expect=",object);
            that.stack.push({'key':key,'expect':object});
        } 
    }
    
    this.next = function next(){
        that.stack.shift();
    }
}

function compareDeep(object,matches,key){
    if (_.isObject(object)){
        _.each(object, function(value,key){
            compareDeep(value,matches,key);
        });
    }else{
        
        if (key === 'desc'){
            object = "_IGNORE_"; //ignore all desc string;
        }
        var actualKey = key;
        var actual = object;
        var match = matches.stack.shift();
        //echo(actualKey,actual,matches,match);
        if (match === undefined){
            return //no more match , exit;
        }
        var expect = match.expect;
        var expectKey = match.key;
        try {
            assert.strictEqual(actualKey,expectKey);
            assert.strictEqual(actual,expect);
            echo("Tested [ "+key+" ] == '"+expect+"'","OK!");
        }catch(e){
            echo("Tested [ "+key+" ] == '"+expect+"'","FAIL!");
            echo("[ actual ] =",actual);
            echo("[ match  ] =",match);
            echo(e.stack)

        }

    }
}

function jsonHttpTest(payload){
    var reqBody = {
        method: payload.method||'GET',
        uri: payload.uri<commit_msg>warning msg<commit_after>var request = require('request');
var assert = require('assert');
var _ = require('underscore');
var echo = console.log;

var testbed = {
    uri:'http://nodejs.org/api/http.json',
    matches:{
        source:'doc/api/http.markdown',
        modules:[{ 
            textRaw:'HTTP', 
            name:'http',
            stability:3,
            stabilityText:'Stable',
            desc: '_IGNORE_',
            properties:[
                {
                    textRaw: '`STATUS_CODES` {Object} ',
                    name:'STATUS_CODES',
                    desc:'_IGNORE_'
                },
                {
                    textRaw:'http.globalAgent',
                    name:'globalAgent',
                    desc:'_IGNORE_'
                },
                {
                    textRaw:'http.IncomingMessage',
                    name:'IncomingMessage',
                    desc:'_IGNORE_',
                    events:[{
                        textRaw:"Event: 'close'",
                        type: 'event',
                        name: 'close',
                        desc: '_IGNORE_',
                        params:[]
                    }],
                    properties:[
                    {
                        textRaw: 'message.httpVersion',
                        name: 'httpVersion',
                        desc: '_IGNORE_',
                    },
                    {
                        textRaw: 'message.headers',
                        name: 'headers',
                        desc: '_IGNORE_',
                    },
                    {
                        textRaw: 'message.trailers',
                        name: 'trailers',
                        desc: '_IGNORE_',
                    },
                    {
                        textRaw: 'message.method',
                        name: 'method', 
                        desc: '_IGNORE_',
                    },
                    {
                        textRaw: 'message.url',
                        name: 'url',
                        desc: '_IGNORE_',
                    },
                    {
                        textRaw: 'message.statusCode',
                        name: 'statusCode',
                        desc: '_IGNORE_' 
                    },
                    {
                        textRaw: 'message.socket',
                        name: 'socket',
                        desc: '_IGNORE_',
                    }
                    ],
                    methods:[
                    {
                        textRaw: 'message.setTimeout(msecs, callback)',
                        type: 'method',
                        name: 'setTimeout',
                    }
                    ]
                }
            ],
        }]
    }
};

function nextMatch(matches) {
    this.stack = [];
    var that = this;
    inpsect(matches);
    function inpsect(object,key){
        if (object == undefined) return;
        if (_.isObject(object)){
            _.each(object, function(value,key){
                inpsect(value,key);
            });
        }else{
            //echo("key=",key, "expect=",object);
            that.stack.push({'key':key,'expect':object});
        } 
    }
    
    this.next = function next(){
        that.stack.shift();
    }
}

function compareDeep(object,matches,key){
    if (_.isObject(object)){
        _.each(object, function(value,key){
            compareDeep(value,matches,key);
        });
    }else{
        
        if (key === 'desc'){
            object = "_IGNORE_"; //ignore all desc string;
        }
        var actualKey = key;
        var actual = object;
        var match = matches.stack.shift();
        //echo(actualKey,actual,matches,match);
        if (match === undefined){
            if (object) {
                echo('WARNING: no more match in your testbed, but comparion not finished, untested {',key,":",object,"}");
            }
            return //no more match , exit;
        }
        var expect = match.expect;
        var expectKey = match.key;
        try {
            assert.strictEqual(actualKey,expectKey);
            assert.strictEqual(actual,expect);
            echo("Tested [ "+key+" ] == '"+expect+"'","OK!");
        }catch(e){
            echo("Tested [ "+key+" ] == '"+expect+"'","FAIL!");
            echo("[ actual ] =",actual);
            echo("[ match  ] =",match);
            echo(e.stack)

        }

    }
}

function jsonHttpTest(payload){
    var reqBody = {
        method: payload.method||'GET',
        uri: payload.uri
{'fraction_non_alphanumeric': 0.12462612163509472, 'fraction_numerical': 0.00022155754957350172, 'mean_word_length': 0.9630354424874973, 'pattern_counts': {'":': 1, '<': 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': '1395568', 'n_tokens_mistral': 2312, 'n_tokens_neox': 2130, 'n_words': 391}