Skip to content

HTTPS clone URL

Subversion checkout URL

You can clone with
or
.
Download ZIP
Browse files

update tests

  • Loading branch information...
commit 275eba960083d477aa1da61e4a41ddb6f53608d7 1 parent 4340ab6
@russellhaering russellhaering authored
View
28 test/assert.js
@@ -1,28 +0,0 @@
-/*
- * Copyright 2011 Rackspace
- *
- * Licensed under the Apache License, Version 2.0 (the "License");
- * you may not use this file except in compliance with the License.
- * You may obtain a copy of the License at
- *
- * http://www.apache.org/licenses/LICENSE-2.0
- *
- * Unless required by applicable law or agreed to in writing, software
- * distributed under the License is distributed on an "AS IS" BASIS,
- * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
- * See the License for the specific language governing permissions and
- * limitations under the License.
- *
- */
-
-
-/**
- * Custom assert methods.
- */
-
-var assert = require('assert');
-
-var keys = Object.keys(assert);
-keys.forEach(function(key) {
- exports[key] = assert[key];
-});
View
102 tests/test-bitbuffer.js
@@ -0,0 +1,102 @@
+/*
+ * Copyright 2011 Rackspace
+ *
+ * Licensed under the Apache License, Version 2.0 (the "License");
+ * you may not use this file except in compliance with the License.
+ * You may obtain a copy of the License at
+ *
+ * http://www.apache.org/licenses/LICENSE-2.0
+ *
+ * Unless required by applicable law or agreed to in writing, software
+ * distributed under the License is distributed on an "AS IS" BASIS,
+ * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
+ * See the License for the specific language governing permissions and
+ * limitations under the License.
+ *
+ */
+
+var bif = require('bitbuffer').BitBuffer;
+
+exports['test_bitbuffer_setbit'] = function(test, assert) {
+ var buf = new bif(24);
+
+ assert.deepEqual(buf.buf[2], 0);
+ assert.deepEqual(buf.buf[1], 0);
+ assert.deepEqual(buf.buf[0], 0);
+
+ buf.setBit(1);
+ buf.setBit(0);
+ buf.setBit(23);
+ assert.deepEqual(buf.buf[2], 3);
+ assert.deepEqual(buf.buf[1], 0);
+ assert.deepEqual(buf.buf[0], 0x80);
+
+ test.finish();
+};
+
+exports['test_bitbuffer_not'] = function(test, assert) {
+ var buf = new bif(24);
+
+ buf.setBit(1);
+ buf.setBit(0);
+ buf.setBit(23);
+
+ buf.not();
+ assert.deepEqual(buf.buf[2], 0xfc);
+ assert.deepEqual(buf.buf[1], 0xff);
+ assert.deepEqual(buf.buf[0], 0x7f);
+
+ test.finish();
+};
+
+exports['test_bitbuffer_and'] = function(test, assert) {
+ var buf = new bif(24);
+ var buf2 = new bif(24);
+
+ buf.setBit(1);
+ buf.setBit(0);
+ buf.setBit(23);
+
+ buf2.setBit(1);
+ buf2.setBit(0);
+ buf2.setBit(22);
+ buf2.setBit(23);
+
+ buf2.and(buf);
+ assert.deepEqual(buf.buf[2], 3);
+ assert.deepEqual(buf.buf[1], 0);
+ assert.deepEqual(buf.buf[0], 0x80);
+
+ test.finish();
+};
+
+exports['test_bitbuffer_cmp'] = function(test, assert) {
+ var buf = new bif(24);
+ var buf2 = new bif(24);
+
+ buf.setBit(1);
+ buf.setBit(0);
+ buf.setBit(23);
+
+ buf2.setBit(1);
+ buf2.setBit(0);
+ buf2.setBit(23);
+
+ assert.deepEqual(buf.cmp(buf2), true);
+
+ buf2.setBit(22);
+
+ assert.deepEqual(buf.cmp(buf2), false);
+ test.finish();
+};
+
+exports['test_bitbuffer_constructor'] = function(test, assert) {
+ var buf, buf2, str = '192.192.192.192';
+ buf = new Buffer(str.split('.'));
+ buf2 = new bif(buf);
+ assert.deepEqual(buf[0], buf2.buf[0]);
+ assert.deepEqual(buf[1], buf2.buf[1]);
+ assert.deepEqual(buf[2], buf2.buf[2]);
+ assert.deepEqual(buf[3], buf2.buf[3]);
+ test.finish();
+};
View
58 tests/test-cidr.js
@@ -0,0 +1,58 @@
+/*
+ * Copyright 2011 Rackspace
+ *
+ * Licensed under the Apache License, Version 2.0 (the "License");
+ * you may not use this file except in compliance with the License.
+ * You may obtain a copy of the License at
+ *
+ * http://www.apache.org/licenses/LICENSE-2.0
+ *
+ * Unless required by applicable law or agreed to in writing, software
+ * distributed under the License is distributed on an "AS IS" BASIS,
+ * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
+ * See the License for the specific language governing permissions and
+ * limitations under the License.
+ *
+ */
+
+CIDR = require('cidr').CIDR;
+
+exports['test_cidr_v4'] = function(test, assert) {
+ c1 = new CIDR('192.169.0.1/29');
+
+ assert.deepEqual(c1.v, 4);
+ assert.deepEqual(c1.subnet, 29);
+ assert.deepEqual(c1.mask.buf[3], 248);
+ assert.deepEqual(c1.mask.buf[1], 255);
+ assert.deepEqual(c1.prefix.buf[0], 192);
+ assert.deepEqual(c1.prefix.buf[1], 169);
+
+ assert.deepEqual(c1.isInCIDR('192.169.0.1'), true);
+ assert.deepEqual(c1.isInCIDR('192.160.0.1'), false);
+ assert.deepEqual(c1.isInCIDR('a::b'), false);
+
+ test.finish();
+};
+
+exports['test_cidr_v6'] = function(test, assert) {
+
+ c1 = new CIDR('a::b/64');
+
+ assert.deepEqual(c1.v, 6);
+ assert.deepEqual(c1.subnet, 64);
+ assert.deepEqual(c1.mask.buf[8], 0);
+ assert.deepEqual(c1.mask.buf[7], 255);
+ assert.deepEqual(c1.prefix.buf[0], 0);
+ assert.deepEqual(c1.prefix.buf[1], 0x0a);
+
+ assert.deepEqual(c1.isInCIDR('a::b'), true);
+ assert.deepEqual(c1.isInCIDR('b::b'), false);
+ assert.deepEqual(c1.isInCIDR('192.150.0.1'), false);
+
+ c1 = new CIDR('fc00::0/7');
+ assert.deepEqual(c1.v, 6);
+ assert.deepEqual(c1.subnet, 7);
+ assert.deepEqual(c1.prefix.buf[0], 0xfc);
+ test.finish();
+
+};
View
88 test/swiz.js → tests/test-swiz.js
@@ -15,8 +15,7 @@
*
*/
-var assert = require('./assert');
-var swiz = require('../lib/serializer');
+var swiz = require('swiz');
// Mock set of serialization defs
@@ -69,18 +68,22 @@ Node.prototype.get_public_address = function(callback) {
*/
Node.prototype.getSerializerType = function() {return 'Node';};
-exports['test_xml_escape_string'] = function() {
- sw = new swiz.Swiz(def);
+exports['test_xml_escape_string'] = function(test, assert) {
+ var sw = new swiz.Swiz(def);
assert.deepEqual(sw.xmlEscapeString('<&blah>'), '&lt;&amp;blah&gt;');
+
+ test.finish();
};
-exports['test_xml_elem'] = function() {
- sw = new swiz.Swiz(def);
+exports['test_xml_elem'] = function(test, assert) {
+ var sw = new swiz.Swiz(def);
assert.deepEqual('<blah>stuff</blah>', sw.xmlElem('blah', 'stuff'));
+
+ test.finish();
};
-exports['test_xml_array_serial'] = function() {
- sw = new swiz.Swiz(def);
+exports['test_xml_array_serial'] = function(test, assert) {
+ var sw = new swiz.Swiz(def);
// test null array handling
var str = sw.serializeArrayXml('blah', []);
var eq1 = '<blah/>' === str;
@@ -95,10 +98,12 @@ exports['test_xml_array_serial'] = function() {
// text mixed-array handling
assert.deepEqual('<blah>1</blah><blah>bla</blah><blah>2</blah>',
sw.serializeArrayXml('blah', [1, 'bla', '2']));
+
+ test.finish();
};
-exports['test_xml_array_hash'] = function() {
- sw = new swiz.Swiz(def);
+exports['test_xml_array_hash'] = function(test, assert) {
+ var sw = new swiz.Swiz(def);
// test null hash handling
var str = sw.serializeHashXml('blah', {});
var eq1 = '<blah/>' === str;
@@ -113,10 +118,12 @@ exports['test_xml_array_hash'] = function() {
// tets mixed-hash handling
assert.deepEqual('<blah><a>1</a><b>c</b></blah>', sw.serializeHashXml(
'blah', {'a': '1', 'b': 'c'}));
+
+ test.finish();
};
-exports['test_build_int_node_xml'] = function() {
- sw = new swiz.Swiz(def);
+exports['test_build_int_node_xml'] = function(test, assert) {
+ var sw = new swiz.Swiz(def);
assert.deepEqual(sw.buildIntNode(swiz.SERIALIZATION.SERIALIZATION_XML,
'blah', 'blag'), '<blah>blag</blah>');
assert.deepEqual(sw.buildIntNode(swiz.SERIALIZATION.SERIALIZATION_XML,
@@ -125,10 +132,12 @@ exports['test_build_int_node_xml'] = function() {
'blah', {'a': 'blah', 'b': 1}), '<blah><a>blah</a><b>1</b></blah>');
assert.deepEqual(sw.buildIntNode(swiz.SERIALIZATION.SERIALIZATION_XML,
'blah', 1), '<blah>1</blah>');
+
+ test.finish();
};
-exports['test_build_int_node_json'] = function() {
- sw = new swiz.Swiz(def);
+exports['test_build_int_node_json'] = function(test, assert) {
+ var sw = new swiz.Swiz(def);
assert.deepEqual(sw.buildIntNode(swiz.SERIALIZATION.SERIALIZATION_JSON,
'blah', 'blag'), ['blah', 'blag']);
assert.deepEqual(sw.buildIntNode(swiz.SERIALIZATION.SERIALIZATION_JSON,
@@ -137,14 +146,16 @@ exports['test_build_int_node_json'] = function() {
'blah', {'a': 'blah', 'b': 1}), ['blah', {'a': 'blah', 'b' : 1}]);
assert.deepEqual(sw.buildIntNode(swiz.SERIALIZATION.SERIALIZATION_JSON,
'blah', 1), ['blah', 1]);
+
+ test.finish();
};
-exports['test_serial_xml'] = function() {
- blahnode = new Node();
- sw = new swiz.Swiz(def);
+exports['test_serial_xml'] = function(test, assert) {
+ var blahnode = new Node();
+ var sw = new swiz.Swiz(def);
//swiz.loadDefinitions(def);
sw.serialize(swiz.SERIALIZATION.SERIALIZATION_XML, 1, blahnode,
- function(err, results)
+ function(err, results)
{
// need to make an appointemnt with a DOM for this one.
assert.deepEqual(results, '<?xml version="1.0" encoding="UTF-8"?>' +
@@ -153,17 +164,18 @@ exports['test_serial_xml'] = function() {
'agent_name><ipaddress>123.33.22.1</ipaddress>' +
'<public_ips>123.45.55.44</public_ips>' +
'<public_ips>122.123.32.2</public_ips></Node>');
- //console.log(results);
+
+ test.finish();
}
);
};
-exports['test_serial_json'] = function() {
- blahnode = new Node();
- sw = new swiz.Swiz(def);
+exports['test_serial_json'] = function(test, assert) {
+ var blahnode = new Node();
+ var sw = new swiz.Swiz(def);
//swiz.loadDefinitions(def);
sw.serialize(swiz.SERIALIZATION.SERIALIZATION_JSON, 1, blahnode,
- function(err, results)
+ function(err, results)
{
var rep = JSON.parse(results);
assert.deepEqual(rep.id, 15245);
@@ -172,17 +184,19 @@ exports['test_serial_json'] = function() {
assert.deepEqual(rep.agent_name, 'gl<ah');
assert.deepEqual(rep.ipaddress, '123.33.22.1');
assert.deepEqual(rep.public_ips, ['123.45.55.44', '122.123.32.2']);
+
+ test.finish();
}
);
};
-exports['test_serial_array_xml'] = function() {
- blahnode = new Node();
- blahnode2 = new Node();
+exports['test_serial_array_xml'] = function(test, assert) {
+ var blahnode = new Node();
+ var blahnode2 = new Node();
blahnode2.hash_id = '444';
blahnode2.agent_name = 'your mom';
var blaharr = [blahnode, blahnode2];
- sw = new swiz.Swiz(def);
+ var sw = new swiz.Swiz(def);
sw.serialize(swiz.SERIALIZATION.SERIALIZATION_XML, 1, blaharr,
function(err, results)
{
@@ -198,30 +212,34 @@ exports['test_serial_array_xml'] = function() {
'agent_name><ipaddress>123.33.22.1</ipaddress>' +
'<public_ips>123.45.55.44</public_ips>' +
'<public_ips>122.123.32.2</public_ips></Node></group>');
+
+ test.finish();
}
);
};
-exports['test_error_type'] = function() {
- blah = { };
- sw = new swiz.Swiz(def);
+exports['test_error_type'] = function(test, assert) {
+ var blah = { };
+ var sw = new swiz.Swiz(def);
blah.getSerializerType = function() {return 'monito';};
sw.serialize(swiz.SERIALIZATION.SERIALIZATION_JSON, 1, blah,
function(err, results)
{
assert.ok(err instanceof Error);
+
+ test.finish();
}
);
};
-exports['test_serial_array_json'] = function() {
- blahnode = new Node();
- blahnode2 = new Node();
+exports['test_serial_array_json'] = function(test, assert) {
+ var blahnode = new Node();
+ var blahnode2 = new Node();
blahnode2.hash_id = '444';
blahnode2.agent_name = 'your mom';
var blaharr = [blahnode, blahnode2];
- sw = new swiz.Swiz(def);
+ var sw = new swiz.Swiz(def);
sw.serialize(swiz.SERIALIZATION.SERIALIZATION_JSON, 1, blaharr,
function(err, results)
{
@@ -240,6 +258,8 @@ exports['test_serial_array_json'] = function() {
assert.deepEqual(rep[1].ipaddress, '123.33.22.1');
assert.deepEqual(rep[1].public_ips,
['123.45.55.44', '122.123.32.2']);
+
+ test.finish();
}
);
};
View
356 test/valve.js → tests/test-valve.js
@@ -15,548 +15,656 @@
*
*/
+var swiz = require('swiz');
-var assert = require('./assert');
-var validate = require('../lib//valve');
-var V = require('../lib/valve').Valve;
-
-exports['test_validate_int'] = function() {
+exports['test_swiz_int'] = function(test, assert) {
var rv;
var schema = {
- a: new V().isInt()
+ a: new swiz.Valve().isInt()
};
// positive case
var obj = { a: 1 };
var obj_ext = { a: 1, b: 2 };
- rv = validate.check(schema, obj_ext);
+ rv = swiz.check(schema, obj_ext);
assert.ok(rv.is_valid === true, 'integer test');
assert.deepEqual(rv.cleaned, obj);
// negative case
var neg = { a: 'test' };
- rv = validate.check(schema, neg);
+ rv = swiz.check(schema, neg);
assert.ok(rv.is_valid === false, 'integer test (negative case)');
+
+ test.finish();
};
-exports['test_validate_email'] = function() {
+exports['test_swiz_email'] = function(test, assert) {
var rv;
var schema = {
- a: new V().isEmail()
+ a: new swiz.Valve().isEmail()
};
// positive case
var obj = { a: 'test@cloudkick.com' };
var obj_ext = { a: 'test@cloudkick.com', b: 2 };
- rv = validate.check(schema, obj_ext);
+ rv = swiz.check(schema, obj_ext);
assert.ok(rv.is_valid === true, 'email test');
assert.deepEqual(rv.cleaned, obj);
// negative case
var neg = { a: 'invalidemail@' };
- rv = validate.check(schema, neg);
+ rv = swiz.check(schema, neg);
assert.ok(rv.is_valid === false, 'email test (negative case)');
+
+ test.finish();
};
-exports['test_validate_url'] = function() {
+exports['test_swiz_url'] = function(test, assert) {
var rv;
var schema = {
- a: new V().isUrl()
+ a: new swiz.Valve().isUrl()
};
// positive case
var obj = { a: 'http://www.cloudkick.com' };
var obj_ext = { a: 'http://www.cloudkick.com', b: 2 };
- rv = validate.check(schema, obj_ext);
+ rv = swiz.check(schema, obj_ext);
assert.ok(rv.is_valid === true, 'url test');
assert.deepEqual(rv.cleaned, obj);
// negative case
var neg = { a: 'invalid/' };
- rv = validate.check(schema, neg);
+ rv = swiz.check(schema, neg);
assert.ok(rv.is_valid === false, 'url test (negative case)');
+
+ test.finish();
};
-exports['test_validate_ip'] = function() {
+exports['test_swiz_ip'] = function(test, assert) {
var rv;
var schema = {
- a: new V().isIP()
+ a: new swiz.Valve().isIP()
};
// positive case
var obj = { a: '192.168.0.1' };
var obj_ext = { a: '192.168.0.1', b: 2 };
- rv = validate.check(schema, obj_ext);
+ rv = swiz.check(schema, obj_ext);
assert.ok(rv.is_valid === true, 'IP test');
assert.deepEqual(rv.cleaned, obj);
// negative case
var neg = { a: 'invalid/' };
- rv = validate.check(schema, neg);
+ rv = swiz.check(schema, neg);
assert.ok(rv.is_valid === false, 'IP test (negative case)');
neg = {a: '12345' };
- rv = validate.check(schema, neg);
+ rv = swiz.check(schema, neg);
assert.ok(rv.is_valid === false, 'IP test (negative case 2)');
// IPv6 normalization
obj_ext = { a: '2001:db8::1:0:0:1'};
- rv = validate.check(schema, obj_ext);
+ rv = swiz.check(schema, obj_ext);
assert.ok(rv.is_valid === true, 'IPv6 test and normalization');
assert.deepEqual(rv.cleaned.a, '2001:0db8:0000:0000:0001:0000:0000:0001');
+
+ test.finish();
};
-exports['test_validate_cidr'] = function() {
+exports['test_swiz_ip_blacklist'] = function(test, assert) {
var rv;
var schema = {
- a: new V().isCIDR()
+ a: new swiz.Valve().isIP().notIpBlacklisted()
+ };
+
+ // positive case
+ var obj_ext = { a: '173.45.245.32', b: 2 };
+ rv = swiz.check(schema, obj_ext);
+ assert.ok(rv.is_valid === true, 'IP Blacklist test');
+
+ // negative case
+ var neg = { a: 'invalid/' };
+ rv = swiz.check(schema, neg);
+ assert.ok(rv.is_valid === false, 'IP blacklist test (negative case)');
+
+ neg = {a: '192.168.0.1' };
+ rv = swiz.check(schema, neg);
+ assert.ok(rv.is_valid === false, 'IP blacklist test (negative case 2)');
+
+ // IPv6
+ obj_ext = { a: '2001:db8::1:0:0:1'};
+ rv = swiz.check(schema, obj_ext);
+ assert.ok(rv.is_valid === true, 'IPv6 blacklist test');
+
+ neg = {a: 'fc00:1:0:0:1' };
+ rv = swiz.check(schema, neg);
+ assert.ok(rv.is_valid === false, 'IPv6 blacklist test (negative case)');
+
+
+ test.finish();
+};
+
+exports['test_swiz_cidr'] = function(test, assert) {
+ var rv;
+ var schema = {
+ a: new swiz.Valve().isCIDR()
};
// positive case
var obj = { a: '192.168.0.1/2' };
var obj_ext = { a: '192.168.0.1/2', b: 2 };
- rv = validate.check(schema, obj_ext);
+ rv = swiz.check(schema, obj_ext);
assert.ok(rv.is_valid === true, 'CIDR test');
assert.deepEqual(rv.cleaned, obj);
// negative case
var neg = { a: 'invalid/' };
- rv = validate.check(schema, neg);
+ rv = swiz.check(schema, neg);
assert.ok(rv.is_valid === false, 'CIDR test (negative case)');
neg = { a: '192.168.0.1/128' };
- rv = validate.check(schema, neg);
+ rv = swiz.check(schema, neg);
assert.ok(rv.is_valid === false, 'CIDR test (negative case 2)');
// IPv6 normalization
obj_ext = { a: '2001:db8::1:0:0:1/3'};
- rv = validate.check(schema, obj_ext);
+ rv = swiz.check(schema, obj_ext);
assert.ok(rv.is_valid === true, 'IPv6 CIDR test');
assert.deepEqual(rv.cleaned.a,
'2001:0db8:0000:0000:0001:0000:0000:0001/3');
neg = { a: '2001:db8::1:0:0:1/194' };
- rv = validate.check(schema, neg);
+ rv = swiz.check(schema, neg);
assert.ok(rv.is_valid === false, 'IPv6 CIDR test (negative case)');
+ test.finish();
};
-exports['test_validate_alpha'] = function() {
+exports['test_swiz_alpha'] = function(test, assert) {
var rv;
var schema = {
- a: new V().isAlpha()
+ a: new swiz.Valve().isAlpha()
};
// positive case
var obj = { a: 'ABC' };
var obj_ext = { a: 'ABC', b: 2 };
- rv = validate.check(schema, obj_ext);
+ rv = swiz.check(schema, obj_ext);
assert.ok(rv.is_valid === true, 'alpha test');
assert.deepEqual(rv.cleaned, obj);
// negative case
var neg = { a: 'invalid/' };
- rv = validate.check(schema, neg);
+ rv = swiz.check(schema, neg);
assert.ok(rv.is_valid === false, 'alpha test (negative case)');
+
+ test.finish();
};
-exports['test_validate_alphanumeric'] = function() {
+exports['test_swiz_alphanumeric'] = function(test, assert) {
var rv;
var schema = {
- a: new V().isAlphanumeric()
+ a: new swiz.Valve().isAlphanumeric()
};
// positive case
var obj = { a: 'ABC123' };
var obj_ext = { a: 'ABC123', b: 2 };
- rv = validate.check(schema, obj_ext);
+ rv = swiz.check(schema, obj_ext);
assert.ok(rv.is_valid === true, 'alphanumeric test');
assert.deepEqual(rv.cleaned, obj);
// negative case
var neg = { a: 'invalid/' };
- rv = validate.check(schema, neg);
+ rv = swiz.check(schema, neg);
assert.ok(rv.is_valid === false, 'alphanumeric test (negative case)');
+
+ test.finish();
};
-exports['test_validate_numeric'] = function() {
+exports['test_swiz_numeric'] = function(test, assert) {
var rv;
var schema = {
- a: new V().isNumeric()
+ a: new swiz.Valve().isNumeric()
};
// positive case
var obj = { a: '123' };
var obj_ext = { a: 123, b: 2 };
- rv = validate.check(schema, obj_ext);
+ rv = swiz.check(schema, obj_ext);
assert.ok(rv.is_valid === true, 'numeric test');
assert.deepEqual(rv.cleaned, obj);
// negative case
var neg = { a: '/' };
- rv = validate.check(schema, neg);
+ rv = swiz.check(schema, neg);
assert.ok(rv.is_valid === false, 'numeric test (negative case)');
+
+ test.finish();
};
-exports['test_validate_lowercase'] = function() {
+exports['test_swiz_lowercase'] = function(test, assert) {
var rv;
var schema = {
- a: new V().isLowercase()
+ a: new swiz.Valve().isLowercase()
};
// positive case
var obj = { a: 'abc' };
var obj_ext = { a: 'abc', b: 2 };
- rv = validate.check(schema, obj_ext);
+ rv = swiz.check(schema, obj_ext);
assert.ok(rv.is_valid === true, 'lowercase test');
assert.deepEqual(rv.cleaned, obj);
// negative case
var neg = { a: 'ABCabc' };
- rv = validate.check(schema, neg);
+ rv = swiz.check(schema, neg);
assert.ok(rv.is_valid === false, 'lowercase test (negative case)');
+
+ test.finish();
};
-exports['test_validate_uppercase'] = function() {
+exports['test_swiz_uppercase'] = function(test, assert) {
var rv;
var schema = {
- a: new V().isUppercase()
+ a: new swiz.Valve().isUppercase()
};
// positive case
var obj = { a: 'ABC' };
var obj_ext = { a: 'ABC', b: 2 };
- rv = validate.check(schema, obj_ext);
+ rv = swiz.check(schema, obj_ext);
assert.ok(rv.is_valid === true, 'uppercase test');
assert.deepEqual(rv.cleaned, obj);
// negative case
var neg = { a: 'ABCabc' };
- rv = validate.check(schema, neg);
+ rv = swiz.check(schema, neg);
assert.ok(rv.is_valid === false, 'uppercase test (negative case)');
+
+ test.finish();
};
-exports['test_validate_decimal'] = function() {
+exports['test_swiz_decimal'] = function(test, assert) {
var rv;
var schema = {
- a: new V().isDecimal()
+ a: new swiz.Valve().isDecimal()
};
// positive case
var obj = { a: '123.123' };
var obj_ext = { a: 123.123, b: 2 };
- rv = validate.check(schema, obj_ext);
+ rv = swiz.check(schema, obj_ext);
assert.ok(rv.is_valid === true, 'decimal test');
assert.deepEqual(rv.cleaned, obj);
// negative case
var neg = { a: 'ABCabc' };
- rv = validate.check(schema, neg);
+ rv = swiz.check(schema, neg);
assert.ok(rv.is_valid === false, 'decimal test (negative case)');
+
+ test.finish();
};
-exports['test_validate_float'] = function() {
+exports['test_swiz_float'] = function(test, assert) {
var rv;
var schema = {
- a: new V().isFloat()
+ a: new swiz.Valve().isFloat()
};
// positive case
var obj = { a: 123.123 };
var obj_ext = { a: 123.123, b: 2 };
- rv = validate.check(schema, obj_ext);
+ rv = swiz.check(schema, obj_ext);
assert.ok(rv.is_valid === true, 'float test');
assert.deepEqual(rv.cleaned, obj);
// negative case
var neg = { a: 'ABCabc' };
- rv = validate.check(schema, neg);
+ rv = swiz.check(schema, neg);
assert.ok(rv.is_valid === false, 'float test (negative case)');
+
+ test.finish();
};
-exports['test_validate_notnull'] = function() {
+exports['test_swiz_notnull'] = function(test, assert) {
var rv;
var schema = {
- a: new V().notNull()
+ a: new swiz.Valve().notNull()
};
// positive case
var obj = { a: '1' };
var obj_ext = { a: '1', b: 2 };
- rv = validate.check(schema, obj_ext);
+ rv = swiz.check(schema, obj_ext);
assert.ok(rv.is_valid === true, 'notnull test');
assert.deepEqual(rv.cleaned, obj);
// negative case
var neg = { a: '' };
- rv = validate.check(schema, neg);
+ rv = swiz.check(schema, neg);
assert.ok(rv.is_valid === false, 'notnull test (negative case)');
+
+ test.finish();
};
-exports['test_validate_notempty'] = function() {
+exports['test_swiz_notempty'] = function(test, assert) {
var rv;
var schema = {
- a: new V().notEmpty()
+ a: new swiz.Valve().notEmpty()
};
// positive case
var obj = { a: '1' };
var obj_ext = { a: '1', b: 2 };
- rv = validate.check(schema, obj_ext);
+ rv = swiz.check(schema, obj_ext);
assert.ok(rv.is_valid === true, 'notempty test');
assert.deepEqual(rv.cleaned, obj);
// negative case
var neg = { a: '' };
- rv = validate.check(schema, neg);
+ rv = swiz.check(schema, neg);
assert.ok(rv.is_valid === false, 'notempty test (negative case)');
+
+ test.finish();
};
-exports['test_validate_regex'] = function() {
+exports['test_swiz_regex'] = function(test, assert) {
var rv;
var schema = {
- a: new V().regex('^a$')
+ a: new swiz.Valve().regex('^a$')
};
// positive case
var obj = { a: 'a' };
var obj_ext = { a: 'a', b: 2 };
- rv = validate.check(schema, obj_ext);
+ rv = swiz.check(schema, obj_ext);
assert.ok(rv.is_valid === true, 'regex test');
assert.deepEqual(rv.cleaned, obj);
// negative case
var neg = { a: 'b' };
- rv = validate.check(schema, neg);
+ rv = swiz.check(schema, neg);
assert.ok(rv.is_valid === false, 'regex test (negative case)');
+
+ test.finish();
};
-exports['test_validate_notregex'] = function() {
+exports['test_swiz_notregex'] = function(test, assert) {
var rv;
var schema = {
- a: new V().notRegex(/e/)
+ a: new swiz.Valve().notRegex(/e/)
};
// positive case
var obj = { a: 'foobar' };
var obj_ext = { a: 'foobar', b: 2 };
- rv = validate.check(schema, obj_ext);
+ rv = swiz.check(schema, obj_ext);
assert.ok(rv.is_valid === true, 'notregex test');
assert.deepEqual(rv.cleaned, obj);
+
+ test.finish();
};
-exports['test_validate_len'] = function() {
+exports['test_swiz_len'] = function(test, assert) {
var rv;
var schema = {
- a: new V().len(1)
+ a: new swiz.Valve().len(1)
};
// positive case
var obj = { a: '1' };
var obj_ext = { a: '1', b: 2 };
- rv = validate.check(schema, obj_ext);
+ rv = swiz.check(schema, obj_ext);
assert.ok(rv.is_valid === true, 'len test');
assert.deepEqual(rv.cleaned, obj);
// negative case
var neg = { a: '' };
- rv = validate.check(schema, neg);
+ rv = swiz.check(schema, neg);
assert.ok(rv.is_valid === false, 'len test (negative case)');
+
+ test.finish();
};
-exports['test_validate_null'] = function() {
+exports['test_swiz_null'] = function(test, assert) {
var rv;
var schema = {
- a: new V().isNull()
+ a: new swiz.Valve().isNull()
};
// positive case
var obj = { a: null};
var obj_ext = { a: null, b: 2 };
- rv = validate.check(schema, obj_ext);
+ rv = swiz.check(schema, obj_ext);
assert.ok(rv.is_valid === true, 'null test');
assert.deepEqual(rv.cleaned, obj);
// negative case
var neg = { a: 'not null' };
- rv = validate.check(schema, neg);
+ rv = swiz.check(schema, neg);
assert.ok(rv.is_valid === false, 'null test (negative case)');
+
+ test.finish();
};
-exports['test_validate_equals'] = function() {
+exports['test_swiz_equals'] = function(test, assert) {
var rv;
var schema = {
- a: new V().equals(123)
+ a: new swiz.Valve().equals(123)
};
// positive case
var obj = { a: 123};
var obj_ext = { a: 123, b: 2 };
- rv = validate.check(schema, obj_ext);
+ rv = swiz.check(schema, obj_ext);
assert.ok(rv.is_valid === true, 'equals test');
assert.deepEqual(rv.cleaned, obj);
// negative case
var neg = { a: 'not 123' };
- rv = validate.check(schema, neg);
+ rv = swiz.check(schema, neg);
assert.ok(rv.is_valid === false, 'equals test (negative case)');
+
+ test.finish();
};
-exports['test_validate_present'] = function() {
+exports['test_swiz_present'] = function(test, assert) {
var rv;
var schema = {
- a: new V().notEmpty()
+ a: new swiz.Valve().notEmpty()
};
// positive case
var obj = { a: 123};
var obj_ext = { a: 123, b: 2 };
- rv = validate.check(schema, obj_ext);
- assert.ok(rv.is_valid === true, 'validate present');
+ rv = swiz.check(schema, obj_ext);
+ assert.ok(rv.is_valid === true, 'swiz present');
assert.deepEqual(rv.cleaned, obj);
// negative case
var neg = { b: 2 };
- rv = validate.check(schema, neg);
- assert.ok(rv.is_valid === false, 'validate (negative case)');
+ rv = swiz.check(schema, neg);
+ assert.ok(rv.is_valid === false, 'swiz (negative case)');
+
+ test.finish();
};
-exports['test_validate_contains'] = function() {
+exports['test_swiz_contains'] = function(test, assert) {
var rv;
var schema = {
- a: new V().contains('abc')
+ a: new swiz.Valve().contains('abc')
};
// positive case
var obj = { a: 'abc'};
var obj_ext = { a: 'abc', b: 2 };
- rv = validate.check(schema, obj_ext);
+ rv = swiz.check(schema, obj_ext);
assert.ok(rv.is_valid === true, 'contains test');
assert.deepEqual(rv.cleaned, obj);
// negative case
var neg = { a: '123' };
- rv = validate.check(schema, neg);
+ rv = swiz.check(schema, neg);
assert.ok(rv.is_valid === false, 'contains test (negative case)');
+
+ test.finish();
};
-exports['test_validate_not_contains'] = function() {
+exports['test_swiz_not_contains'] = function(test, assert) {
var rv;
var schema = {
- a: new V().notContains('abc')
+ a: new swiz.Valve().notContains('abc')
};
// positive case
var obj = { a: '123'};
var obj_ext = { a: '123', b: 2 };
- rv = validate.check(schema, obj_ext);
+ rv = swiz.check(schema, obj_ext);
assert.ok(rv.is_valid === true, 'not contains test');
assert.deepEqual(rv.cleaned, obj);
// negative case
var neg = { a: 'abc' };
- rv = validate.check(schema, neg);
+ rv = swiz.check(schema, neg);
assert.ok(rv.is_valid === false, 'not contains test (negative case)');
+
+ test.finish();
};
-exports['test_validate_chain'] = function() {
+exports['test_swiz_chain'] = function(test, assert) {
var rv;
var schema = {
- a: new V().len(1).isNumeric()
+ a: new swiz.Valve().len(1).isNumeric()
};
// positive case
var obj = { a: '1' };
var obj_ext = { a: '1', b: 2 };
- rv = validate.check(schema, obj_ext);
+ rv = swiz.check(schema, obj_ext);
assert.ok(rv.is_valid === true, 'chain test');
assert.deepEqual(rv.cleaned, obj);
// negative case
- rv = validate.check(schema, { a: '' });
+ rv = swiz.check(schema, { a: '' });
assert.ok(rv.is_valid === false, 'chain test (negative case)');
// negative case
- rv = validate.check(schema, { a: 'A' });
+ rv = swiz.check(schema, { a: 'A' });
assert.ok(rv.is_valid === false, 'chain test (negative case)');
+
+ test.finish();
};
-exports['test_validate_nested'] = function() {
+exports['test_swiz_nested'] = function(test, assert) {
var rv;
var schema = {
- a: new V().array(new V().isInt().toInt())
+ a: new swiz.Valve().array(new swiz.Valve().isInt().toInt())
};
// positive case
var obj = { a: [1] };
var obj_ext = { a: ['1'], b: 2 };
- rv = validate.check(schema, obj_ext);
+ rv = swiz.check(schema, obj_ext);
assert.ok(rv.is_valid === true, 'nested test');
assert.deepEqual(rv.cleaned, obj);
+
+ test.finish();
};
-exports['test_validate_tofloat'] = function() {
+exports['test_swiz_tofloat'] = function(test, assert) {
var rv;
var schema = {
- a: new V().array(new V().toFloat())
+ a: new swiz.Valve().array(new swiz.Valve().toFloat())
};
// positive case
var obj = { a: [3.145] };
var obj_ext = { a: ['3.145'], b: 2 };
- rv = validate.check(schema, obj_ext);
+ rv = swiz.check(schema, obj_ext);
assert.ok(rv.is_valid === true, 'tofloat test');
assert.ok(typeof rv.cleaned.a[0] === 'number', 'tofloat === number test');
assert.deepEqual(rv.cleaned, obj);
+
+ test.finish();
};
-exports['test_validate_string'] = function() {
- var rv;
+exports['test_swiz_string'] = function(test, assert) {
+ var rv, obj, obj_ext;
var schema = {
- a: new V().string()
+ a: new swiz.Valve().string()
};
// positive case
- var obj = { a: 'test' };
- var obj_ext = { a: 'test', b: 2 };
- rv = validate.check(schema, obj_ext);
+ obj = { a: 'test' };
+ obj_ext = { a: 'test', b: 2 };
+ rv = swiz.check(schema, obj_ext);
assert.ok(rv.is_valid === true, 'string test');
assert.deepEqual(rv.cleaned, obj);
// negative case
- var obj = { a: 123 };
- var obj_ext = { a: 123, b: 2 };
- rv = validate.check(schema, obj_ext);
+ obj = { a: 123 };
+ obj_ext = { a: 123, b: 2 };
+ rv = swiz.check(schema, obj_ext);
assert.ok(rv.is_valid === false, 'string test (negative case)');
+
+ test.finish();
};
-exports['test_validate_nested_array'] = function() {
+exports['test_swiz_nested_array'] = function(test, assert) {
var rv;
var schema = {
- a: new V().array(new V().string())
+ a: new swiz.Valve().array(new swiz.Valve().string())
};
// positive case
var obj = { a: ['test'] };
var obj_ext = { a: ['test'], b: 2 };
- rv = validate.check(schema, obj_ext);
+ rv = swiz.check(schema, obj_ext);
assert.ok(rv.is_valid === true, 'string test');
assert.deepEqual(rv.cleaned, obj);
+
+ test.finish();
};
-exports['test_validate_nested_hash'] = function() {
+exports['test_swiz_nested_hash'] = function(test, assert) {
var rv;
var schema = {
- a: new V().hash(new V().string(), new V().string())
+ a: new swiz.Valve().hash(new swiz.Valve().string(), new swiz.Valve().string())
};
// positive case
var obj = { a: {'test' : 'test'} };
var obj_ext = { a: {'test' : 'test'}, b: 2 };
- rv = validate.check(schema, obj_ext);
+ rv = swiz.check(schema, obj_ext);
assert.ok(rv.is_valid === true, 'hash test');
assert.deepEqual(rv.cleaned, obj);
+
+ test.finish();
+};
+
+exports['test_swiz_range'] = function(test, assert) {
+ var rv;
+ var schema = {
+ a: new swiz.Valve().range(1, 65535)
+ };
+
+ // positive case
+ var obj = { a: 500 };
+ var obj_ext = { a: 500, b: 2 };
+ rv = swiz.check(schema, obj_ext);
+ assert.ok(rv.is_valid === true, 'range test');
+ assert.deepEqual(rv.cleaned, obj);
+
+ // negative case
+ obj = { a: 65536 };
+ obj_ext = { a: 65536, b: 2 };
+ rv = swiz.check(schema, obj_ext);
+ console.log(rv);
+ assert.ok(rv.is_valid === false, 'range test');
+
+ test.finish();
};
Please sign in to comment.
Something went wrong with that request. Please try again.