<commit_before>import test from 'ava';
import Validator from './../src/validator';

const validator = new Validator({
    email: 'email',
    required: 'required',
    min: 'min:3',
    max: 'max:10',
    in: 'in:1,2,3,5',
    not_in: 'not_in:1,2,3,5',
    alpha: 'alpha',
    alpha_dash: 'alpha_dash',
    alpha_num: 'alpha_num',
    numeric: 'numeric'
});

test('it validates alpha', t => {
    t.true(validator.validate('alpha', 'abcdefgHijklMnOpqRsTUVwxYZ abc'));
    t.false(validator.validate('alpha', 'abcdefgHijklMnOpqRsTUVwxYZ abc1'));
    t.true(validator.validate('alpha', ''));
});

test('it validates alpha_num', t => {
    t.true(validator.validate('alpha_num', 'abcdefgHijklMnOpqRsTUVwxYZ abc 123'));
    t.true(validator.validate('alpha_num', ''));
    t.false(validator.validate('alpha_num', 'abcdefgHijklMnOpqRsTUVwxYZ -'));
});

test('it validates alpha_dash', t => {
    t.true(validator.validate('alpha_dash', 'abcdefgHijklMnOpqRsTUVwxYZ abc 123 _-'));
    t.true(validator.validate('alpha_dash', 'abcdefgHijklMnOpqRsTUVwxYZ abc'));
    t.true(validator.validate('alpha_dash', ''));
    t.false(validator.validate('alpha_dash', 'abcdefgHijklMnOpqRsTUVwxYZ @'));
});

test('it validates numeric', t => {
    t.true(validator.validate('numeric', '1234567890'));
    t.false(validator.validate('numeric', '123abc'));
    t.true(validator.validate('numeric', ''));
});

test('it validates emails', t => {
    t.true(validator.validate('email', '<EMAIL>'));
    t.false(validator.validate('email', '<EMAIL>'));
});

test('it validates min', t => {
    t.true(validator.validate('min', 'wow'));
    t.false(validator.validate('min', 'wo'));
});

test('it validates max', t => {
    t.true(validator.validate('max', 'not long'));
    t.false(validator.validate('max', 'this is some very long text'));
});

test('it validates required', t => {
    t.true(validator.validate('required', 'asjdj'));
    t.true(validator.validate('required', 0));
    t.false(validator.validate('required', ''));
    t.false(validator.validate('required', []));
});

test('it validates in', t => {
    t.true(validator.validate('in', 1));
    t.true(validator.validate('in', 2));
    t.true(validator.validate('in', 3));
    t.true(validator.validate('in', 5));
    t.false(validator.validate('in', 4));
});

test('it validates not_in', t => {
    t.false(validator.validate('not_in', 1));
    t.false(validator.validate('not_in', 2));
    t.false(validator.validate('not_in', 3));
    t.false(validator.validate('not_in', 5));
    t.true(validator.validate('not_in', 4));
});<commit_msg>add test for regex validation<commit_after>import test from 'ava';
import Validator from './../src/validator';

const validator = new Validator({
    email: 'email',
    required: 'required',
    min: 'min:3',
    max: 'max:10',
    in: 'in:1,2,3,5',
    not_in: 'not_in:1,2,3,5',
    alpha: 'alpha',
    alpha_dash: 'alpha_dash',
    alpha_num: 'alpha_num',
    numeric: 'numeric',
    regex: 'regex:[0-9]+',
    regex2: 'regex:[a-z]+,i'
});

test('it validates alpha', t => {
    t.true(validator.validate('alpha', 'abcdefgHijklMnOpqRsTUVwxYZ abc'));
    t.false(validator.validate('alpha', 'abcdefgHijklMnOpqRsTUVwxYZ abc1'));
    t.true(validator.validate('alpha', ''));
});

test('it validates alpha_num', t => {
    t.true(validator.validate('alpha_num', 'abcdefgHijklMnOpqRsTUVwxYZ abc 123'));
    t.true(validator.validate('alpha_num', ''));
    t.false(validator.validate('alpha_num', 'abcdefgHijklMnOpqRsTUVwxYZ -'));
});

test('it validates alpha_dash', t => {
    t.true(validator.validate('alpha_dash', 'abcdefgHijklMnOpqRsTUVwxYZ abc 123 _-'));
    t.true(validator.validate('alpha_dash', 'abcdefgHijklMnOpqRsTUVwxYZ abc'));
    t.true(validator.validate('alpha_dash', ''));
    t.false(validator.validate('alpha_dash', 'abcdefgHijklMnOpqRsTUVwxYZ @'));
});

test('it validates numeric', t => {
    t.true(validator.validate('numeric', '1234567890'));
    t.false(validator.validate('numeric', '123abc'));
    t.true(validator.validate('numeric', ''));
});

test('it validates emails', t => {
    t.true(validator.validate('email', '<EMAIL>'));
    t.false(validator.validate('email', '<EMAIL>'));
});

test('it validates min', t => {
    t.true(validator.validate('min', 'wow'));
    t.false(validator.validate('min', 'wo'));
});

test('it validates max', t => {
    t.true(validator.validate('max', 'not long'));
    t.false(validator.validate('max', 'this is some very long text'));
});

test('it validates required', t => {
    t.true(validator.validate('required', 'asjdj'));
    t.true(validator.validate('required', 0));
    t.false(validator.validate('required', ''));
    t.false(validator.validate('required', []));
});

test('it validates in', t => {
    t.true(validator.validate('in', 1));
    t.true(validator.validate('in', 2));
    t.true(validator.validate('in', 3));
    t.true(validator.validate('in', 5));
    t.false(validator.validate('in', 4));
});

test('it validates not_in', t => {
    t.false(validator.validate('not_in', 1));
    t.false(validator.validate('not_in', 2));
    t.false(validator.validate('not_in', 3));
    t.false(validator.validate('not_in', 5));
    t.true(validator.validate('not_in', 4));
});


// TODO: A regex expression with a pipe '|' or a comma ',' will get shat on.
// fix this by supporting array syntax.
test('it validates regular expressions', t => {
    t.true(validator.validate('regex', '213213123123'));
    t.true(validator.validate('regex', 'ad1231231231'));
    t.false(validator.validate('regex', 'ads'));
    t.true(validator.validate('regex2', 'ABC'));
});
{'fraction_non_alphanumeric': 0.2121751512993948, 'fraction_numerical': 0.019579921680313278, 'mean_word_length': 4.763076923076923, 'pattern_counts': {'":': 0, '<': 7, '<?xml version=': 0, '>': 28, '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': '1622294', 'n_tokens_mistral': 2079, 'n_tokens_neox': 2056, 'n_words': 331}