<commit_before>import $ from 'jquery';
import ParsleyValidator from '../../src/parsley/validator';
import ParsleyValidatorRegistry from '../../src/parsley/validator_registry';
import Parsley from '../../src/parsley';
import fr from '../../src/i18n/fr';

describe('ParsleyValidatorRegistry', () => {
  var validatorRegistry = Parsley._validatorRegistry;

  var expectValidation = function(value, name, requirements, extra = {}) {
    var validatorSpec = validatorRegistry.validators[name];
    var validator = new ParsleyValidator(validatorSpec);
    var argList = validator.parseRequirements(requirements, key => { return extra[key]; });
    return expect(validator.validate(value, ...argList));
  };

  afterEach(() => {
    Parsley.setLocale('en');
  });

  it('should be a function', () => {
    expect(ParsleyValidatorRegistry).to.be.a('function');
  });
  it('should bind global config validators if given in constructor', () => {
    $.extend(true, Parsley.options, {
      validators: {
        foo: {fn: () => {}, priority: 42},
        bar: {fn: () => {}, priority: 12}
      }
    });
    var validator = new ParsleyValidatorRegistry(Parsley.options.validators);
    expect(validator.validators).to.have.key('foo');
    expect(validator.validators).to.have.key('bar');
    expect(validatorRegistry.validators).not.to.have.key('foo');
    delete Parsley.options.validators.foo;
    delete Parsley.options.validators.bar;
  });
  it('should have a required validator', () => {
    expectValidation('', 'required').not.to.be(true);
    expectValidation('foo', 'required').to.be(true);<commit_msg>Respect the validator's interface by testing with instance parameter<commit_after>import $ from 'jquery';
import ParsleyValidator from '../../src/parsley/validator';
import ParsleyValidatorRegistry from '../../src/parsley/validator_registry';
import Parsley from '../../src/parsley';
import fr from '../../src/i18n/fr';

describe('ParsleyValidatorRegistry', () => {
  var validatorRegistry = Parsley._validatorRegistry;

  var expectValidation = function(value, name, requirements, extra = {}) {
    var validatorSpec = validatorRegistry.validators[name];
    var validator = new ParsleyValidator(validatorSpec);
    var argList = validator.parseRequirements(requirements, key => { return extra[key]; });
    let instance = null;
    return expect(validator.validate(value, ...argList, instance));
  };

  afterEach(() => {
    Parsley.setLocale('en');
  });

  it('should be a function', () => {
    expect(ParsleyValidatorRegistry).to.be.a('function');
  });
  it('should bind global config validators if given in constructor', () => {
    $.extend(true, Parsley.options, {
      validators: {
        foo: {fn: () => {}, priority: 42},
        bar: {fn: () => {}, priority: 12}
      }
    });
    var validator = new ParsleyValidatorRegistry(Parsley.options.validators);
    expect(validator.validators).to.have.key('foo');
    expect(validator.validators).to.have.key('bar');
    expect(validatorRegistry.validators).not.to.have.key('foo');
    delete Parsley.options.validators.foo;
    delete Parsley.options.validators.bar;
  });
  it('should have a required validator', () => {
    expectValidation('', 'required').not.to.be(true);
    expectValidation('foo', 'required').to.be(true);
{'fraction_non_alphanumeric': 0.16808252427184467, 'fraction_numerical': 0.0036407766990291263, 'mean_word_length': 4.041284403669724, 'pattern_counts': {'":': 0, '<': 3, '<?xml version=': 0, '>': 19, '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': '7198177', 'n_tokens_mistral': 956, 'n_tokens_neox': 960, 'n_words': 195}