Browse Source

EAGLESIX-3003: Cleaned up test cases and some of hte code on the class.

Scott Munday 11 years ago
parent
commit
16f6760777

+ 3 - 5
lib/pipeline/matcher/TypeMatchExpression.js

@@ -46,12 +46,12 @@ proto.shallowClone = function shallowClone(){
 };
 
 /**
- * Used number reference to types like C++.
+ * Used number reference to types like the C++ enum (?).
  *
  * @param e
  * @returns {number}
  */
-var _type = function _type(e) {
+klass.type = function type(e) {
 	if(e === undefined) {
 		return 6;
 	} else if (e === null) {
@@ -66,7 +66,6 @@ var _type = function _type(e) {
 		case 'boolean':
 			return 8;
 		case 'object':
-			console.log(e.constructor);
 			if (e instanceof Array)
 				return 4;
 			if (e instanceof RegExp)
@@ -89,8 +88,7 @@ var _type = function _type(e) {
  * @returns {boolean}
  */
 proto.matchesSingleElement = function matchesSingleElement(e) {
-	console.log(e);
-	return _type() === this._type;
+	return TypeMatchExpression.type(e) === this._type;
 };
 
 /**

+ 71 - 76
test/lib/pipeline/matcher/TypeMatchExpression.js

@@ -5,120 +5,115 @@ var assert = require("assert"),
 
 
 module.exports = {
-	"TypeMatchExpression": {
-		"should match string type": function (){
+	'TypeMatchExpression': {
+		'Should match string type.': function () {
 			var e = new TypeMatchExpression();
-			var s = e.init('', 2 );
 
-			assert.strictEqual(s.code, 'OK');
-			assert.ok( e.matches('abc') );
-			assert.ok( ! e.matches(2) );
+			assert.strictEqual(e.init('', 2).code, 'OK');
 
+			assert.ok(e.matches('abc'));
+			assert.ok(! e.matches(2));
 		},
-		"should match null type": function() {
+
+		'Should match null type.': function () {
 			var e = new TypeMatchExpression();
-			var s = e.init('',10 );
 
-			assert.strictEqual(s.code, 'OK');
-			assert.ok( e.matches(null) );
-			assert.ok( ! e.matches(10) );
+			assert.strictEqual(e.init('', 10).code, 'OK');
 
+			assert.ok(e.matches(null));
+			assert.ok(!e.matches(10));
 		},
-		"should match unknown type": function() {
+
+		'Should match unknown type.': function () {
 			var e = new TypeMatchExpression();
-			var s = e.init('', 1024);
-	
-			assert.strictEqual(s.code, 'OK');
-			assert.ok( ! e.matches(1024) );
-			assert.ok( ! e.matches('abc') );
 
+			assert.strictEqual(e.init('', 1024).code, 'OK');
+
+			assert.ok(!e.matches(1024));
+			assert.ok(!e.matches('abc'));
 		},
-		"should match bool type": function() {
+
+		'Should match bool type.': function () {
 			var e = new TypeMatchExpression();
-			var s = e.init('',8 );
 
-			assert.strictEqual(s.code, 'OK');
-			assert.ok( e.matches(true) );
-			assert.ok( ! e.matches(8) );
+			assert.strictEqual(e.init('', 8).code, 'OK');
 
+			assert.ok(e.matches(true));
+			assert.ok(!e.matches(8));
 		},
-		"should match number type": function() {
+
+		'Should match number type.': function () {
 			var e = new TypeMatchExpression();
 			var s = e.init('a',1 );
 
-			assert.strictEqual(s.code, 'OK');
-			assert.ok( e.matches({'a':[4]}) );	
-			assert.ok( e.matches({'a':[4, 'a']}) );	
-			assert.ok( e.matches({'a':['a', 4]}) );
-			assert.ok( ! e.matches({'a':['a']}) );
-			assert.ok( ! e.matches({'a':[[4]]}) );
+			assert.strictEqual(e.init('a', 1).code, 'OK');
+
+			assert.ok(e.matches({'a':[4]}));
+			assert.ok(e.matches({'a':[4, 'a']}));
+			assert.ok(e.matches({'a':['a', 4]}));
+			assert.ok(!e.matches({'a':['a']}));
+			assert.ok(!e.matches({'a':[[4]]}));
 
 		},
-		"should match array type": function() {
+
+		'Should match array type.': function () {
 			var e = new TypeMatchExpression();
-			var s = e.init('a', 4);
-		
-			assert.strictEqual(s.code, 'OK');
-			assert.ok( ! e.matches({'a':[]}) );	
-			//assert.ok( ! e.matches({'a':[4, 'a']}) );
-			assert.ok( e.matches({'a':[[2]]}) );
-			assert.ok( ! e.matches({'a':'bar'}) );
 
+			assert.strictEqual(e.init('a', 4).code, 'OK');
+
+			assert.ok(!e.matches({a: []}));
+			assert.ok(e.matches({a: [[2]]}));
+			assert.ok(!e.matches({a: 'bar'}));
 		},
-		"should match null type more": function() {
+
+		'Should match null type expanded.': function () {
 			var e = new TypeMatchExpression();
-			var s = e.init('a', 10);
 
-			assert.strictEqual(s.code, 'OK');
-			assert.ok( e.matches({'a':null}) );
-			assert.ok( ! e.matches({'a':4}) );
-			assert.ok( ! e.matches({}));
+			assert.strictEqual(e.init('a', 10).code, 'OK');
+
+			assert.ok(e.matches({a: null}));
+			assert.ok(!e.matches({a: 4}));
+			assert.ok(!e.matches({}));
 
 		},
-		"should match and preserve elemMatchKey": function() {
-			var e = new TypeMatchExpression();
-			var s = e.init('a.b', 2);
-			var m = new MatchDetails();
+
+		'Should match and preserve elemMatchKey.': function () {
+			var e = new TypeMatchExpression()
+				m = new MatchDetails();
+
 			m.requestElemMatchKey();
 
-			assert.strictEqual(s.code, 'OK');
+			assert.strictEqual(e.init('a.b', 2).code, 'OK');
 			
-			assert.ok( ! e.matches({'a':1}, m) );
-			assert.ok( ! m.hasElemMatchKey() );
+			assert.ok(!e.matches({'a':1}, m));
+			assert.ok(!m.hasElemMatchKey());
 			
-			assert.ok( e.matches({'a':{'b':'string'}},m) );
-			assert.ok( ! m.hasElemMatchKey() );
+			assert.ok(e.matches({a: {b: 'string'}}, m));
+			assert.ok(!m.hasElemMatchKey());
 			
-			assert.ok( e.matches({'a':{'b':['string']}},m) );
-			assert.ok( m.hasElemMatchKey() );
-			assert.strictEqual('0', m.elemMatchKey() );
+			assert.ok(e.matches({a: {b: ['string']}}, m));
+			assert.ok(m.hasElemMatchKey());
+			assert.strictEqual('0', m.elemMatchKey());
 
-	
-			assert.ok( e.matches({'a':[2, {'b':['string']}]},m) );
-			assert.ok( m.hasElemMatchKey() );
-			assert.strictEqual('1', m.elemMatchKey() );
+			assert.ok(e.matches({a: [2, {b: ['string']}]}, m));
+			assert.ok(m.hasElemMatchKey());
+			assert.strictEqual('1', m.elemMatchKey());
+		},
 
+		'Should be equivalent': function() {
+			var e = new TypeMatchExpression(),
+				b = new TypeMatchExpression();
+				c = new TypeMatchExpression();
 
+			assert.strictEqual(e.init('a', 2).code, 'OK');
+			assert.strictEqual(b.init('a', 1).code, 'OK');
+			assert.strictEqual(c.init('b', 2).code, 'OK');
 
-		},
-		"should be equivalent": function() {
-			var e = new TypeMatchExpression();
-			var s = e.init('a', 2);
-			var b = new TypeMatchExpression();
-			var c = new TypeMatchExpression();
-
-			assert.strictEqual(s.code, 'OK');
-			s = b.init('a', 1);	
-			assert.strictEqual(s.code, 'OK');
-			s = c.init('b', 2);
-			assert.strictEqual(s.code, 'OK');
-			assert.ok( e.equivalent(e) );
-			assert.ok( !e.equivalent(b) );
-			assert.ok( !e.equivalent(c) );
+			assert.ok(e.equivalent(e));
+			assert.ok(!e.equivalent(b));
+			assert.ok(!e.equivalent(c));
 		}
-
 	}
 };
 
 if (!module.parent)(new(require("mocha"))()).ui("exports").reporter("spec").addFile(__filename).run(process.exit);
-