<commit_before>'use strict';

const QueryHash = require('../query-hash');
const expect = require('chai').expect;

describe('QueryHash Constructor', function () {
    it('Should construct without throwing an exception', function () {
        let hasError = false;
        let q;
        try {
            q = new QueryHash();
        }
        catch (ex) {
            hasError = true;
        }

        expect(q).to.be.an.instanceof(QueryHash);
        expect(hasError).to.equal(false);
    });
});

describe('QueryHash.add method', function () {
    let q = new QueryHash();

    it('Should add two key-values to the query hash', function () {
        q.add('first', 'passed');
        q.add('second', 'also-passed');

        expect(q.keys()).to.have.lengthOf(2);
    });

    it('Should throw an expection if 0 parameters are given', function () {
        expect(q.add.bind(q)).to.throw('QueryHash.add expects 2 parameters, 0 given');
    });

    it('Should throw an expection if 1 parameter is given', function () {
        expect(q.add.bind(q, 'test')).to.throw('QueryHash.add expects 2 parameters, 1 given');
    });

});

describe('QueryHash.remove method', function () {
    let q = new QueryHash();
    q.add('remove', 'me');

    it('Should remove a key-value by its key', function () {
        q.remove('remove');

        expect(q.keys()).to.have.lengthOf(0);
    });

    it('Should throw an expection if 0 parameters are given', function () {
        expect(q.remove.bind(q)).to.throw('QueryHash.remove expects one parameter, 0 given');
    });
});

describe('QueryHash.find method', function () {
    let q = new QueryHash(); 
    q.add('first', 'passed');
    q.add('second', 'also-passed');

    it('Should find a value by its key', function () {
        expect(q.find('first')).to.equal('passed');
    });

    it('Should throw an expection if 0 parameters are given', function () {
        expect(q.find.bind(q)).to.throw('QueryHash.find expects one parameter, 0 given');
    });
});

describe('QueryHash.keys method', function () {
    let q = new QueryHash();
    q.fromQueryString('test=passed&again=hooray');

    it('Should return an array of query string keys', function () {
        expect(q.keys()).to.have.lengthOf(2);
        expect(q.keys()).to.deep.equal(['test', 'again']);
    });
});

describe('QueryHash.toString method', function () {
    let q = new QueryHash();
    q.add('test', 'passed');
    q.add('again', 'hooray');

    it('Should create a query string from added key-values', function () {
        expect(q.toString()).to.equal('test=passed&again=hooray');
    });
});

describe('QueryHash.fromQueryString method', function () {
    let q = new QueryHash();
    it('Should accept a query string and modify it', function () {
        q.fromQueryString('test=passed&again=hooray');

        expect(q.keys()).to.deep.equal(['test', 'again']);
    });<commit_msg>more accurate test description<commit_after>'use strict';

const QueryHash = require('../query-hash');
const expect = require('chai').expect;

describe('QueryHash Constructor', function () {
    it('Should construct without throwing an exception', function () {
        let hasError = false;
        let q;
        try {
            q = new QueryHash();
        }
        catch (ex) {
            hasError = true;
        }

        expect(q).to.be.an.instanceof(QueryHash);
        expect(hasError).to.equal(false);
    });
});

describe('QueryHash.add method', function () {
    let q = new QueryHash();

    it('Should add two key-values to the query hash', function () {
        q.add('first', 'passed');
        q.add('second', 'also-passed');

        expect(q.keys()).to.have.lengthOf(2);
    });

    it('Should throw an expection if 0 parameters are given', function () {
        expect(q.add.bind(q)).to.throw('QueryHash.add expects 2 parameters, 0 given');
    });

    it('Should throw an expection if 1 parameter is given', function () {
        expect(q.add.bind(q, 'test')).to.throw('QueryHash.add expects 2 parameters, 1 given');
    });

});

describe('QueryHash.remove method', function () {
    let q = new QueryHash();
    q.add('remove', 'me');

    it('Should remove a key-value by its key', function () {
        q.remove('remove');

        expect(q.keys()).to.have.lengthOf(0);
    });

    it('Should throw an expection if 0 parameters are given', function () {
        expect(q.remove.bind(q)).to.throw('QueryHash.remove expects one parameter, 0 given');
    });
});

describe('QueryHash.find method', function () {
    let q = new QueryHash(); 
    q.add('first', 'passed');
    q.add('second', 'also-passed');

    it('Should find a value by its key', function () {
        expect(q.find('first')).to.equal('passed');
    });

    it('Should throw an expection if 0 parameters are given', function () {
        expect(q.find.bind(q)).to.throw('QueryHash.find expects one parameter, 0 given');
    });
});

describe('QueryHash.keys method', function () {
    let q = new QueryHash();
    q.fromQueryString('test=passed&again=hooray');

    it('Should return an array of query string keys', function () {
        expect(q.keys()).to.have.lengthOf(2);
        expect(q.keys()).to.deep.equal(['test', 'again']);
    });
});

describe('QueryHash.toString method', function () {
    let q = new QueryHash();
    q.add('test', 'passed');
    q.add('again', 'hooray');

    it('Should create a query string from added key-values', function () {
        expect(q.toString()).to.equal('test=passed&again=hooray');
    });
});

describe('QueryHash.fromQueryString method', function () {
    let q = new QueryHash();
    it('Should accept a querystring correctly', function () {
        q.fromQueryString('test=passed&again=hooray');

        expect(q.keys()).to.deep.equal(['test', 'again']);
    });
{'fraction_non_alphanumeric': 0.17651098901098902, 'fraction_numerical': 0.004464285714285714, 'mean_word_length': 2.9869952087611225, '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': '1491997', 'n_tokens_mistral': 1791, 'n_tokens_neox': 1713, 'n_words': 436}