[mirror] Make your go dev experience better github.com/olexsmir/gopher.nvim
neovim golang
at main 1.5 kB view raw
1local t = require "spec.testutils" 2local _, T, utils = t.setup "utils" 3 4utils["should .remove_empty_lines()"] = function() 5 local u = require "gopher._utils" 6 local inp = { "hi", "", "a", "", "", "asdf" } 7 8 t.eq(u.remove_empty_lines(inp), { "hi", "a", "asdf" }) 9end 10 11utils["should .readfile_joined()"] = function() 12 local data = "line1\nline2\nline3" 13 local tmp = t.tmpfile() 14 local u = require "gopher._utils" 15 16 t.writefile(tmp, data) 17 t.eq(u.readfile_joined(tmp), data) 18end 19 20utils["should .trimend()"] = function() 21 local u = require "gopher._utils" 22 t.eq(u.trimend " hi ", " hi") 23end 24 25utils["should add .indent() spaces"] = function() 26 local u = require "gopher._utils" 27 local line = " func Test() error {" 28 local indent = 4 29 30 t.eq(" ", u.indent(line, indent)) 31end 32 33utils["should add .indent() a tab"] = function() 34 local u = require "gopher._utils" 35 local line = "\tfunc Test() error {" 36 local indent = 1 37 38 t.eq("\t", u.indent(line, indent)) 39end 40 41utils["should add .indent() 2 tabs"] = function() 42 local u = require "gopher._utils" 43 local line = "\t\tfunc Test() error {" 44 local indent = 2 45 46 t.eq("\t\t", u.indent(line, indent)) 47end 48 49utils["should .list_unique on list with duplicates"] = function() 50 local u = require "gopher._utils" 51 t.eq({ "json", "xml" }, u.list_unique { "json", "xml", "json" }) 52end 53 54utils["should .list_unique on list with no duplicates"] = function() 55 local u = require "gopher._utils" 56 t.eq({ "json", "xml" }, u.list_unique { "json", "xml" }) 57end 58 59return T