<commit_before>var _ = require('lodash'),
    assert = require('assert'),
    Validator = require('../lib/Validator');

describe('Validator', function() {
  var validator;

  beforeEach(function() {
    validator = new Validator();
    validator.loadFromJSON(require('../lang/en/messages'));
  });

  describe('getPreset()', function() {
    it('should throw when try to get a non existent preset', function() {
      assert.throws(function() {
        validator.getPreset('p1');
      }, /Preset named "p1" is not defined/);
    });
  });

  describe('getPresets()', function() {
    var presets;

    beforeEach(function() {
      presets = {
        a: {
          rules: {}
        },
        b: {
          rules: {}
        },
        c: {
          rules: {}
        }
      };
    });
    
    it('should retrieve all the presets in the validator instance stores', function() {
      validator.setPreset(presets);<commit_msg>unit tests for setPreset() constructor function<commit_after>var _ = require('lodash'),
    assert = require('assert'),
    Validator = require('../lib/Validator');

describe('Validator', function() {
  var validator;

  beforeEach(function() {
    validator = new Validator();
    validator.loadFromJSON(require('../lang/en/messages'));
  });

  describe('constructor()', function() {
    describe('setPreset()', function() {
      var stores = Validator.defaults.stores,
          presets = stores.presets;

      afterEach(function() {
        _.forEach(presets, function(value, key) {
          delete presets[key];
        });
      });

      it('should define multiple presets on the global defaults variable', function() {
        Validator.setPreset({
          e: {
            rules: {}
          }
        });
        assert.deepEqual(presets, {
          e: {
            rules: {}
          }
        });
      });
    });
  });

  describe('getPreset()', function() {
    it('should throw when try to get a non existent preset', function() {
      assert.throws(function() {
        validator.getPreset('p1');
      }, /Preset named "p1" is not defined/);
    });
  });

  describe('getPresets()', function() {
    var presets;

    beforeEach(function() {
      presets = {
        a: {
          rules: {}
        },
        b: {
          rules: {}
        },
        c: {
          rules: {}
        }
      };
    });
    
    it('should retrieve all the presets in the validator instance stores', function() {
      validator.setPreset(presets);
{'fraction_non_alphanumeric': 0.15526210484193678, 'fraction_numerical': 0.001600640256102441, 'mean_word_length': 2.1055900621118013, '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': 0, 'profanity_word_list.json': 0, 'sexual_word_list.json': 0, 'zh_pornsignals.json': 0}}
{'dir': 'git-commits-cleaned', 'id': '3553654', 'n_tokens_mistral': 735, 'n_tokens_neox': 716, 'n_words': 155}