<commit_before>"use strict";

var Schema = require('./_lib/schema');

exports['schema nested object build validation'] = {
	'builder isn\'t string/schema/function': function (test) {
		var sh1 = new Schema();

		test.throws(function () {
			sh1.object(null);
		});
		test.done();
	}
};

exports['check compile return value'] = {
	'isn\'t array/function': function (test) {
		var sh1 = new Schema().validate(function (value, done) {
			done();
		});

		test.throws(function () {
			sh1.compile(function () {
				return {};
			});
		});

		test.done();
	}
};

exports['required'] = {
	'set required': function (test) {
		var sh1 = new Schema();
		sh1.optional();
		sh1.required();
		sh1.optional();
		sh1.required();

		test.ok(sh1.isRequired);

		test.done();
	},
	'set optional': function (test) {
		var sh1 = new Schema();
		sh1.optional();
		sh1.required();
		sh1.optional();

		test.ok(!sh1.isRequired);

		test.done();
	}
};

exports['register'] = {
	'add: name is not string': function (test) {
		var sc1 = new Schema();

		test.throws(function () {
			Schema.register(null, sc1);
		});

		test.done();
	},
	'add: empty name': function (test) {
		var sc1 = new Schema();

		test.throws(function () {
			Schema.register('', sc1);
		});

		test.done();
	},
	'add: schema is not a Schema instance': function (test) {
		test.throws(function () {
			Schema.register('_some_1', null);
		});

		test.done();
	},
	'add: schema exists': function (test) {
		var sc1 = new Schema();
		var sc2 = new Schema();
		Schema.register('_some_1', sc1);

		test.throws(function () {
			Schema.register('_some_1', sc2);
		});

		test.done();
	},
	'get: name is not string': function (test) {
		test.throws(function () {
			Schema.get();
		});

		test.done();
	},
	'get: empty name': function (test) {
		test.throws(function () {
			Schema.get('');
		});

		test.done();
	},
	'get: no schema defined': function (test) {
		test.throws(function () {
			Schema.get('_some_2');
		});

		test.done();
	}
};

exports['validation error'] = {
	'rule name is not string': function (test) {
		test.throws(function () {
			var err = new Schema.ValidationError(null, null, null);
		});

		test.throws(function () {
			var err = new Schema.ValidationResultError(null, null, null, null, null);
		});

		test.done();
	},
	'empty rule': function (test) {
		test.throws(function () {
			var err = new Schema.ValidationError('', null, null);
		});

		test.throws(function () {
			var err = new Schema.ValidationResultError('', null, null, null, null);
		});

		test.done();
	},
	'create Error': function (test) {
		var err;
		err = new Schema.ValidationError('hello', null, null);
		test.ok(err instanceof Error);
		test.ok(err instanceof Schema.ValidationError);
		test.ok(!(err instanceof Schema.ValidationResultError));

		err = Schema.ValidationError('hello', null, null);
		test.ok(err instanceof Error);
		test.ok(err instanceof Schema.ValidationError);
		test.ok(!(err instanceof Schema.ValidationResultError));

		err = new Schema.ValidationResultError('hello', null, null);
		test.ok(err instanceof Error);
		test.ok(err instanceof Schema.ValidationError);
		test.ok(err instanceof Schema.ValidationResultError);

		err = Schema.ValidationResultError('hello', null, null);
		test.ok(err instanceof Error);
		test.ok(err instanceof Schema.ValidationError);
		test.ok(err instanceof Schema.ValidationResultError);

		test.done();
	}
};<commit_msg>add tests for Validation error. add test for process function in like method<commit_after>"use strict";

var Schema = require('./_lib/schema');

exports['schema nested object build validation'] = {
	'builder isn\'t string/schema/function': function (test) {
		var sh1 = new Schema();

		test.throws(function () {
			sh1.object(null);
		});
		test.done();
	}
};

exports['check compile return value'] = {
	'isn\'t array/function': function (test) {
		var sh1 = new Schema().validate(function (value, done) {
			done();
		});

		test.throws(function () {
			sh1.compile(function () {
				return {};
			});
		});

		test.done();
	}
};

exports['schema - like'] = {
	'process': function (test) {
		var sh1 = new Schema();
		var sh2 = new Schema().array();

		sh1.like(sh2, function (schema) {
			return false;
		});

		test.ok(!sh1.isArray);

		test.done();
	},
	'throw if schema isn\'t Schema': function (test) {
		var sh2 = new Schema().array();

		test.throws(function () {
			sh2.like(null);
		});

		test.done();
	}
};

exports['required'] = {
	'set required': function (test) {
		var sh1 = new Schema();
		sh1.optional();
		sh1.required();
		sh1.optional();
		sh1.required();

		test.ok(sh1.isRequired);

		test.done();
	},
	'set optional': function (test) {
		var sh1 = new Schema();
		sh1.optional();
		sh1.required();
		sh1.optional();

		test.ok(!sh1.isRequired);

		test.done();
	}
};

exports['register'] = {
	'add: name is not string': function (test) {
		var sc1 = new Schema();

		test.throws(function () {
			Schema.register(null, sc1);
		});

		test.done();
	},
	'add: empty name': function (test) {
		var sc1 = new Schema();

		test.throws(function () {
			Schema.register('', sc1);
		});

		test.done();
	},
	'add: schema is not a Schema instance': function (test) {
		test.throws(function () {
			Schema.register('_some_1', null);
		});

		test.done();
	},
	'add: schema exists': function (test) {
		var sc1 = new Schema();
		var sc2 = new Schema();
		Schema.register('_some_1', sc1);

		test.throws(function () {
			Schema.register('_some_1', sc2);
		});

		test.done();
	},
	'get: name is not string': function (test) {
		test.throws(function () {
			Schema.get();
		});

		test.done();
	},
	'get: empty name': function (test) {
		test.throws(function () {
			Schema.get('');
		});

		test.done();
	},
	'get: no schema defined': function (test) {
		test.throws(function () {
			Schema.get('_some_2');
		});

		test.done();
	}
};

exports['validation error'] = {
	'rule name is not string': function (test) {
		test.throws(function () {
			var err = new Schema.ValidationError(null, null, null);
		});

		test.throws(function () {
			var err = new Schema.ValidationResultError(null, null, null, null, null);
		});

		test.done();
	},
	'index': function (test) {
		var err = new Schema.ValidationResultError('hello', 'world', [1, 3, 2, 4, 5], 3, 'some/path/to/error');

		test.deepEqual(err.path, ['some', 'path', 'to', 'error', '3']);
		test.deepEqual(err.index, 3);
		test.deepEqual(err.rule, 'hello');
		test.deepEqual(err.params, 'world');
		test.deepEqual(err.value, 4);

		test.done();
	},
	'empty rule': function (test) {
		test.throws(function () {
			var err = new Schema.ValidationError('', null, null);
		});

		test.throws(function () {
			var err = new Schema.ValidationResultError('', null, null, null, null);
		});

		test.done();
	},
	'create Error': function (test) {
		var err;
		err = new Schema.ValidationError('hello', null, null);
		test.ok(err instanceof Error);
		test.ok(err instanceof Schema.ValidationError);
		test.ok(!(err instanceof Schema.ValidationResultError));

		err = Schema.ValidationError('hello', null, null);
		test.ok(err instanceof Error);
		test.ok(err instanceof Schema.ValidationError);
		test.ok(!(err instanceof Schema.ValidationResultError));

		err = new Schema.ValidationResultError('hello', null, null);
		test.ok(err instanceof Error);
		test.ok(err instanceof Schema.ValidationError);
		test.ok(err instanceof Schema.ValidationResultError);

		err = Schema.ValidationResultError('hello', null, null);
		test.ok(err instanceof Error);
		test.ok(err instanceof Schema.ValidationError);
		test.ok(err instanceof Schema.ValidationResultError);

		test.done();
	}
};
{'fraction_non_alphanumeric': 0.18318514644351463, 'fraction_numerical': 0.009152719665271966, 'mean_word_length': 3.7657320872274145, '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': '3669897', 'n_tokens_mistral': 2844, 'n_tokens_neox': 2535, 'n_words': 606}