peachy/tests/test-schema.lua

55 lines
1.4 KiB
Lua
Raw Normal View History

2024-07-18 08:24:28 +00:00
local schema = require "schema"
local sqlite = require "lsqlite3"
local describe, it, expect = lester.describe, lester.it, lester.expect
describe("schema", function()
local db
lester.before(function()
db = sqlite.open_memory()
db:exec("PRAGMA foreign_keys")
schema.setup(db)
end)
lester.after(function()
db:close()
db = nil
end)
describe("new_node_type", function()
it("creates new node types", function()
local node_type_names = {"a", "b", "c", "d"}
for _, name in ipairs(node_type_names) do
schema.new_node_type(db, name)
end
local results = {}
for name in schema.get_node_types(db) do
table.insert(results, name)
end
expect.equal(node_type_names, results)
end)
it("fails when creating a duplicate node type", function()
local function create()
schema.new_node_type(db, "a")
end
create()
expect.fail(create)
end)
end)
describe("quote name", function()
it("quotes names and escapes double quotes", function()
local original = [[My "name" is "Frankie".]]
local expected = [["My ""name"" is ""Frankie""."]]
local actual = schema.quote_name(original)
expect.equal(expected, actual)
end)
end)
describe("parse_node_name", function()
it("returns NULL on non-sexp table names", function()
for val in db:urows("SELECT parse_node_name('not a sexp')") do
expect.not_exist(val)
end
end)
end)
2024-07-18 08:24:28 +00:00
end)