Software / code / prosody
Comparison
spec/net_websocket_frames_spec.lua @ 9660:7e75c348095b 0.11
net.websocket.frames: Add some brief tests
These are mostly just recordings of minimal input roundtripped back into tables.
| author | Kim Alvefur <zash@zash.se> |
|---|---|
| date | Thu, 29 Nov 2018 17:20:49 +0100 |
| child | 10583:624ad69dbaf7 |
| child | 11162:ee399a0522cc |
comparison
equal
deleted
inserted
replaced
| 9655:e9b8982e3b5d | 9660:7e75c348095b |
|---|---|
| 1 describe("net.websocket.frames", function () | |
| 2 local nwf = require "net.websocket.frames"; | |
| 3 | |
| 4 local test_frames = { | |
| 5 simple_empty = { | |
| 6 ["opcode"] = 0; | |
| 7 ["length"] = 0; | |
| 8 ["data"] = ""; | |
| 9 ["FIN"] = false; | |
| 10 ["MASK"] = false; | |
| 11 ["RSV1"] = false; | |
| 12 ["RSV2"] = false; | |
| 13 ["RSV3"] = false; | |
| 14 }; | |
| 15 simple_data = { | |
| 16 ["opcode"] = 0; | |
| 17 ["length"] = 5; | |
| 18 ["data"] = "hello"; | |
| 19 ["FIN"] = false; | |
| 20 ["MASK"] = false; | |
| 21 ["RSV1"] = false; | |
| 22 ["RSV2"] = false; | |
| 23 ["RSV3"] = false; | |
| 24 }; | |
| 25 simple_fin = { | |
| 26 ["opcode"] = 0; | |
| 27 ["length"] = 0; | |
| 28 ["data"] = ""; | |
| 29 ["FIN"] = true; | |
| 30 ["MASK"] = false; | |
| 31 ["RSV1"] = false; | |
| 32 ["RSV2"] = false; | |
| 33 ["RSV3"] = false; | |
| 34 }; | |
| 35 } | |
| 36 | |
| 37 describe("build", function () | |
| 38 local build = nwf.build; | |
| 39 it("works", function () | |
| 40 assert.equal("\0\0", build(test_frames.simple_empty)); | |
| 41 assert.equal("\0\5hello", build(test_frames.simple_data)); | |
| 42 assert.equal("\128\0", build(test_frames.simple_fin)); | |
| 43 end); | |
| 44 end); | |
| 45 | |
| 46 describe("parse", function () | |
| 47 local parse = nwf.parse; | |
| 48 it("works", function () | |
| 49 assert.same(test_frames.simple_empty, parse("\0\0")); | |
| 50 assert.same(test_frames.simple_data, parse("\0\5hello")); | |
| 51 assert.same(test_frames.simple_fin, parse("\128\0")); | |
| 52 end); | |
| 53 end); | |
| 54 | |
| 55 end); | |
| 56 |