Permalink
Browse files

Rewrite the ‘regex’ test suite into Mocha

  • Loading branch information...
1 parent c731609 commit 57ae3b9e748f4f3dcf7d0f18286b37f335e79940 @Baggz committed Mar 7, 2012
Showing with 58 additions and 0 deletions.
  1. +58 −0 tests/json/attributes/format/regex.js
@@ -0,0 +1,58 @@
+if (typeof module !== 'undefined' && module.exports) {
+ var expect = require('expect.js');
+ var Amanda = require('../../../../dist/latest.js');
+}
+
+/**
+ * Format
+ * --------------------
+ */
+suite('JSON/Attribute/format#regex', function() {
+
+ var count = 0;
+
+ /**
+ * Schema
+ */
+ var schema = {
+ format: 'regex'
+ };
+
+ /**
+ * Validator
+ */
+ var Validator = new Amanda('json');
+
+ test('should not return an error', function() {
+ [
+ new RegExp(),
+ /a/gi
+ ].forEach(function(data) {
+ Validator.validate(data, schema, function(error) {
+ count += 1;
+ expect(error).to.not.be.ok();
+ });
+ });
+ });
+
+ test('should return an error', function() {
+ [
+ new Date(),
+ [],
+ {},
+ function() {},
+ '11/11/11',
+ 11
+ ].forEach(function(data) {
+ Validator.validate(data, schema, function(error) {
+ count += 1;
+ expect(error).to.be.ok();
+ });
+ });
+ });
+
+ test('should run 8 times', function() {
+ expect(count).to.be.eql(8);
+ });
+
+});

0 comments on commit 57ae3b9

Please sign in to comment.