<commit_before>import {expect} from 'chai';
import {
    parser1,
    parser2,
    charParser,
    andThen,
    orElse,
    choice,
    alternativeParsers,
} from 'parsers';
import {
    isPair,
    isSuccess,
    isFailure,
    isParser,
} from 'util';

let lowercases = ['a', 'b', 'c', 'd', 'e', 'f', 'g', 'h', 'i', 'j', 'k', 'l', 'm', 'n', 'o', 'p', 'q', 'r', 's', 't', 'u', 'v', 'w', 'x', 'y', 'z',];
let uppercases = ['A', 'B', 'C', 'D', 'E', 'F', 'G', 'H', 'I', 'J', 'K', 'L', 'M', 'N', 'O', 'P', 'Q', 'R', 'S', 'T', 'U', 'V', 'W', 'X', 'Y', 'Z',];
let digits = [0, 1, 2, 3, 4, 5, 6, 7, 8, 9];

describe('a parsers for a choice of chars', () => {

    it('can parse any lowercase char', () => {
        let lowercasesParser = alternativeParsers(lowercases);

        expect(isParser(lowercasesParser)).to.be.true;
        let parsingChoice = lowercasesParser.run('a');
        expect(isSuccess(parsingChoice)).to.be.true;
        expect(parsingChoice.first()).to.be.eql('a');
        expect(parsingChoice.second()).to.be.eql('');
        parsingChoice = lowercasesParser.run('b');
        expect(isSuccess(parsingChoice)).to.be.true;
        expect(parsingChoice.first()).to.be.eql('b');
        expect(parsingChoice.second()).to.be.eql('');
        parsingChoice = lowercasesParser.run('d');
        expect(isSuccess(parsingChoice)).to.be.true;
        expect(parsingChoice.first()).to.be.eql('d');
        expect(parsingChoice.second()).to.be.eql('');
        parsingChoice = lowercasesParser.run('z');
        expect(isSuccess(parsingChoice)).to.be.true;
        expect(parsingChoice.first()).to.be.eql('z');
        expect(parsingChoice.second()).to.be.eql('');

        parsingChoice = lowercasesParser.run('Y');
        expect(isFailure(parsingChoice)).to.be.true;
        expect(parsingChoice.first()).to.be.eql('parsing failed');
        expect(parsingChoice.second()).to.be.eql('Y');
    });

    it('can parse any uppercase char', () => {
        let uppercasesParser = alternativeParsers(uppercases);

        expect(isParser(uppercasesParser)).to.be.true;
        let parsingChoice = uppercasesParser.run('A');
        expect(isSuccess(parsingChoice)).to.be.true;
        expect(parsingChoice.first()).to.be.eql('A');
        expect(parsingChoice.second()).to.be.eql('');
        parsingChoice = uppercasesParser.run('B');
        expect(isSuccess(parsingChoice)).to.be.true;
        expect(parsingChoice.first()).to.be.eql('B');
        expect(parsingChoice.second()).to.be.eql('');
        parsingChoice = uppercasesParser.run('R');
        expect(isSuccess(parsingChoice)).to.be.true;
        expect(parsingChoice.first()).to.be.eql('R');
        expect(parsingChoice.second()).to.be.eql('');
        parsingChoice = uppercasesParser.run('Z');
        expect(isSuccess(parsingChoice)).to.be.true;
        expect(parsingChoice.first()).to.be.eql('Z');
        expect(parsingChoice.second()).to.be.eql('');

        parsingChoice = uppercasesParser.run('s');
        expect(isFailure(parsingChoice)).to.be.true;
        expect(parsingChoice.first()).to.be.eql('parsing failed');
        expect(parsingChoice.second()).to.be.eql('s');
    });
});

describe('a choice of parsers bound by orElse', () => {
    let parsersChoice;

    beforeEach(() => {
        parsersChoice = choice([charParser('a'), charParser('b'), charParser('c'), charParser('d'),]);
    });

    it('can parse one of four chars', () => {
        expect(isParser(parsersChoice)).to.be.true;
        let parsingChoice = parsersChoice.run('a');
        expect(isSuccess(parsingChoice)).to.be.true;
        expect(parsingChoice.first()).to.be.eql('a');
        expect(parsingChoice.second()).to.be.eql('');
        parsingChoice = parsersChoice.run('b');
        expect(isSuccess(parsingChoice)).to.be.true;
        expect(parsingChoice.first()).to.be.eql('b');
        expect(parsingChoice.second()).to.be.eql('');
        parsingChoice = parsersChoice.run('d');
        expect(isSuccess(parsingChoice)).to.be.true;
        expect(parsingChoice.first()).to.be.eql('d');
        expect(parsingChoice.second()).to.be.eql('');
    });<commit_msg>understood and implemented digits parser<commit_after>import {expect} from 'chai';
import {
    parser1,
    parser2,
    charParser,
    andThen,
    orElse,
    choice,
    alternativeParsers,
} from 'parsers';
import {
    isPair,
    isSuccess,
    isFailure,
    isParser,
} from 'util';

let lowercases = ['a', 'b', 'c', 'd', 'e', 'f', 'g', 'h', 'i', 'j', 'k', 'l', 'm', 'n', 'o', 'p', 'q', 'r', 's', 't', 'u', 'v', 'w', 'x', 'y', 'z',];
let uppercases = ['A', 'B', 'C', 'D', 'E', 'F', 'G', 'H', 'I', 'J', 'K', 'L', 'M', 'N', 'O', 'P', 'Q', 'R', 'S', 'T', 'U', 'V', 'W', 'X', 'Y', 'Z',];
let digits = ['0', '1', '2', '3', '4', '5', '6', '7', '8', '9'];

describe('a parsers for a choice of chars', () => {

    it('can parse any lowercase char', () => {
        let lowercasesParser = alternativeParsers(lowercases);

        expect(isParser(lowercasesParser)).to.be.true;
        let parsingChoice = lowercasesParser.run('a');
        expect(isSuccess(parsingChoice)).to.be.true;
        expect(parsingChoice.first()).to.be.eql('a');
        expect(parsingChoice.second()).to.be.eql('');
        parsingChoice = lowercasesParser.run('b');
        expect(isSuccess(parsingChoice)).to.be.true;
        expect(parsingChoice.first()).to.be.eql('b');
        expect(parsingChoice.second()).to.be.eql('');
        parsingChoice = lowercasesParser.run('d');
        expect(isSuccess(parsingChoice)).to.be.true;
        expect(parsingChoice.first()).to.be.eql('d');
        expect(parsingChoice.second()).to.be.eql('');
        parsingChoice = lowercasesParser.run('z');
        expect(isSuccess(parsingChoice)).to.be.true;
        expect(parsingChoice.first()).to.be.eql('z');
        expect(parsingChoice.second()).to.be.eql('');

        parsingChoice = lowercasesParser.run('Y');
        expect(isFailure(parsingChoice)).to.be.true;
        expect(parsingChoice.first()).to.be.eql('parsing failed');
        expect(parsingChoice.second()).to.be.eql('Y');
    });

    it('can parse any uppercase char', () => {
        let uppercasesParser = alternativeParsers(uppercases);

        expect(isParser(uppercasesParser)).to.be.true;
        let parsingChoice = uppercasesParser.run('A');
        expect(isSuccess(parsingChoice)).to.be.true;
        expect(parsingChoice.first()).to.be.eql('A');
        expect(parsingChoice.second()).to.be.eql('');
        parsingChoice = uppercasesParser.run('B');
        expect(isSuccess(parsingChoice)).to.be.true;
        expect(parsingChoice.first()).to.be.eql('B');
        expect(parsingChoice.second()).to.be.eql('');
        parsingChoice = uppercasesParser.run('R');
        expect(isSuccess(parsingChoice)).to.be.true;
        expect(parsingChoice.first()).to.be.eql('R');
        expect(parsingChoice.second()).to.be.eql('');
        parsingChoice = uppercasesParser.run('Z');
        expect(isSuccess(parsingChoice)).to.be.true;
        expect(parsingChoice.first()).to.be.eql('Z');
        expect(parsingChoice.second()).to.be.eql('');

        parsingChoice = uppercasesParser.run('s');
        expect(isFailure(parsingChoice)).to.be.true;
        expect(parsingChoice.first()).to.be.eql('parsing failed');
        expect(parsingChoice.second()).to.be.eql('s');
    });

    it('can parse any digit', () => {
        let digitsParser = alternativeParsers(digits);

        expect(isParser(digitsParser)).to.be.true;
        let parsingChoice = digitsParser.run('1');
        expect(isSuccess(parsingChoice)).to.be.true;
        expect(parsingChoice.first()).to.be.eql('1');
        expect(parsingChoice.second()).to.be.eql('');
        parsingChoice = digitsParser.run('3');
        expect(isSuccess(parsingChoice)).to.be.true;
        expect(parsingChoice.first()).to.be.eql('3');
        expect(parsingChoice.second()).to.be.eql('');
        parsingChoice = digitsParser.run('0');
        expect(isSuccess(parsingChoice)).to.be.true;
        expect(parsingChoice.first()).to.be.eql('0');
        expect(parsingChoice.second()).to.be.eql('');
        parsingChoice = digitsParser.run('8');
        expect(isSuccess(parsingChoice)).to.be.true;
        expect(parsingChoice.first()).to.be.eql('8');
        expect(parsingChoice.second()).to.be.eql('');

        parsingChoice = digitsParser.run('s');
        expect(isFailure(parsingChoice)).to.be.true;
        expect(parsingChoice.first()).to.be.eql('parsing failed');
        expect(parsingChoice.second()).to.be.eql('s');
    });
});

describe('a choice of parsers bound by orElse', () => {
    let parsersChoice;

    beforeEach(() => {
        parsersChoice = choice([charParser('a'), charParser('b'), charParser('c'), charParser('d'),]);
    });

    it('can parse one of four chars', () => {
        expect(isParser(parsersChoice)).to.be.true;
        let parsingChoice = parsersChoice.run('a');
        expect(isSuccess(parsingChoice)).to.be.true;
        expect(parsingChoice.first()).to.be.eql('a');
        expect(parsingChoice.second()).to.be.eql('');
        parsingChoice = parsersChoice.run('b');
        expect(isSuccess(parsingChoice)).to.be.true;
        expect(parsingChoice.first()).to.be.eql('b');
        expect(parsingChoice.second()).to.be.eql('');
        parsingChoice = parsersChoice.run('d');
        expect(isSuccess(parsingChoice)).to.be.true;
        expect(parsingChoice.first()).to.be.eql('d');
        expect(parsingChoice.second()).to.be.eql('');
    });
{'fraction_non_alphanumeric': 0.2077117041395251, 'fraction_numerical': 0.0033620508510191216, 'mean_word_length': 3.2495535714285713, 'pattern_counts': {'":': 0, '<': 3, '<?xml version=': 0, '>': 16, 'https://': 0, 'lorem ipsum': 0, 'www.': 0, 'xml': 0}, 'pii_count': 0, 'substrings_counts': 0, 'word_list_counts': {'cursed_substrings.json': 9, 'profanity_word_list.json': 0, 'sexual_word_list.json': 0, 'zh_pornsignals.json': 0}}
{'dir': 'git-commits-cleaned', 'id': '5264608', 'n_tokens_mistral': 3240, 'n_tokens_neox': 3193, 'n_words': 451}