Permalink
Browse files

Adding more functions to assert modules

assert.defined, assert.undefined, assert.null, assert.notNull are added
  • Loading branch information...
ssuda
ssuda committed Mar 6, 2012
1 parent 0613af0 commit bddbeb5267ffd0a13600d923b16cab001d326075
Showing with 33 additions and 0 deletions.
  1. +24 −0 lib/assert.js
  2. +9 −0 test/simple/test-assert.js
View
@@ -334,3 +334,27 @@ assert.doesNotThrow = function(block, /*optional*/error, /*optional*/message) {
};
assert.ifError = function(err) { if (err) {throw err;}};
+
+assert.defined = function(value, message) {
+ if (value === undefined) {
+ fail(value, 'defined', message, 'defined', assert.defined);
+ }
+}
+
+assert.undefined = function(value, message) {
+ if (value !== undefined) {
+ fail(value, undefined, message, 'undefined', assert.undefined);
+ }
+}
+
+assert.null = function(value, message) {
+ if (value !== null) {
+ fail(value, 'notNull', message, 'null', assert.null);
+ }
+}
+
+assert.notNull = function(value, message) {
+ if (value === null) {
+ fail(value, null, message, 'notNull', assert.notNull);
+ }
+}
@@ -283,3 +283,12 @@ testAssertionMessage({a: undefined, b: null}, '{"a":"undefined","b":null}');
testAssertionMessage({a: NaN, b: Infinity, c: -Infinity},
'{"a":"NaN","b":"Infinity","c":"-Infinity"}');
+
+assert.doesNotThrow(makeBlock(a.defined, 'a'));
+assert.throws(makeBlock(a.defined, undefined));
+assert.doesNotThrow(makeBlock(a.undefined, undefined));
+assert.throws(makeBlock(a.undefined, 'a'));
+assert.doesNotThrow(makeBlock(a.null, null));
+assert.throws(makeBlock(a.null, 'a'));
+assert.doesNotThrow(makeBlock(a.notNull, 'a'));
+assert.throws(makeBlock(a.notNull, null));

0 comments on commit bddbeb5

Please sign in to comment.