Skip to content
This repository was archived by the owner on Apr 27, 2023. It is now read-only.

Commit a860460

Browse files
authored
Merge pull request #19 from zhucebuliaopx/master
fix pr#17 && unit test && add Travis CI
2 parents 294e7ef + c787329 commit a860460

File tree

4 files changed

+90
-4
lines changed

4 files changed

+90
-4
lines changed

.travis.yml

Lines changed: 15 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,15 @@
1+
language: c
2+
3+
env:
4+
- LUA=""
5+
6+
branches:
7+
only:
8+
- master
9+
10+
install:
11+
- sudo apt-get install luarocks
12+
- sudo luarocks install busted
13+
- sudo luarocks make *.rockspec;
14+
15+
script: "busted spec"
Lines changed: 4 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -1,8 +1,9 @@
11
package = "lua-struct"
2-
version = "@VERSION@-@REVISION@"
2+
version = "0.9.2-1"
33

44
source = {
5-
url = "git://github.com/iryont/lua-struct.git"
5+
url = "git://github.com/iryont/lua-struct.git",
6+
tag = "0.9.2-1",
67
}
78

89
description = {
@@ -21,7 +22,7 @@ build = {
2122
type = 'none',
2223
install = {
2324
lua = {
24-
['struct'] = 'struct.lua'
25+
['struct'] = 'src/struct.lua'
2526
}
2627
}
2728
}

spec/struct_spec.lua

Lines changed: 70 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,70 @@
1+
local struct = require "struct"
2+
3+
describe("struct test", function ()
4+
5+
it("test ss", function ()
6+
local s1 = "test1"
7+
local s2 = "test2"
8+
local packed = struct.pack("<ss", s1, s2)
9+
local uns1, uns2 = struct.unpack("<ss", packed)
10+
assert.same(uns1, s1)
11+
assert.same(uns2, s2)
12+
end)
13+
14+
it("test s", function ()
15+
local value = "test"
16+
local packed = struct.pack("<s", value)
17+
local unpacked = struct.unpack("<s", packed)
18+
assert.same(unpacked, value)
19+
end)
20+
21+
it("test L", function ()
22+
local value = 12345678912345678
23+
local packed = struct.pack('<L', value)
24+
local unpacked = struct.unpack('<L', packed)
25+
assert.same(unpacked, value)
26+
end)
27+
28+
it("test I", function ()
29+
local value = 123456789
30+
local packed = struct.pack('<I', value)
31+
local unpacked = struct.unpack('<I', packed)
32+
assert.same(unpacked, value)
33+
end)
34+
35+
it("test h", function ()
36+
local value = -3200
37+
local packed = struct.pack('<h', value)
38+
local unpacked = struct.unpack('<h', packed)
39+
assert.same(unpacked, value)
40+
end)
41+
42+
it("test B", function ()
43+
local value = 255
44+
local packed = struct.pack('<B', value)
45+
local unpacked = struct.unpack('<B', packed)
46+
assert.same(unpacked, value)
47+
end)
48+
49+
it("test b", function ()
50+
local value = -1
51+
local packed = struct.pack('<b', value)
52+
local unpacked = struct.unpack('<b', packed)
53+
assert.same(unpacked, value)
54+
end)
55+
56+
it("test f", function ()
57+
local value = 1.56789
58+
local packed = struct.pack('<f', value)
59+
local unpacked = struct.unpack('<f', packed)
60+
assert.is.truthy(unpacked < value)
61+
end)
62+
63+
it("test d", function ()
64+
local value = 1.56789
65+
local packed = struct.pack('<d', value)
66+
local unpacked = struct.unpack('<d', packed)
67+
assert.same(unpacked, value)
68+
end)
69+
70+
end)

struct.lua renamed to src/struct.lua

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -175,7 +175,7 @@ function struct.unpack(format, stream, pos)
175175
elseif opt == 's' then
176176
local bytes = {}
177177
for j = iterator, stream:len() do
178-
if stream:sub(j) == '' then
178+
if stream:sub(j,j) == string.char(0) or stream:sub(j) == '' then
179179
break
180180
end
181181

0 commit comments

Comments
 (0)