/
test_pack.html
executable file
·99 lines (95 loc) · 2.91 KB
/
test_pack.html
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
<html>
<head>
<title> test </title>
<script language="JavaScript" type="text/javascript"
src="./jsunit/app/jsUnitCore.js">
</script>
<script language="JavaScript" type="text/javascript"
src="./msgpack.js">
</script>
<script language="JavaScript" type="text/javascript">
if(MessagePack.hasVBS){
// quick hack for Internet Explorer unescape();
execScript(
'Function msgpack_getByte(data, pos)\r\n' +
' msgpack_getByte = AscB(MidB(data, 2*pos + 1, 1))\r\n'+
'End Function\r\n' , "VBScript"
);
}
function _test_pack(value, hex){
var data = MessagePack.pack(value);
var pp = "\"" + hex.replace(/../g, "\\x$&") + "\""
var str = eval(pp);
if(value == 0.1){
var s = "";
for(var i = 0; i < data.length; ++i){
s += data.charCodeAt(i).toString(16);
}
}
assertEquals(str, data);
}
function test_pack_positive_fixnum() {
_test_pack(0, "00");
}
function test_pack_negative_fixnum() {
_test_pack(-1, "ff");
}
function test_pack_uint8() {
_test_pack(255, "ccff");
}
function test_pack_FixRaw() {
_test_pack("a", "a161");
}
function test_pack_FixArray() {
_test_pack([0], "9100");
}
function test_pack_FixMap() {
_test_pack({"a": 64}, "81a16140");
}
function test_pack_Nil() {
_test_pack(null, "c0");
}
function test_pack_True() {
_test_pack(true, "c3");
}
function test_pack_False() {
_test_pack(false, "c2");
}
function test_pack_double() {
_test_pack(0.1, "cb3fb999999999999a");
}
function test_pack_uint16() {
_test_pack(32768, "cd8000");
}
function test_pack_uint32() {
_test_pack(1048576, "ce00100000");
}
function test_pack_int8() {
_test_pack(-64, "d0c0");
}
function test_pack_int16() {
_test_pack(-1024, "d1fc00");
}
function test_pack_int32() {
_test_pack(-1048576, "d2fff00000");
}
function test_pack_int64() {
_test_pack(-1099511627776, "d3ffffff0000000000");
}
function test_pack_raw16() {
var spaces = " ";
_test_pack(spaces, "da002820202020202020202020202020202020202020202020202020202020202020202020202020202020");
}
function test_pack_array16() {
var ary = [0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0];
_test_pack(ary, "dc001000000000000000000000000000000000");
}
function test_pack_hiragana() {
//var data = MessagePack.pack("あい");
//assertEquals("hiragana ai", data, "\x");
}
</script>
</head>
<body>
</body>
</html>