Commits

Shu Zong Chen  committed 5a5218b

moving test values to separate file

  • Participants
  • Parent commits a344dcb

Comments (0)

Files changed (2)

File test/test_values.js

+var ord = function(c){ return c.charCodeAt(0); };
+
+values = {};
+
+values.simple = [
+	["NULL", null, [0xc0]],
+	["FALSE", false, [0xc2]],
+	["TRUE", true, [0xc3]],
+	["0", 0, [0x00]],
+	["127", 127, [0x7f]],
+	["128", 128, [0xcc, 0x80]],
+	["256", 256, [0xcd, 0x01, 0x00]],
+	["-1", -1, [0xff]],
+	["-33", -33, [0xd0, 0xdf]],
+	["-129", -129, [0xd1, 0xff, 0x7f]],
+	["'foo' string", "foo", [0xa3, ord('f'), ord('o'), ord('o')]],
+	["'bar' string", "bar", [0xa3, ord('b'), ord('a'), ord('r')]],
+	["'foobar' string", "foobar", [0xa6, ord('f'), ord('o'), ord('o'), ord('b'), ord('a'), ord('r')]],
+	["float 0", 0, [0xca, 0x00, 0x00, 0x00, 0x00]],
+	["float inf", Infinity, [0xca, 0x7f, 0x80, 0x00, 0x00]],
+	["float -inf", -Infinity, [0xca, 0xff, 0x80, 0x00, 0x00]],
+	["float NaN", NaN, [0xca, 0x7f, 0xc0, 0x00, 0x00]],
+	["float 1/3", 0.3333333432674408, [0xca, 0x3e, 0xaa, 0xaa, 0xab]],
+	["float 0.9", 0.8999999761581421, [0xca, 0x3f, 0x66, 0x66, 0x66]],
+	["float 1", 1.0, [0xca, 0x3f, 0x80, 0x00, 0x00]],
+	["float -2", -2.0, [0xca, 0xc0, 0x00, 0x00, 0x0]],
+	["float 25", 25, [0xca, 0x41, 0xc8, 0x00, 0x0]],
+	["double 0", 0, [0xcb, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00]],
+	["double inf", Infinity, [0xcb, 0x7f, 0xf0, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00]],
+	["double -inf", -Infinity, [0xcb, 0xff, 0xf0, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00]],
+	["double NaN", NaN, [0xcb, 0x7f, 0xf8, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00]],
+	["double 1/3", 0.3333333333333428, [0xcb, 0x3f, 0xd5, 0x55, 0x55, 0x55, 0x55, 0x55, 0x55]],
+	["double 1", 1.0, [0xcb, 0x3f, 0xf0, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00]],
+	["double 2", 2.0, [0xcb, 0x40, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00]],
+	["double -2", -2.0, [0xcb, 0xc0, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00]],
+];
+
+values.complex = [
+	["Empty array", [], [0x90]],
+	["Empty object", {}, [0x80]],
+	["Object {foo:bar}", {"foo":"bar"}, [0x81, 0xa3, ord('f'), ord('o'), ord('o'), 0xa3, ord('b'), ord('a'), ord('r')]],
+	["Array of 0~14", [0,1,2,3,4,5,6,7,8,9,10,11,12,13,14], [0x9f, 0x00, 0x01, 0x02, 0x03, 0x04, 0x05, 0x06, 0x07, 0x08, 0x09, 0x0a, 0x0b, 0x0c, 0x0d, 0x0e]],
+	["Array of 0~15", [0,1,2,3,4,5,6,7,8,9,10,11,12,13,14,15], [0xdc, 0x00, 0x10, 0x00, 0x01, 0x02, 0x03, 0x04, 0x05, 0x06, 0x07, 0x08, 0x09, 0x0a, 0x0b, 0x0c, 0x0d, 0x0e, 0x0f]],
+	["Map of {a:a, b:b, c:c, ..., o:o}",
+		{'a':'a', 'b':'b', 'c':'c', 'd':'d', 'e':'e', 'f':'f', 'g':'g', 'h':'h', 'i':'i', 'j':'j', 'k':'k', 'l':'l', 'm':'m', 'n':'n', 'o':'o'},
+		[0x8f,
+			0xa1, ord('a'),
+			0xa1, ord('a'),
+			0xa1, ord('b'),
+			0xa1, ord('b'),
+			0xa1, ord('c'),
+			0xa1, ord('c'),
+			0xa1, ord('d'),
+			0xa1, ord('d'),
+			0xa1, ord('e'),
+			0xa1, ord('e'),
+			0xa1, ord('f'),
+			0xa1, ord('f'),
+			0xa1, ord('g'),
+			0xa1, ord('g'),
+			0xa1, ord('h'),
+			0xa1, ord('h'),
+			0xa1, ord('i'),
+			0xa1, ord('i'),
+			0xa1, ord('j'),
+			0xa1, ord('j'),
+			0xa1, ord('k'),
+			0xa1, ord('k'),
+			0xa1, ord('l'),
+			0xa1, ord('l'),
+			0xa1, ord('m'),
+			0xa1, ord('m'),
+			0xa1, ord('n'),
+			0xa1, ord('n'),
+			0xa1, ord('o'),
+			0xa1, ord('o'),
+		]
+	],
+]
+
+module.exports = values;

File test/unpack-test.js

 var vows = require('vows');
 var assert = require('assert');
 var msgpack = require('../msgpack.js');
+var values = require('./test_values.js');
 
 var chr = String.fromCharCode;
-var ord = function(c){ return c.charCodeAt(0); };
-
-var simple_matches = [
-	["NULL", null, [0xc0]],
-	["FALSE", false, [0xc2]],
-	["TRUE", true, [0xc3]],
-	["0", 0, [0x00]],
-	["127", 127, [0x7f]],
-	["128", 128, [0xcc, 0x80]],
-	["256", 256, [0xcd, 0x01, 0x00]],
-	["-1", -1, [0xff]],
-	["-33", -33, [0xd0, 0xdf]],
-	["-129", -129, [0xd1, 0xff, 0x7f]],
-	["'foo' string", "foo", [0xa3, ord('f'), ord('o'), ord('o')]],
-	["'bar' string", "bar", [0xa3, ord('b'), ord('a'), ord('r')]],
-	["'foobar' string", "foobar", [0xa6, ord('f'), ord('o'), ord('o'), ord('b'), ord('a'), ord('r')]],
-	["float 0", 0, [0xca, 0x00, 0x00, 0x00, 0x00]],
-	["float inf", Infinity, [0xca, 0x7f, 0x80, 0x00, 0x00]],
-	["float -inf", -Infinity, [0xca, 0xff, 0x80, 0x00, 0x00]],
-	["float NaN", NaN, [0xca, 0x7f, 0xc0, 0x00, 0x00]],
-	["float 1/3", 0.3333333432674408, [0xca, 0x3e, 0xaa, 0xaa, 0xab]],
-	["float 0.9", 0.8999999761581421, [0xca, 0x3f, 0x66, 0x66, 0x66]],
-	["float 1", 1.0, [0xca, 0x3f, 0x80, 0x00, 0x00]],
-	["float -2", -2.0, [0xca, 0xc0, 0x00, 0x00, 0x0]],
-	["float 25", 25, [0xca, 0x41, 0xc8, 0x00, 0x0]],
-	["double 0", 0, [0xcb, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00]],
-	["double inf", Infinity, [0xcb, 0x7f, 0xf0, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00]],
-	["double -inf", -Infinity, [0xcb, 0xff, 0xf0, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00]],
-	["double NaN", NaN, [0xcb, 0x7f, 0xf8, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00]],
-	["double 1/3", 0.3333333333333428, [0xcb, 0x3f, 0xd5, 0x55, 0x55, 0x55, 0x55, 0x55, 0x55]],
-	["double 1", 1.0, [0xcb, 0x3f, 0xf0, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00]],
-	["double 2", 2.0, [0xcb, 0x40, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00]],
-	["double -2", -2.0, [0xcb, 0xc0, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00]],
-];
 
 SimpleBatch = {};
 SimpleBatch['topic'] = new(msgpack.Unpacker);
-simple_matches.forEach(function(i){
+values.simple.forEach(function(i){
 	var name = i[0];
 	var value = i[1];
 	var _result = i[2].map(function(i){ return chr(i);});
 }
 });
 
-var complex_matches = [
-	["Empty array", [], [0x90]],
-	["Empty object", {}, [0x80]],
-	["Object {foo:bar}", {"foo":"bar"}, [0x81, 0xa3, ord('f'), ord('o'), ord('o'), 0xa3, ord('b'), ord('a'), ord('r')]],
-	["Array of 0~14", [0,1,2,3,4,5,6,7,8,9,10,11,12,13,14], [0x9f, 0x00, 0x01, 0x02, 0x03, 0x04, 0x05, 0x06, 0x07, 0x08, 0x09, 0x0a, 0x0b, 0x0c, 0x0d, 0x0e]],
-	["Array of 0~15", [0,1,2,3,4,5,6,7,8,9,10,11,12,13,14,15], [0xdc, 0x00, 0x10, 0x00, 0x01, 0x02, 0x03, 0x04, 0x05, 0x06, 0x07, 0x08, 0x09, 0x0a, 0x0b, 0x0c, 0x0d, 0x0e, 0x0f]],
-	["Map of {a:a, b:b, c:c, ..., o:o}",
-		{'a':'a', 'b':'b', 'c':'c', 'd':'d', 'e':'e', 'f':'f', 'g':'g', 'h':'h', 'i':'i', 'j':'j', 'k':'k', 'l':'l', 'm':'m', 'n':'n', 'o':'o'},
-		[0x8f,
-			0xa1, ord('a'),
-			0xa1, ord('a'),
-			0xa1, ord('b'),
-			0xa1, ord('b'),
-			0xa1, ord('c'),
-			0xa1, ord('c'),
-			0xa1, ord('d'),
-			0xa1, ord('d'),
-			0xa1, ord('e'),
-			0xa1, ord('e'),
-			0xa1, ord('f'),
-			0xa1, ord('f'),
-			0xa1, ord('g'),
-			0xa1, ord('g'),
-			0xa1, ord('h'),
-			0xa1, ord('h'),
-			0xa1, ord('i'),
-			0xa1, ord('i'),
-			0xa1, ord('j'),
-			0xa1, ord('j'),
-			0xa1, ord('k'),
-			0xa1, ord('k'),
-			0xa1, ord('l'),
-			0xa1, ord('l'),
-			0xa1, ord('m'),
-			0xa1, ord('m'),
-			0xa1, ord('n'),
-			0xa1, ord('n'),
-			0xa1, ord('o'),
-			0xa1, ord('o'),
-		]
-	],
-]
-
 ComplexBatch = {};
 ComplexBatch['topic'] = new(msgpack.Unpacker);
-complex_matches.forEach(function(i){
+values.complex.forEach(function(i){
 	var name = i[0];
 	var value = i[1];
 	var _result = i[2].map(function(i){ return String.fromCharCode(i);});