<commit_before>
var Regularity = require('../lib/regularity.js');

describe("Regularity", function() {
    var regularity;

    beforeEach(function() {
        regularity = new Regularity();
    });

    it("is an object constructor", function() {
        expect(typeof regularity).toBe('object');
    });

    describe("return from done()", function() {
        it("is a RegExp instance", function() {
            expect(regularity.done() instanceof RegExp).toBe(true);
        });

        it ("returns an empty regexp by default", function() {
            expect(regularity.done()).toEqual(new RegExp());
        });
    });

    describe("escapes regexp special chars", function() {
        var chars = [ '*', '.', '?', '^', '+', '$', '|', '(', ')', '[', ']',
          '{', '}' ];

        function testEscapedChar(c) {
            it ("escapes '" + c + "'", function() {
                var regex = regularity.append( c ).done();
                expect(regex.source).toBe("\\" + c);
            });
        }
        for(var i = 0; i < chars.length; i++ ) { testEscapedChar(chars[i]); }
    });

    describe("#startsWith", function(){
        it("matches positive", function(){
            var regex = regularity.startWith('a').done();
            expect(regex.test('abcde')).toBeTruthy();
        });

        it("matches negative", function(){
            var regex = regularity.startWith('a').done();
            expect(regex.test('edcba')).toBeFalsy();
        });
    });

    describe("#endWith", function(){
        it("matches positive", function(){
            var regex = regularity.endWith('a').done();
            expect(regex.test('edcba')).toBeTruthy();
        });

        it("matches negative", function(){
            var regex = regularity.endWith('a').done();
            expect(regex.test('abcde')).toBeFalsy();
        });
    });

    describe("#maybe", function(){
        it("matches with pattern", function(){
            var regex = regularity.maybe('a').done();<commit_msg>Rewrite 'escape' test using forEach.<commit_after>
var Regularity = require('../lib/regularity.js');

describe("Regularity", function() {
    var regularity;

    beforeEach(function() {
        regularity = new Regularity();
    });

    it("is an object constructor", function() {
        expect(typeof regularity).toBe('object');
    });

    describe("return from done()", function() {
        it("is a RegExp instance", function() {
            expect(regularity.done() instanceof RegExp).toBe(true);
        });

        it ("returns an empty regexp by default", function() {
            expect(regularity.done()).toEqual(new RegExp());
        });
    });

    describe("escapes regexp special characters", function() {
        var charactersToBeEscaped = [ '*', '.', '?', '^', '+',
        '$', '|', '(', ')', '[', ']', '{', '}' ];

        charactersToBeEscaped.forEach(function testEscapedChar(character) {
            it("escapes '" + character + "'", function() {
                var currentRegex = regularity.append(character).done();

                expect(currentRegex.source).toBe("\\" + character);
            });
        });
    });

    describe("#startsWith", function(){
        it("matches positive", function(){
            var regex = regularity.startWith('a').done();
            expect(regex.test('abcde')).toBeTruthy();
        });

        it("matches negative", function(){
            var regex = regularity.startWith('a').done();
            expect(regex.test('edcba')).toBeFalsy();
        });
    });

    describe("#endWith", function(){
        it("matches positive", function(){
            var regex = regularity.endWith('a').done();
            expect(regex.test('edcba')).toBeTruthy();
        });

        it("matches negative", function(){
            var regex = regularity.endWith('a').done();
            expect(regex.test('abcde')).toBeFalsy();
        });
    });

    describe("#maybe", function(){
        it("matches with pattern", function(){
            var regex = regularity.maybe('a').done();
{'fraction_non_alphanumeric': 0.19255424063116372, 'fraction_numerical': 0.0002465483234714004, 'mean_word_length': 2.3254098360655737, 'pattern_counts': {'":': 0, '<': 4, '<?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': 2, 'profanity_word_list.json': 0, 'sexual_word_list.json': 0, 'zh_pornsignals.json': 0}}
{'dir': 'git-commits-cleaned', 'id': '2230425', 'n_tokens_mistral': 1131, 'n_tokens_neox': 1078, 'n_words': 211}