-
Notifications
You must be signed in to change notification settings - Fork 22
/
index.html
120 lines (111 loc) · 3.48 KB
/
index.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
100
101
102
103
104
105
106
107
108
109
110
111
112
113
114
115
116
117
118
119
120
<!doctype html>
<html>
<head>
<meta http-equiv="Content-Type" content="text/html; charset=UTF-8" />
<title>Msgpack</title>
<style>
#heading {
display: inline-block;
}
#test-running {
display: inline-block;
}
#test-success {
display: none;
}
#test-fail {
color: red;
display: none;
}
.passed {
background-color: #8f8;
color: #000;
}
.failed {
background-color: #f22;
color: #000;
font-weight: bold;
}
</style>
</head>
<body>
<h1 id="heading">Msgpack</h1>
<h2 id="test-running"> - running...</h2>
<h2 id="test-success"> - succeeded</h2>
<h2 id="test-fail"> - FAILED</h2>
<table>
<thead>
<tr>
<th>Input</th>
<th>Encoded</th>
<th>Decoded</th>
</tr>
</thead>
<tbody></tbody>
</table>
<script src="msgpack.js"></script>
<script>
/* jshint browser: true */
/* global console, msgpack */
function Buffer(string) {
var buffer = new ArrayBuffer(msgpack.utf8ByteCount(string));
var view = new DataView(buffer);
msgpack.utf8Write(view, 0, string);
return buffer;
}
var tests = [
"$", "¢", "€",
"임창진",
true, false, null, undefined,
0, 1, -1, 2, -2, 4, -4, 6, -6,
0x10, -0x10, 0x20, -0x20, 0x40, -0x40,
0x80, -0x80, 0x100, -0x100, 0x200, -0x200,
0x1000, -0x1000, 0x10000, -0x10000,
0x20000, -0x20000, 0x40000,-0x40000,
10, 100, 1000, 10000, 100000, 1000000,
-10, -100, -1000, -10000, -100000, -1000000,
'hello', 'world', Buffer("Hello"), Buffer("World"),
[1,2,3], [], {name: "Tim", age: 29}, {},
{a: 1, b: 2, c: [1, 2, 3]}, [[],[]],
"fixstr-890123456789012345678901",
"str8-678901234567890123456789012",
];
var body = document.querySelector("tbody");
var statusRun = document.getElementById("test-running");
var statusSuccess = document.getElementById("test-success");
var statusFail = document.getElementById("test-fail");
tests.forEach(function (value) {
var tr = document.createElement("tr");
var tdIn = document.createElement("td");
var tdEnc = document.createElement("td");
var tdOut = document.createElement("td");
tdIn.textContent = String(value);
tr.appendChild(tdIn);
tr.appendChild(tdEnc);
tr.appendChild(tdOut);
tr.setAttribute("class", "failed");
body.appendChild(tr);
try {
var valueString = msgpack.inspect(value);
tdIn.textContent = valueString;
var buffer = msgpack.encode(value);
tdEnc.textContent = msgpack.inspect(buffer);
var decoded = msgpack.decode(buffer);
var decodedString = msgpack.inspect(decoded);
tdOut.textContent = decodedString;
var passed = valueString === decodedString;
console[(passed ? "log" : "error")](value, msgpack.inspect(buffer), decoded);
tr.setAttribute("class", passed ? "passed" : "failed");
}
catch(err) {
tdOut.textContent = "Exception: " + err.message;
statusRun.style.display = "none";
statusFail.style.display = "inline-block";
throw err;
}
});
statusRun.style.display = "none";
statusSuccess.style.display = "inline-block";
</script>
</body>
</html>