<commit_before>// test memcache:

var
    _ = require('lodash'),
    async = require('async'),
    should = require('should');

var cache = require('../cache');

var keyPrefix = require('<KEY>').v4().replace(/\-/g, '');

function toKeys(keys) {
    if (typeof(keys)==='string') {
        return keyPrefix + keys;
    }
    return _.map(keys, function(key) {
        return keyPrefix + key;
    });
}

describe('#cache', function() {

    it('#get', function(done) {
        var keys = toKeys(['aa', 'bb', 'cc']);
        async.series({
            aa: function(callback) {
                cache.get(keys[0], callback);
            },
            bb: function(callback) {
                cache.get(keys[1], callback);
            },
            cc: function(callback) {
                cache.get(keys[2], callback);
            }
        }, function(err, data) {
            should(err===null).be.true;
            should(data).be.ok;
            should(data.aa===null).be.true;
            should(data.bb===null).be.true;
            should(data.cc===null).be.true;
            done();
        });
    });

    it('#getByDefaultValue', function(done) {
        var key1 = keyPrefix + 'k1';
        cache.get(key1, 'DEFAULT-1', function(err, data) {
            should(err===null).be.true;
            should(data==='DEFAULT-1').be.true;
            // should not in cache:
            cache.get(key1, function(err, data2) {
                should(err===null).be.true;
                should(data2===null).be.true;
                done();
            });
        });
    });

    it('#getByFunctionValue', function(done) {
        var key1 = keyPrefix + 'f1';
        cache.get(key1, function() { return 'F1' }, function(err, data) {
            should(err===null).be.true;
            should(data==='F1').be.true;
            // should in cache:
            cache.get(key1, function(err, data2) {
                should(err===null).be.true;
                should(data2==='F1').be.true;
                done();
            });
        });
    });

    it('#setAndGet', function(done) {
        var key1 = keyPrefix + 'set1';
        cache.set(key1, 'Value1', function(err) {
            should(err===null).be.true;
            // get:
            cache.get(key1, function(err, data) {
                should(err===null).be.true;
                should(data==='Value1').be.true;
                done();
            });
        });
    });

    it('#gets', function(done) {
        var key1 = keyPrefix + 'multi-1';
        var key2 = keyPrefix + 'multi-2';
        var key3 = keyPrefix + 'multi-3';
        var keys = [key1, key2, key3];
        cache.gets(keys, function(err, data) {
            should(err===null).be.ok;
            data.should.be.instanceof(Array).and.have.lengthOf(3);
            should(data[0]===null).be.true;
            should(data[1]===null).be.true;
            should(data[2]===null).be.true;
            cache.set(key1, 'Multi', function(err) {
                should(err===null).be.true;
                // gets again:
                cache.gets(keys, function(err, data2) {
                    should(err===null).be.ok;
                    data2.should.be.instanceof(Array).and.have.lengthOf(3);
                    should(data2[0]==='Multi').be.true;
                    should(data2[1]===null).be.true;
                    should(data2[2]===null).be.true;
                    done();
                });
            });
        });
    });

    it('#setAndGetThenExpires', function(done) {
        var key1 = keyPrefix + 'exp1';
        cache.set(key1, 'Expires soon', 2, function(err) {
            should(err===null).be.true;
            // get:
            cache.get(key1, function(err, data) {
                should(err===null).be.true;
                should(data==='Expires soon').be.ok;
                setTimeout(function() {
                    cache.get(key1, function(err, data2) {
                        should(err===null).be.true;
                        should(data2===null).be.true;
                        done();
                    });
                }, 2100);
            });
        });
    });

    it('#incr', function(done) {
        var key1 = keyPrefix + 'inc1';
        cache.incr(key1, function(err, num) {
            should(err===null).be.true;
            should(num===1).be.true;<commit_msg>update testcase<commit_after>// test memcache:

var
    _ = require('lodash'),
    async = require('async'),
    should = require('should');

var cache = require('../cache');

var keyPrefix = require('<KEY>').v4().replace(/\-/g, '');

function toKeys(keys) {
    if (typeof(keys)==='string') {
        return keyPrefix + keys;
    }
    return _.map(keys, function(key) {
        return keyPrefix + key;
    });
}

describe('#cache', function() {

    it('#get', function(done) {
        var keys = toKeys(['aa', 'bb', 'cc']);
        async.series({
            aa: function(callback) {
                cache.get(keys[0], callback);
            },
            bb: function(callback) {
                cache.get(keys[1], callback);
            },
            cc: function(callback) {
                cache.get(keys[2], callback);
            }
        }, function(err, data) {
            should(err===null).be.true;
            should(data).be.ok;
            should(data.aa===null).be.true;
            should(data.bb===null).be.true;
            should(data.cc===null).be.true;
            done();
        });
    });

    it('#getByDefaultValue', function(done) {
        var key1 = keyPrefix + 'k1';
        cache.get(key1, 'DEFAULT-1', function(err, data) {
            should(err===null).be.true;
            should(data==='DEFAULT-1').be.true;
            // should not in cache:
            cache.get(key1, function(err, data2) {
                should(err===null).be.true;
                should(data2===null).be.true;
                done();
            });
        });
    });

    it('#getByFunctionValue', function(done) {
        var key1 = keyPrefix + 'f1';
        cache.get(key1, function() { return ['F1', null, {}] }, function(err, data) {
            should(err===null).be.true;
            data.should.be.instanceof(Array).and.have.lengthOf(3);
            data[0].should.equal('F1');
            should(data[1]===null).be.true;
            data[2].should.be.instanceof(Object);
            // should in cache:
            cache.get(key1, function(err, data2) {
                should(err===null).be.true;
                data2.should.be.instanceof(Array).and.have.lengthOf(3);
                data2[0].should.equal('F1');
                should(data2[1]===null).be.true;
                data2[2].should.be.instanceof(Object);
                done();
            });
        });
    });

    it('#setAndGet', function(done) {
        var key1 = keyPrefix + 'set1';
        cache.set(key1, 'Value1', function(err) {
            should(err===null).be.true;
            // get:
            cache.get(key1, function(err, data) {
                should(err===null).be.true;
                should(data==='Value1').be.true;
                done();
            });
        });
    });

    it('#gets', function(done) {
        var key1 = keyPrefix + 'multi-1';
        var key2 = keyPrefix + 'multi-2';
        var key3 = keyPrefix + 'multi-3';
        var keys = [key1, key2, key3];
        cache.gets(keys, function(err, data) {
            should(err===null).be.ok;
            data.should.be.instanceof(Array).and.have.lengthOf(3);
            should(data[0]===null).be.true;
            should(data[1]===null).be.true;
            should(data[2]===null).be.true;
            cache.set(key1, 'Multi', function(err) {
                should(err===null).be.true;
                // gets again:
                cache.gets(keys, function(err, data2) {
                    should(err===null).be.ok;
                    data2.should.be.instanceof(Array).and.have.lengthOf(3);
                    should(data2[0]==='Multi').be.true;
                    should(data2[1]===null).be.true;
                    should(data2[2]===null).be.true;
                    done();
                });
            });
        });
    });

    it('#setAndGetThenExpires', function(done) {
        var key1 = keyPrefix + 'exp1';
        cache.set(key1, { expires: 1234 }, 2, function(err) {
            should(err===null).be.true;
            // get:
            cache.get(key1, function(err, data) {
                should(err===null).be.true;
                data.should.be.ok;
                data.expires.should.equal(1234);
                setTimeout(function() {
                    cache.get(key1, function(err, data2) {
                        should(err===null).be.true;
                        should(data2===null).be.true;
                        done();
                    });
                }, 2100);
            });
        });
    });

    it('#incr', function(done) {
        var key1 = keyPrefix + 'inc1';
        cache.incr(key1, function(err, num) {
            should(err===null).be.true;
            should(num===1).be.true;
{'fraction_non_alphanumeric': 0.17529398835036816, 'fraction_numerical': 0.016595230245081877, 'mean_word_length': 1.5263742365352582, 'pattern_counts': {'":': 0, '<': 5, '<?xml version=': 0, '>': 5, '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': '7014442', 'n_tokens_mistral': 2798, 'n_tokens_neox': 2695, 'n_words': 407}