<commit_before>'use strict';

const expect = require('chai').expect;
const Helper = require('./helpers');
const ObjectType = require('../lib/types/object');
const ArrayType = require('../lib/types/array');
const StringType = require('../lib/types/string');

describe('ObjectType', function() {
  let schema;

  beforeEach(function() {
    schema = (new ObjectType()).isObject;
  });

  // describe('isObject()', function() {
  //   it('should validate valid values', function() {
  //     Helper.validate(schema, [
  //       [null, false],
  //       [0, false],
  //       ['', false],
  //       [NaN, false],
  //       [[], true],
  //       [new Object(), true],
  //       [{}, true]
  //     ], { convert: false });
  //   });
  // });
  //
  // describe('rename()', function() {
  //   it('should rename old key to new key', function() {
  //     Helper.validate(schema.rename('name', 'nickname'), [
  //       [{ name: '<NAME>' }, { nickname: '<NAME>' }]
  //     ], { convert: false });
  //   });
  //
  //   it('should rename according to renames', function() {
  //     Helper.validate(schema.rename({
  //       name: 'nickname',
  //       sex: 'gender'
  //     }), [
  //       [{ name: '<NAME>', sex: 'male' }, { nickname: '<NAME>', gender: 'male' }]
  //     ], { convert: false });
  //   });
  // });

  describe('keys()', function() {
    it('should validate valid values', function() {
      let newSchema = schema.keys({
        name: (new StringType).isString.required.valid('Felix'),
        hobbies: (new ArrayType).isArray.required.items((new StringType).isString.required)
      }).keys({
        gender: (new StringType).isString.required.only(['male', 'femaile', 'unknown'])
      });
      Helper.validate(newSchema, [
        [{ name: 'Jill' }, false],
        [{ name: 'Felix' }, false],
        [{ name: 'Felix', hobbies: [] }, false],
        [{ name: 'Felix', hobbies: ['pingpong'] }, false],
        [{ name: 'Felix', hobbies: ['pingpong'], gender: 'boy' }, false],
        [{ name: 'Felix', hobbies: ['pingpong'], gender: 'male' }, true]
      ], { convert: false });

      newSchema.keys({
        nickname: (new StringType).isString.required.valid('my nick name')
      });

      expect(newSchema._inner.children).not.to.have.property('nickname');
    });
  });

  // describe('add()', function() {
  //   it('should validate valid values', function() {
  //     Helper.validate(
  //       schema
  //         .add('name', (new StringType).isString.required.valid('Felix'))
  //         .add('hobbies', (new ArrayType).isArray.required.items((new StringType).isString.required))
  //         .add('gender', (new StringType).isString.required.only(['male', 'femaile', 'unknown']))
  //     ,
  //       [
  //         [{ name: 'Jill' }, false],
  //         [{ name: 'Felix' }, false],
  //         [{ name: 'Felix', hobbies: [] }, false],
  //         [{ name: 'Felix', hobbies: ['pingpong'] }, false],
  //         [{ name: 'Felix', hobbies: ['pingpong'], gender: 'boy' }, false],
  //         [{ name: 'Felix', hobbies: ['pingpong'], gender: 'male' }, true]
  //       ],
  //       { convert: false }
  //     );
  //   });
  // });
});<commit_msg>uncomment object test codes<commit_after>'use strict';

const expect = require('chai').expect;
const Helper = require('./helpers');
const ObjectType = require('../lib/types/object');
const ArrayType = require('../lib/types/array');
const StringType = require('../lib/types/string');

describe('ObjectType', function() {
  let schema;

  beforeEach(function() {
    schema = (new ObjectType()).isObject;
  });

  describe('isObject()', function() {
    it('should validate valid values', function() {
      Helper.validate(schema, [
        [null, false],
        [0, false],
        ['', false],
        [NaN, false],
        [[], true],
        [new Object(), true],
        [{}, true]
      ], { convert: false });
    });
  });

  describe('rename()', function() {
    it('should rename old key to new key', function() {
      Helper.validate(schema.rename('name', 'nickname'), [
        [{ name: '<NAME>' }, { nickname: '<NAME>' }]
      ], { convert: false });
    });

    it('should rename according to renames', function() {
      Helper.validate(schema.rename({
        name: 'nickname',
        sex: 'gender'
      }), [
        [{ name: '<NAME>', sex: 'male' }, { nickname: '<NAME>', gender: 'male' }]
      ], { convert: false });
    });
  });

  describe('keys()', function() {
    it('should validate valid values', function() {
      let newSchema = schema.keys({
        name: (new StringType).isString.required.valid('Felix'),
        hobbies: (new ArrayType).isArray.required.items((new StringType).isString.required)
      }).keys({
        gender: (new StringType).isString.required.only(['male', 'femaile', 'unknown'])
      });
      Helper.validate(newSchema, [
        [{ name: 'Jill' }, false],
        [{ name: 'Felix' }, false],
        [{ name: 'Felix', hobbies: [] }, false],
        [{ name: 'Felix', hobbies: ['pingpong'] }, false],
        [{ name: 'Felix', hobbies: ['pingpong'], gender: 'boy' }, false],
        [{ name: 'Felix', hobbies: ['pingpong'], gender: 'male' }, true]
      ], { convert: false });

      newSchema.keys({
        nickname: (new StringType).isString.required.valid('my nick name')
      });

      expect(newSchema._inner.children).not.to.have.property('nickname');
    });
  });

  describe('add()', function() {
    it('should validate valid values', function() {
      Helper.validate(
        schema
          .add('name', (new StringType).isString.required.valid('Felix'))
          .add('hobbies', (new ArrayType).isArray.required.items((new StringType).isString.required))
          .add('gender', (new StringType).isString.required.only(['male', 'femaile', 'unknown']))
      ,
        [
          [{ name: 'Jill' }, false],
          [{ name: 'Felix' }, false],
          [{ name: 'Felix', hobbies: [] }, false],
          [{ name: 'Felix', hobbies: ['pingpong'] }, false],
          [{ name: 'Felix', hobbies: ['pingpong'], gender: 'boy' }, false],
          [{ name: 'Felix', hobbies: ['pingpong'], gender: 'male' }, true]
        ],
        { convert: false }
      );
    });
  });
});
{'fraction_non_alphanumeric': 0.2181004157339303, 'fraction_numerical': 0.0003197953309881676, 'mean_word_length': 2.455801104972376, 'pattern_counts': {'":': 0, '<': 11, '<?xml version=': 0, '>': 11, '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': '1415544', 'n_tokens_mistral': 1997, 'n_tokens_neox': 1942, 'n_words': 403}