Software /
code /
prosody
Annotate
spec/net_websocket_frames_spec.lua @ 10049:c523642ea293
util.dependencies: Increase Lua version to warn about to 5.4
No significant problems have been encountered with Lua 5.3 itself, so
apart from some odd problems in LuaExpat it seems about time to declare
it ready.
author | Kim Alvefur <zash@zash.se> |
---|---|
date | Wed, 19 Jun 2019 19:16:09 +0200 |
parent | 9660:7e75c348095b |
child | 10583:624ad69dbaf7 |
child | 11162:ee399a0522cc |
rev | line source |
---|---|
9660
7e75c348095b
net.websocket.frames: Add some brief tests
Kim Alvefur <zash@zash.se>
parents:
diff
changeset
|
1 describe("net.websocket.frames", function () |
7e75c348095b
net.websocket.frames: Add some brief tests
Kim Alvefur <zash@zash.se>
parents:
diff
changeset
|
2 local nwf = require "net.websocket.frames"; |
7e75c348095b
net.websocket.frames: Add some brief tests
Kim Alvefur <zash@zash.se>
parents:
diff
changeset
|
3 |
7e75c348095b
net.websocket.frames: Add some brief tests
Kim Alvefur <zash@zash.se>
parents:
diff
changeset
|
4 local test_frames = { |
7e75c348095b
net.websocket.frames: Add some brief tests
Kim Alvefur <zash@zash.se>
parents:
diff
changeset
|
5 simple_empty = { |
7e75c348095b
net.websocket.frames: Add some brief tests
Kim Alvefur <zash@zash.se>
parents:
diff
changeset
|
6 ["opcode"] = 0; |
7e75c348095b
net.websocket.frames: Add some brief tests
Kim Alvefur <zash@zash.se>
parents:
diff
changeset
|
7 ["length"] = 0; |
7e75c348095b
net.websocket.frames: Add some brief tests
Kim Alvefur <zash@zash.se>
parents:
diff
changeset
|
8 ["data"] = ""; |
7e75c348095b
net.websocket.frames: Add some brief tests
Kim Alvefur <zash@zash.se>
parents:
diff
changeset
|
9 ["FIN"] = false; |
7e75c348095b
net.websocket.frames: Add some brief tests
Kim Alvefur <zash@zash.se>
parents:
diff
changeset
|
10 ["MASK"] = false; |
7e75c348095b
net.websocket.frames: Add some brief tests
Kim Alvefur <zash@zash.se>
parents:
diff
changeset
|
11 ["RSV1"] = false; |
7e75c348095b
net.websocket.frames: Add some brief tests
Kim Alvefur <zash@zash.se>
parents:
diff
changeset
|
12 ["RSV2"] = false; |
7e75c348095b
net.websocket.frames: Add some brief tests
Kim Alvefur <zash@zash.se>
parents:
diff
changeset
|
13 ["RSV3"] = false; |
7e75c348095b
net.websocket.frames: Add some brief tests
Kim Alvefur <zash@zash.se>
parents:
diff
changeset
|
14 }; |
7e75c348095b
net.websocket.frames: Add some brief tests
Kim Alvefur <zash@zash.se>
parents:
diff
changeset
|
15 simple_data = { |
7e75c348095b
net.websocket.frames: Add some brief tests
Kim Alvefur <zash@zash.se>
parents:
diff
changeset
|
16 ["opcode"] = 0; |
7e75c348095b
net.websocket.frames: Add some brief tests
Kim Alvefur <zash@zash.se>
parents:
diff
changeset
|
17 ["length"] = 5; |
7e75c348095b
net.websocket.frames: Add some brief tests
Kim Alvefur <zash@zash.se>
parents:
diff
changeset
|
18 ["data"] = "hello"; |
7e75c348095b
net.websocket.frames: Add some brief tests
Kim Alvefur <zash@zash.se>
parents:
diff
changeset
|
19 ["FIN"] = false; |
7e75c348095b
net.websocket.frames: Add some brief tests
Kim Alvefur <zash@zash.se>
parents:
diff
changeset
|
20 ["MASK"] = false; |
7e75c348095b
net.websocket.frames: Add some brief tests
Kim Alvefur <zash@zash.se>
parents:
diff
changeset
|
21 ["RSV1"] = false; |
7e75c348095b
net.websocket.frames: Add some brief tests
Kim Alvefur <zash@zash.se>
parents:
diff
changeset
|
22 ["RSV2"] = false; |
7e75c348095b
net.websocket.frames: Add some brief tests
Kim Alvefur <zash@zash.se>
parents:
diff
changeset
|
23 ["RSV3"] = false; |
7e75c348095b
net.websocket.frames: Add some brief tests
Kim Alvefur <zash@zash.se>
parents:
diff
changeset
|
24 }; |
7e75c348095b
net.websocket.frames: Add some brief tests
Kim Alvefur <zash@zash.se>
parents:
diff
changeset
|
25 simple_fin = { |
7e75c348095b
net.websocket.frames: Add some brief tests
Kim Alvefur <zash@zash.se>
parents:
diff
changeset
|
26 ["opcode"] = 0; |
7e75c348095b
net.websocket.frames: Add some brief tests
Kim Alvefur <zash@zash.se>
parents:
diff
changeset
|
27 ["length"] = 0; |
7e75c348095b
net.websocket.frames: Add some brief tests
Kim Alvefur <zash@zash.se>
parents:
diff
changeset
|
28 ["data"] = ""; |
7e75c348095b
net.websocket.frames: Add some brief tests
Kim Alvefur <zash@zash.se>
parents:
diff
changeset
|
29 ["FIN"] = true; |
7e75c348095b
net.websocket.frames: Add some brief tests
Kim Alvefur <zash@zash.se>
parents:
diff
changeset
|
30 ["MASK"] = false; |
7e75c348095b
net.websocket.frames: Add some brief tests
Kim Alvefur <zash@zash.se>
parents:
diff
changeset
|
31 ["RSV1"] = false; |
7e75c348095b
net.websocket.frames: Add some brief tests
Kim Alvefur <zash@zash.se>
parents:
diff
changeset
|
32 ["RSV2"] = false; |
7e75c348095b
net.websocket.frames: Add some brief tests
Kim Alvefur <zash@zash.se>
parents:
diff
changeset
|
33 ["RSV3"] = false; |
7e75c348095b
net.websocket.frames: Add some brief tests
Kim Alvefur <zash@zash.se>
parents:
diff
changeset
|
34 }; |
7e75c348095b
net.websocket.frames: Add some brief tests
Kim Alvefur <zash@zash.se>
parents:
diff
changeset
|
35 } |
7e75c348095b
net.websocket.frames: Add some brief tests
Kim Alvefur <zash@zash.se>
parents:
diff
changeset
|
36 |
7e75c348095b
net.websocket.frames: Add some brief tests
Kim Alvefur <zash@zash.se>
parents:
diff
changeset
|
37 describe("build", function () |
7e75c348095b
net.websocket.frames: Add some brief tests
Kim Alvefur <zash@zash.se>
parents:
diff
changeset
|
38 local build = nwf.build; |
7e75c348095b
net.websocket.frames: Add some brief tests
Kim Alvefur <zash@zash.se>
parents:
diff
changeset
|
39 it("works", function () |
7e75c348095b
net.websocket.frames: Add some brief tests
Kim Alvefur <zash@zash.se>
parents:
diff
changeset
|
40 assert.equal("\0\0", build(test_frames.simple_empty)); |
7e75c348095b
net.websocket.frames: Add some brief tests
Kim Alvefur <zash@zash.se>
parents:
diff
changeset
|
41 assert.equal("\0\5hello", build(test_frames.simple_data)); |
7e75c348095b
net.websocket.frames: Add some brief tests
Kim Alvefur <zash@zash.se>
parents:
diff
changeset
|
42 assert.equal("\128\0", build(test_frames.simple_fin)); |
7e75c348095b
net.websocket.frames: Add some brief tests
Kim Alvefur <zash@zash.se>
parents:
diff
changeset
|
43 end); |
7e75c348095b
net.websocket.frames: Add some brief tests
Kim Alvefur <zash@zash.se>
parents:
diff
changeset
|
44 end); |
7e75c348095b
net.websocket.frames: Add some brief tests
Kim Alvefur <zash@zash.se>
parents:
diff
changeset
|
45 |
7e75c348095b
net.websocket.frames: Add some brief tests
Kim Alvefur <zash@zash.se>
parents:
diff
changeset
|
46 describe("parse", function () |
7e75c348095b
net.websocket.frames: Add some brief tests
Kim Alvefur <zash@zash.se>
parents:
diff
changeset
|
47 local parse = nwf.parse; |
7e75c348095b
net.websocket.frames: Add some brief tests
Kim Alvefur <zash@zash.se>
parents:
diff
changeset
|
48 it("works", function () |
7e75c348095b
net.websocket.frames: Add some brief tests
Kim Alvefur <zash@zash.se>
parents:
diff
changeset
|
49 assert.same(test_frames.simple_empty, parse("\0\0")); |
7e75c348095b
net.websocket.frames: Add some brief tests
Kim Alvefur <zash@zash.se>
parents:
diff
changeset
|
50 assert.same(test_frames.simple_data, parse("\0\5hello")); |
7e75c348095b
net.websocket.frames: Add some brief tests
Kim Alvefur <zash@zash.se>
parents:
diff
changeset
|
51 assert.same(test_frames.simple_fin, parse("\128\0")); |
7e75c348095b
net.websocket.frames: Add some brief tests
Kim Alvefur <zash@zash.se>
parents:
diff
changeset
|
52 end); |
7e75c348095b
net.websocket.frames: Add some brief tests
Kim Alvefur <zash@zash.se>
parents:
diff
changeset
|
53 end); |
7e75c348095b
net.websocket.frames: Add some brief tests
Kim Alvefur <zash@zash.se>
parents:
diff
changeset
|
54 |
7e75c348095b
net.websocket.frames: Add some brief tests
Kim Alvefur <zash@zash.se>
parents:
diff
changeset
|
55 end); |
7e75c348095b
net.websocket.frames: Add some brief tests
Kim Alvefur <zash@zash.se>
parents:
diff
changeset
|
56 |