Browse Source

EAGLESIX-2651: Value: stub tests; mv _coerceToNumber to coerceToNumber and add docs for this minor deviation

Kyle P Davis 11 years ago
parent
commit
9ec141c961
2 changed files with 107 additions and 61 deletions
  1. 8 8
      lib/pipeline/Value.js
  2. 99 53
      test/lib/pipeline/Value.js

+ 8 - 8
lib/pipeline/Value.js

@@ -35,10 +35,10 @@ klass.coerceToBool = function coerceToBool(value) {
  *  These currently assert if called on an unconvertible type.
  *  TODO: decided how to handle unsupported types.
  */
-klass.coerceToInt =
-klass.coerceToLong =
-klass.coerceToDouble =
-klass._coerceToNumber = function _coerceToNumber(value) {
+//SKIPPED: coerceToInt -- use coerceToNumber
+//SKIPPED:  coerceToLong -- use coerceToNumber
+//SKIPPED:  coerceToDouble -- use coerceToNumber
+klass.coerceToNumber = function coerceToNumber(value) {
 	if (value === null) return 0;
 	switch (typeof(value)) {
 	case "undefined":
@@ -117,13 +117,13 @@ klass.compare = function compare(l, r) {
 	}
 	// Compare MinKey and MaxKey cases
 	if(l.constructor && l.constructor.name in {'MinKey':1,'MaxKey':1} ){
-		if(l.constructor.name == r.constructor.name) { 
-			return 0; 
+		if(l.constructor.name == r.constructor.name) {
+			return 0;
 		} else if (l.constructor.name === 'MinKey'){
 			return -1;
 		} else {
 			return 1; // Must be MaxKey, which is greater than everything but MaxKey (which r cannot be)
-		}	
+		}
 	}
 	// hack: These should really get converted to their BSON type ids and then compared, we use int vs object in queries
 	if (lt === "number" && rt === "object"){
@@ -258,6 +258,6 @@ klass.canonicalize = function canonicalize(x) {
 			return 65;
 		default:
 			// Default value for Object
-			return 20;  
+			return 20;
 	}
 };

+ 99 - 53
test/lib/pipeline/Value.js

@@ -2,72 +2,118 @@
 var assert = require("assert"),
 	Value = require("../../../lib/pipeline/Value");
 
-module.exports = {
+// Mocha one-liner to make these tests self-hosted
+if(!module.parent)return(require.cache[__filename]=null,(new(require("mocha"))({ui:"exports",reporter:"spec",grep:process.env.TEST_GREP})).addFile(__filename).run(process.exit));
 
-	"Value": {
+exports.Value = {
 
-		"#ctor": {
+	".constructor()": {
 
-			"should throw an error when used": function ctorThrows() {
-				assert.throws(function() {
-					var val = new Value();
-				});
-			}
+		"should throw an error when used": function ctorThrows() {
+			assert.throws(function() {
+				new Value();
+			});
+		}
+
+	},
+
+	".coerceToBool()": {
 
+		"should be tested": function(){
+			assert.equal("TESTS", "NO");
 		},
 
-		"#consume": {
+	},
 
-			"should return an equivalent array, empty the original":function works() {
-				var testArray = [5,6,"hi"],
-					result = Value.consume(testArray);
-				assert.deepEqual([5,6,"hi"], result); // tests that insides were copied
-				assert.notEqual(testArray, result);   // tests that a new array was returned
-				assert.equal(testArray.length, 0);    // tests that the old array was emptied
-			},
+	".coerceToNumber()": {
+
+		"should be tested": function(){
+			assert.equal("TESTS", "NO");
+		},
 
-			"should work given an empty array":function worksWhenEmpty() {
-				var testArray = [],
-					result = Value.consume(testArray);
-				assert.deepEqual([], result);
-				assert.equal(testArray.length, 0);
-			}
+	},
 
+	".coerceToDate()": {
+
+		"should be tested": function(){
+			assert.equal("TESTS", "NO");
 		},
 
-		"#compare": {
-
-			"follows canonical type order when types differ": function throwsWhenDiffTypes() {
-				var a = 5,
-					b = "hi",
-					actual = Value.compare(a,b);
-				assert.equal(actual, -1);
-			},
-
-			"should compare two numbers": function comparesNumbers() {
-				var a = 5,
-					b = 6,
-					actual = Value.compare(a,b);
-				assert.equal(actual, -1);
-			},
-
-			"should compare two strings": function comparesStrings() {
-				var a = 'a',
-					b = 'b',
-					actual = Value.compare(b,a);
-				assert.equal(actual, 1);
-			},
-
-			"should detect the same object": function compareSameObj() {
-				var a = {},
-					b = a,
-					actual = Value.compare(a,b);
-				assert.equal(actual, 0);
-			}
+	},
+
+	".coerceToString()": {
+
+		"should be tested": function(){
+			assert.equal("TESTS", "NO");
+		},
+
+	},
+
+	".cmp()": {
+
+		"should be tested": function(){
+			assert.equal("TESTS", "NO");
+		},
+
+	},
+
+	".compare()": {
+
+		"follows canonical type order when types differ": function throwsWhenDiffTypes() {
+			var a = 5,
+				b = "hi",
+				actual = Value.compare(a,b);
+			assert.equal(actual, -1);
+		},
 
+		"should compare two numbers": function comparesNumbers() {
+			var a = 5,
+				b = 6,
+				actual = Value.compare(a,b);
+			assert.equal(actual, -1);
+		},
+
+		"should compare two strings": function comparesStrings() {
+			var a = "a",
+				b = "b",
+				actual = Value.compare(b,a);
+			assert.equal(actual, 1);
+		},
+
+		"should detect the same object": function compareSameObj() {
+			var a = {},
+				b = a,
+				actual = Value.compare(a,b);
+			assert.equal(actual, 0);
+		}
+
+	},
+
+	".consume()": {
+
+		"should return an equivalent array, empty the original":function works() {
+			var testArray = [5,6,"hi"],
+				result = Value.consume(testArray);
+			assert.deepEqual([5,6,"hi"], result); // tests that insides were copied
+			assert.notEqual(testArray, result);   // tests that a new array was returned
+			assert.equal(testArray.length, 0);    // tests that the old array was emptied
+		},
+
+		"should work given an empty array":function worksWhenEmpty() {
+			var testArray = [],
+				result = Value.consume(testArray);
+			assert.deepEqual([], result);
+			assert.equal(testArray.length, 0);
 		}
 
+	},
+
+	".canonicalize()": {
+
+		"should be tested": function(){
+			assert.equal("TESTS", "NO");
+		},
+
 	}
-};
 
-if (!module.parent)(new(require("mocha"))()).ui("exports").reporter("spec").addFile(__filename).grep(process.env.MOCHA_GREP || '').run(process.exit);
+};