47 lines
1.3 KiB
Lua
47 lines
1.3 KiB
Lua
local csexp = require "csexp"
|
|
local serialize, parse = csexp.serialize, csexp.parse
|
|
|
|
local describe, it, expect = lester.describe, lester.it, lester.expect
|
|
|
|
describe("csexp", function()
|
|
describe("serialize", function()
|
|
it("handles empty string", function()
|
|
expect.equal(serialize"", "0:")
|
|
end)
|
|
|
|
it("handles nonempty string", function()
|
|
expect.equal(serialize"abcd", "4:abcd")
|
|
end)
|
|
|
|
it("handles empty list", function()
|
|
expect.equal(serialize{}, "()")
|
|
end)
|
|
|
|
it("converts non-string values", function()
|
|
expect.equal(serialize(12345), "5:12345")
|
|
end)
|
|
|
|
it("inverts parse", function()
|
|
local original = "(10:abcdefghij(5:hello(5:world)7:goodbye))"
|
|
local obj = parse(original)
|
|
local serialized = serialize(obj)
|
|
expect.equal(serialized, original)
|
|
end)
|
|
end)
|
|
|
|
describe("parse", function()
|
|
local rejects = {
|
|
["malformed lists"] = "(5:hello5:world",
|
|
["early eof in strings"] = "5:1234",
|
|
["extra chars in strings"] = "5:123456",
|
|
["extra chars after list"] = "()0:"
|
|
}
|
|
for description, value in pairs(rejects) do
|
|
it("rejects "..description, function()
|
|
expect.fail(function()
|
|
parse(value)
|
|
end)
|
|
end)
|
|
end
|
|
end)
|
|
end) |