This repository has been archived by the owner on Apr 27, 2023. It is now read-only.
-
Notifications
You must be signed in to change notification settings - Fork 29
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
Merge pull request #19 from zhucebuliaopx/master
fix pr#17 && unit test && add Travis CI
- Loading branch information
Showing
4 changed files
with
90 additions
and
4 deletions.
There are no files selected for viewing
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,15 @@ | ||
language: c | ||
|
||
env: | ||
- LUA="" | ||
|
||
branches: | ||
only: | ||
- master | ||
|
||
install: | ||
- sudo apt-get install luarocks | ||
- sudo luarocks install busted | ||
- sudo luarocks make *.rockspec; | ||
|
||
script: "busted spec" |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,70 @@ | ||
local struct = require "struct" | ||
|
||
describe("struct test", function () | ||
|
||
it("test ss", function () | ||
local s1 = "test1" | ||
local s2 = "test2" | ||
local packed = struct.pack("<ss", s1, s2) | ||
local uns1, uns2 = struct.unpack("<ss", packed) | ||
assert.same(uns1, s1) | ||
assert.same(uns2, s2) | ||
end) | ||
|
||
it("test s", function () | ||
local value = "test" | ||
local packed = struct.pack("<s", value) | ||
local unpacked = struct.unpack("<s", packed) | ||
assert.same(unpacked, value) | ||
end) | ||
|
||
it("test L", function () | ||
local value = 12345678912345678 | ||
local packed = struct.pack('<L', value) | ||
local unpacked = struct.unpack('<L', packed) | ||
assert.same(unpacked, value) | ||
end) | ||
|
||
it("test I", function () | ||
local value = 123456789 | ||
local packed = struct.pack('<I', value) | ||
local unpacked = struct.unpack('<I', packed) | ||
assert.same(unpacked, value) | ||
end) | ||
|
||
it("test h", function () | ||
local value = -3200 | ||
local packed = struct.pack('<h', value) | ||
local unpacked = struct.unpack('<h', packed) | ||
assert.same(unpacked, value) | ||
end) | ||
|
||
it("test B", function () | ||
local value = 255 | ||
local packed = struct.pack('<B', value) | ||
local unpacked = struct.unpack('<B', packed) | ||
assert.same(unpacked, value) | ||
end) | ||
|
||
it("test b", function () | ||
local value = -1 | ||
local packed = struct.pack('<b', value) | ||
local unpacked = struct.unpack('<b', packed) | ||
assert.same(unpacked, value) | ||
end) | ||
|
||
it("test f", function () | ||
local value = 1.56789 | ||
local packed = struct.pack('<f', value) | ||
local unpacked = struct.unpack('<f', packed) | ||
assert.is.truthy(unpacked < value) | ||
end) | ||
|
||
it("test d", function () | ||
local value = 1.56789 | ||
local packed = struct.pack('<d', value) | ||
local unpacked = struct.unpack('<d', packed) | ||
assert.same(unpacked, value) | ||
end) | ||
|
||
end) |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters