Skip to content
Open
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
2 changes: 1 addition & 1 deletion set-0.2.1-1.rockspec
Original file line number Diff line number Diff line change
Expand Up @@ -13,7 +13,7 @@ description = {
license = "LGPL+"
}
dependencies = {
"lua >= 5.2",
"lua >= 5.1",
"lunitx >= 0.6"
}
build = {
Expand Down
25 changes: 25 additions & 0 deletions set-0.2.1-2.rockspec
Original file line number Diff line number Diff line change
@@ -0,0 +1,25 @@
package = "set"
version = "0.2.1-2"
source = {
url = "git://github.com/wscherphof/lua-set.git",
branch = "v0.2.1"
}
description = {
summary = "Straightforward Set library",
detailed = [[
Creating and manipulating sets, including + (union), - (subtraction), * (intersection), len(), and tostring()
]],
homepage = "http://wscherphof.github.io/lua-set/",
license = "LGPL+"
}
dependencies = {
"lua >= 5.1",
"lunitx >= 0.6"
}
build = {
type = "builtin",
copy_directories = {"doc", "tst"},
modules = {
["Set.init"] = "src/Set/init.lua"
}
}
23 changes: 21 additions & 2 deletions tst/init.lua
Original file line number Diff line number Diff line change
@@ -1,6 +1,6 @@
require("luarocks.loader")
-- Omit next line in actual module clients; it's only to support development of the module itself
package.path = "../src/?/init.lua;" .. package.path
package.path = "../src/?/init.lua;" .. "./src/?/init.lua;" .. package.path

local lunitx = require("lunitx")
module("test_set", lunitx.testcase, package.seeall)
Expand Down Expand Up @@ -36,7 +36,26 @@ end
function test_tostring()
assert_equal(Set.mt.__tostring(Set:new({1, 2, 3})), "{1, 2, 3}")
assert_equal(9, #Set.mt.__tostring(Set:new({"a", "b", "c"})), "{a, b, c} (or in a different permutation)")
assert_equal(23, #Set.mt.__tostring(Set:new({ {} })), "{table: 0x7ff498c52ea0} (but a different same-length key)")
local expected_length;
-- this will be 18 on lua5.2, 19 on luajit, and either 17 or 18 on lua5.1 randomly
-- those numbers might totally change on a 32 bit architecture.
expected_length = #(tostring({}))+2;
if _VERSION == 'Lua 5.1' then
if jit then
weird = 19 ~= expected_length;
else
if(expected_length ~= 17 and expected_length ~= 18) then
weird = true
end
end
else
weird = 18 ~= expected_length
end
if weird then
print('Warning: expected_length of tostring(table) was sort of weird: '..expected_length)
end

assert_equal(expected_length, #Set.mt.__tostring(Set:new({ {} })), "{table: 0x7ff498c52ea0} (but a different same-length key)")
end

function test_new_len()
Expand Down