9 files changed,
88 insertions(+),
125 deletions(-)
Author:
Smirnov Oleksandr
ss2316544@gmail.com
Committed by:
GitHub
noreply@github.com
Committed at:
2023-07-21 02:57:46 +0300
Parent:
b5327cd
A
.github/workflows/tests.yml
@@ -0,0 +1,24 @@
+name: tests +on: [push, pull_request] + +jobs: + tests: + strategy: + matrix: + os: [ubuntu-latest] + runs-on: ${{ matrix.os }} + steps: + - uses: actions/checkout@v3 + - name: Install Neovim + shell: bash + run: | + mkdir -p /tmp/nvim + wget -q https://github.com/neovim/neovim/releases/download/nightly/nvim.appimage -O /tmp/nvim/nvim.appimage + cd /tmp/nvim + chmod a+x ./nvim.appimage + ./nvim.appimage --appimage-extract + echo "/tmp/nvim/squashfs-root/usr/bin/" >> $GITHUB_PATH + - name: Run Tests + run: | + nvim --version + nvim --headless -u ./spec/minimal_init.lua -c "PlenaryBustedDirectory spec {minimal_init='./spec/minimal_init.lua', sequential=true}"
A
.luarc.json
@@ -0,0 +1,10 @@
+{ + "diagnostics.globals": [ + "describe", + "it", + "before_each", + "after_each", + "before_all", + "after_all" + ] +}
M
lua/gopher/_utils/init.lua
@@ -9,17 +9,6 @@ end
return next(t) == nil end ----@param s string ----@return string -function utils.rtrim(s) - local n = #s - while n > 0 and s:find("^%s", n) do - n = n - 1 - end - - return s:sub(1, n) -end - ---@param msg string ---@param lvl any function utils.deferred_notify(msg, lvl)
D
@@ -1,41 +0,0 @@
-describe("gopher.config", function() - it("can be required", function() - require "gopher.config" - end) - - it(".setup() when gets empty table not edit config", function() - local c = require "gopher.config" - c.setup {} - - assert.are.same(c.config.commands.go, "go") - assert.are.same(c.config.commands.gomodifytags, "gomodifytags") - assert.are.same(c.config.commands.gotests, "gotests") - assert.are.same(c.config.commands.impl, "impl") - end) - - it(".setup() when get one custom value sets that", function() - local c = require "gopher.config" - c.setup { commands = { - go = "custom_go", - } } - - assert.are.same(c.config.commands.go, "custom_go") - end) - - it(".setup() when get all custom values sets it", function() - local c = require "gopher.config" - c.setup { - commands = { - go = "go1.18", - gomodifytags = "user-gomodifytags", - gotests = "gotests", - impl = "goimpl", - }, - } - - assert.are.same(c.config.commands.go, "go1.18") - assert.are.same(c.config.commands.gomodifytags, "user-gomodifytags") - assert.are.same(c.config.commands.gotests, "gotests") - assert.are.same(c.config.commands.impl, "goimpl") - end) -end)
D
@@ -1,19 +0,0 @@
-describe("gopher._utils", function() - it("can be requried", function() - require "gopher._utils" - end) - - it(".empty() with non-empty talbe", function() - local empty = require("gopher._utils").empty - local res = empty { first = "1", second = 2 } - - assert.are.same(res, false) - end) - - it(".empty() with empty talbe", function() - local empty = require("gopher._utils").empty - local res = empty {} - - assert.are.same(res, true) - end) -end)
A
spec/units/config_spec.lua
@@ -0,0 +1,29 @@
+describe("gopher.config", function() + it(".setup() should provide default when .setup() is not called", function() + local c = require "gopher.config" + + assert.are.same(c.commands.go, "go") + assert.are.same(c.commands.gomodifytags, "gomodifytags") + assert.are.same(c.commands.gotests, "gotests") + assert.are.same(c.commands.impl, "impl") + assert.are.same(c.commands.iferr, "iferr") + assert.are.same(c.commands.dlv, "dlv") + end) + + it(".setup() should change options on users config", function() + local c = require "gopher.config" + c.setup { + commands = { + go = "go1.420", + gomodifytags = "iDontUseRustBtw", + }, + } + + assert.are.same(c.commands.go, "go1.420") + assert.are.same(c.commands.gomodifytags, "iDontUseRustBtw") + assert.are.same(c.commands.gotests, "gotests") + assert.are.same(c.commands.impl, "impl") + assert.are.same(c.commands.iferr, "iferr") + assert.are.same(c.commands.dlv, "dlv") + end) +end)
A
spec/units/utils_spec.lua
@@ -0,0 +1,25 @@
+describe("gopher._utils", function() + local u = require "gopher._utils" + + describe(".is_tbl_empty()", function() + it("it is empty", function() + assert.are.same(true, u.is_tbl_empty {}) + end) + + it("it is not empty", function() + assert.are.same(false, u.is_tbl_empty { first = "1", second = 2 }) + end) + end) + + describe(".sreq()", function() + it("can require existing module", function() + assert.are.same(require "gopher", u.sreq "gopher") + end) + + it("cannot require non-existing module", function() + assert.has.errors(function() + u.sreq "iDontExistBtw" + end) + end) + end) +end)