<commit_before>const objectPath = require('object-path');
const promiseTools = require('./tools/promise');

class Validator {
    constructor(statements, messages) {
        // TODO validate rules is array
        // TODO validate all elements in rules are valid rules
        this.statements = statements;
        this.messages = messages;
    }

    test(values) {
        return promiseTools
            .series(this.statements, statement => {
                const value = objectPath.get(values, statement._getField().getName());
                // TODO array support
                return statement._invoke(value, values);
            })
            .then(fieldRuleErrorGroups => {
                return fieldRuleErrorGroups.reduce((a, b) => a.concat(b));<commit_msg>make messages array optional<commit_after>const objectPath = require('object-path');
const promiseTools = require('./tools/promise');

class Validator {
    constructor(statements, messages) {
        messages = typeof messages !== 'undefined' ? messages : [];
        this.statements = statements;
        this.messages = messages;
    }

    test(values) {
        return promiseTools
            .series(this.statements, statement => {
                const value = objectPath.get(values, statement._getField().getName());
                // TODO array support
                return statement._invoke(value, values);
            })
            .then(fieldRuleErrorGroups => {
                return fieldRuleErrorGroups.reduce((a, b) => a.concat(b));
{'fraction_non_alphanumeric': 0.11321989528795812, 'fraction_numerical': 0.0, 'mean_word_length': 2.281115879828326, 'pattern_counts': {'":': 0, '<': 3, '<?xml version=': 0, '>': 9, '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': '3551672', 'n_tokens_mistral': 372, 'n_tokens_neox': 355, 'n_words': 89}