Skip to content

Commit

Permalink
feat: add tests for utils (wip)
Browse files Browse the repository at this point in the history
this commit includes tests for str_to_lines and lines_to_str

It include `pending` tests for the remaining utils
  • Loading branch information
aarondill committed Jan 16, 2024
1 parent 2426970 commit d748e97
Showing 1 changed file with 132 additions and 0 deletions.
132 changes: 132 additions & 0 deletions tests/utils_spec.lua
Original file line number Diff line number Diff line change
@@ -0,0 +1,132 @@
local utils = require("tabnine.utils")
local eq = assert.same

describe("utils", function()
describe("debounce", function()
pending("TODO")
-- utils.debounce(func, delay)
end)

describe("str_to_lines", function()
it("splits on newlines", function()
local lines = utils.str_to_lines("Hello\nworld")
eq({ "Hello", "world" }, lines)
end)
--- TODO: Should it? This is different than lines_to_str
it("trims leading and trailing newlines", function()
local lines = utils.str_to_lines("\nHello\nworld\n")
eq({ "Hello", "world" }, lines)
end)
it("includes empty lines", function()
local lines = utils.str_to_lines("Hello\n\nworld")
eq({ "Hello", "", "world" }, lines)
end)
it("includes consecutive empty lines", function()
local lines = utils.str_to_lines("Hello\n\n\n\n\nworld")
eq({ "Hello", "", "", "", "", "world" }, lines)
end)
end)

describe("lines_to_str", function()
it("joins on newlines", function()
local str = utils.lines_to_str({ "Hello", "world" })
eq("Hello\nworld", str)
end)
it("includes leading and trailing newlines", function()
local str = utils.lines_to_str({ "", "Hello", "world", "" })
eq("\nHello\nworld\n", str)
end)
it("includes empty lines", function()
local str = utils.lines_to_str({ "Hello", "", "world" })
eq("Hello\n\nworld", str)
end)
it("includes consecutive empty lines", function()
local str = utils.lines_to_str({ "Hello", "", "", "", "", "world" })
eq("Hello\n\n\n\n\nworld", str)
end)
it("is the inverse of str_to_lines", function()
local str = "Hello\n\n\n\nWorld\n\rWith" .. string.char(27) .. "escapes"
eq(str, utils.lines_to_str(utils.str_to_lines(str)))
end)
end)

describe("remove_matching_suffix", function()
pending("TODO")
-- utils.remove_matching_suffix(str, suffix)
end)

describe("remove_matching_prefix", function()
pending("TODO")
-- utils.remove_matching_prefix(str, prefix)
end)

describe("subset", function()
pending("TODO")
-- utils.subset(tbl, from, to)
end)

describe("script_path", function()
pending("TODO")
-- utils.script_path()
end)

describe("prequire", function()
pending("TODO")
-- utils.prequire("")
end)

describe("pumvisible", function()
pending("TODO")
-- utils.pumvisible()
end)

describe("current_position", function()
pending("TODO")
-- utils.current_position()
end)

describe("ends_with", function()
pending("TODO")
-- utils.ends_with(str, suffix)
end)

describe("starts_with", function()
pending("TODO")
-- utils.starts_with(str, prefix)
end)

describe("is_end_of_line", function()
pending("TODO")
-- utils.is_end_of_line()
end)

describe("end_of_line", function()
pending("TODO")
-- utils.end_of_line()
end)

describe("document_changed", function()
pending("TODO")
-- utils.document_changed()
end)

describe("selected_text", function()
pending("TODO")
-- utils.selected_text()
end)

describe("set", function()
pending("TODO")
-- utils.set(array)
end)

describe("select_range", function()
pending("TODO")
-- utils.select_range(range)
end)

describe("select_range", function()
pending("TODO")
-- utils.select_range(range)
end)
end)

0 comments on commit d748e97

Please sign in to comment.