Skip to content

Commit 31e286a

Browse files
committed
Add regression tests for B#21
Three tests are added, checking both the reported bug (certain values to format p will crash vstruct) and the underlying bug that causes it (fractional values to formats i and u are not truncated properly).
1 parent 0f63b92 commit 31e286a

2 files changed

Lines changed: 28 additions & 0 deletions

File tree

vstruct/test.lua

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -32,6 +32,7 @@ require "vstruct.test.basic"
3232
require "vstruct.test.fp-bigendian"
3333
require "vstruct.test.fp-littleendian"
3434
require "vstruct.test.error"
35+
require "vstruct.test.regression"
3536

3637
if arg and #arg > 0 then
3738
require "vstruct.test.struct-test-gen"

vstruct/test/regression.lua

Lines changed: 27 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,27 @@
1+
-- regression tests for vstruct
2+
-- tests for fixed bugs go here to make sure they don't recur
3+
-- tests are named after the bug they trigger, not the intended behaviour
4+
5+
local test = require "vstruct.test.common"
6+
7+
local x = test.x
8+
local T = test.autotest
9+
10+
test.group "regression tests"
11+
12+
-- B#21
13+
-- this was found as an error in packing fixed point values, but is actually an underlying issue
14+
-- with how u and i handle non-integer inputs
15+
-- in short: don't assume string.char() truncates, because it doesn't.
16+
T("i rounds instead of truncating",
17+
"> i2",
18+
x"FF FF", -1.5,
19+
x"FF FF", -1)
20+
T("u rounds instead of truncating",
21+
"> u2",
22+
x"00 01", 1.5,
23+
x"00 01", 1)
24+
T("p passes invalid value to string.char and crashes",
25+
"> p2,2",
26+
x"FD 00", -192.098910,
27+
x"FD 00", -192.00)

0 commit comments

Comments
 (0)