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

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

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

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

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

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

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

    describe("#startWith requires that the passed pattern occur exactly at the beginning of the input", function() {
        beforeEach(function() {
            regularity.startWith('a');
        });

        it("matches in the positive case", function() {
            expect(regularity.done().test('abcde')).toBe(true);
        });

        it("does not match in the negative case", function() {
            expect(regularity.done().test('edcba')).toBe(false);
        });

        it("can only be called once", function() {
            expect(function() {
                regularity.startWith('b');
            }).toThrow(errors.MethodCalledMultipleTimes('startWith'));
        });
    });

    describe("#startWith -- checks against literal regexp", function() {
        var regexp;

        describe("unnumbered", function() {
            it("single character", function() {
                regexp = regularity.startWith('a').done();
                expect(regexp).toEqual(/^a/);
            });

            it("multiple characters", function() {
                regexp = regularity.startWith('abc').done();
                expect(regexp).toEqual(/^abc/);
            });
        });

        describe("numbered", function() {
            it("special identifiers", function() {
                regexp = regularity.startWith(4, 'digits').done();
                expect(regexp).toEqual(/^(?:[0-9]){4}/);
            });

            it("one occurrence of one character", function() {
                regexp = regularity.startWith(1, 'p').done();
                expect(regexp).toEqual(/^p/);
            });

            it("more than one occurence of one character", function() {
                regexp = regularity.startWith(6, 'p').done();
                expect(regexp).toEqual(/^(?:p){6}/);
            });

            it("one occurence of several characters", function() {
                regexp = regularity.startWith(1, 'hey').done();
                expect(regexp).toEqual(/^hey/);
            });

            xit("more than one occurence of several characters", function() {
                regexp = regularity.startWith(5, 'hey').done();
                expect(regexp).toEqual(/^(?:hey){5}/);
            });
        });
    });

    describe("#endWith requires that the passed pattern occur exactly at the end of the input", function() {
        beforeEach(function() {
            regularity.endWith('a');
        });

        it("matches in the positive case", function() {
            expect(regularity.done().test('edcba')).toBe(true);
        });

        it("does not match in the negative case", function() {
            expect(regularity.done().test('abcde')).toBe(false);
        });

        it("can only be called once", function() {
            expect(function() {
                regularity.endWith('z');
            }).toThrow(errors.MethodCalledMultipleTimes('endWith'));
        });
    });

    describe("#endWith -- checks against literal regexp", function() {
        var regexp;

        describe("unnumbered", function() {
            it("single character", function() {
                regexp = regularity.endWith('a').done();
                expect(regexp).toEqual(/a$/);
            });

            it("multiple characters", function() {
                regexp = regularity.endWith('abc').done();
                expect(regexp).toEqual(/abc$/);
            });
        });

        describe("numbered", function() {
            it("numbered special identifier", function() {
                regexp = regularity.endWith(4, 'alphanumeric').done();
                expect(regexp).toEqual(/(?:[A-Za-z0-9]){4}$/);
            });

            it("one occurrence of one character", function() {
                regexp = regularity.endWith(1, 'p').done();
                expect(regexp).toEqual(/p$/);
            });

            it("more than one occurence of one character", function() {
                regexp = regularity.endWith(6, 'p').done();
                expect(regexp).toEqual(/(?:p){6}$/);
            });

            it("one occurence of several characters", function() {
                regexp = regularity.endWith(1, 'hey').done();
                expect(regexp).toEqual(/hey$/);
            });

            xit("more than one occurence of several characters", function() {
                regexp = regularity.endWith(5, 'hey').done();
                expect(regexp).toEqual(/(?:hey){5}$/);
            });
        });
    });

    describe("#maybe requires that the passed pattern occur either one or zero times", function() {<commit_msg>Enable the two specs which were pending.<commit_after>var Regularity = require('../lib/regularity.js');
var errors = require('../lib/errors');

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

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

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

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

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

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

    describe("#startWith requires that the passed pattern occur exactly at the beginning of the input", function() {
        beforeEach(function() {
            regularity.startWith('a');
        });

        it("matches in the positive case", function() {
            expect(regularity.done().test('abcde')).toBe(true);
        });

        it("does not match in the negative case", function() {
            expect(regularity.done().test('edcba')).toBe(false);
        });

        it("can only be called once", function() {
            expect(function() {
                regularity.startWith('b');
            }).toThrow(errors.MethodCalledMultipleTimes('startWith'));
        });
    });

    describe("#startWith -- checks against literal regexp", function() {
        var regexp;

        describe("unnumbered", function() {
            it("single character", function() {
                regexp = regularity.startWith('a').done();
                expect(regexp).toEqual(/^a/);
            });

            it("multiple characters", function() {
                regexp = regularity.startWith('abc').done();
                expect(regexp).toEqual(/^abc/);
            });
        });

        describe("numbered", function() {
            it("special identifiers", function() {
                regexp = regularity.startWith(4, 'digits').done();
                expect(regexp).toEqual(/^(?:[0-9]){4}/);
            });

            it("one occurrence of one character", function() {
                regexp = regularity.startWith(1, 'p').done();
                expect(regexp).toEqual(/^p/);
            });

            it("more than one occurence of one character", function() {
                regexp = regularity.startWith(6, 'p').done();
                expect(regexp).toEqual(/^(?:p){6}/);
            });

            it("one occurence of several characters", function() {
                regexp = regularity.startWith(1, 'hey').done();
                expect(regexp).toEqual(/^hey/);
            });

            it("more than one occurence of several characters", function() {
                regexp = regularity.startWith(5, 'hey').done();
                expect(regexp).toEqual(/^(?:hey){5}/);
            });
        });
    });

    describe("#endWith requires that the passed pattern occur exactly at the end of the input", function() {
        beforeEach(function() {
            regularity.endWith('a');
        });

        it("matches in the positive case", function() {
            expect(regularity.done().test('edcba')).toBe(true);
        });

        it("does not match in the negative case", function() {
            expect(regularity.done().test('abcde')).toBe(false);
        });

        it("can only be called once", function() {
            expect(function() {
                regularity.endWith('z');
            }).toThrow(errors.MethodCalledMultipleTimes('endWith'));
        });
    });

    describe("#endWith -- checks against literal regexp", function() {
        var regexp;

        describe("unnumbered", function() {
            it("single character", function() {
                regexp = regularity.endWith('a').done();
                expect(regexp).toEqual(/a$/);
            });

            it("multiple characters", function() {
                regexp = regularity.endWith('abc').done();
                expect(regexp).toEqual(/abc$/);
            });
        });

        describe("numbered", function() {
            it("numbered special identifier", function() {
                regexp = regularity.endWith(4, 'alphanumeric').done();
                expect(regexp).toEqual(/(?:[A-Za-z0-9]){4}$/);
            });

            it("one occurrence of one character", function() {
                regexp = regularity.endWith(1, 'p').done();
                expect(regexp).toEqual(/p$/);
            });

            it("more than one occurence of one character", function() {
                regexp = regularity.endWith(6, 'p').done();
                expect(regexp).toEqual(/(?:p){6}$/);
            });

            it("one occurence of several characters", function() {
                regexp = regularity.endWith(1, 'hey').done();
                expect(regexp).toEqual(/hey$/);
            });

            it("more than one occurence of several characters", function() {
                regexp = regularity.endWith(5, 'hey').done();
                expect(regexp).toEqual(/(?:hey){5}$/);
            });
        });
    });

    describe("#maybe requires that the passed pattern occur either one or zero times", function() {
{'fraction_non_alphanumeric': 0.16560223081766665, 'fraction_numerical': 0.003598093010704327, 'mean_word_length': 1.868421052631579, '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': 8, 'profanity_word_list.json': 0, 'sexual_word_list.json': 0, 'zh_pornsignals.json': 0}}
{'dir': 'git-commits-cleaned', 'id': '626500', 'n_tokens_mistral': 2954, 'n_tokens_neox': 2774, 'n_words': 582}