forked from Archives/navigator.lua
github workflow and reference spec test
parent
b292c2b981
commit
72e0b4e1e4
@ -0,0 +1,3 @@
|
|||||||
|
module github.com/navigator/tests
|
||||||
|
|
||||||
|
go 1.17
|
@ -0,0 +1,72 @@
|
|||||||
|
package main
|
||||||
|
|
||||||
|
import (
|
||||||
|
"fmt"
|
||||||
|
"math"
|
||||||
|
//"math"
|
||||||
|
)
|
||||||
|
|
||||||
|
type geometry interface {
|
||||||
|
area() float64
|
||||||
|
perim() float64
|
||||||
|
}
|
||||||
|
|
||||||
|
type rect struct {
|
||||||
|
width float64 `-line:"width"`
|
||||||
|
height float64 `-line:"height"`
|
||||||
|
}
|
||||||
|
|
||||||
|
type rect2 struct {
|
||||||
|
width int `yml:"width"`
|
||||||
|
height int `yml:"height"`
|
||||||
|
}
|
||||||
|
|
||||||
|
func (r rect) area() float64 {
|
||||||
|
return r.width * r.height
|
||||||
|
}
|
||||||
|
|
||||||
|
func (r rect) perim() float64 {
|
||||||
|
return 2*r.width + 2*r.height
|
||||||
|
}
|
||||||
|
|
||||||
|
type circle struct {
|
||||||
|
radius float64
|
||||||
|
}
|
||||||
|
|
||||||
|
func (c circle) area() float64 {
|
||||||
|
return math.Pi * c.radius * c.radius
|
||||||
|
}
|
||||||
|
|
||||||
|
func (c circle) perim() float64 {
|
||||||
|
return 2 * math.Pi * c.radius
|
||||||
|
}
|
||||||
|
|
||||||
|
func measure(g geometry) int {
|
||||||
|
fmt.Println(g)
|
||||||
|
fmt.Println(g.area())
|
||||||
|
fmt.Println(g.perim())
|
||||||
|
return 1
|
||||||
|
}
|
||||||
|
|
||||||
|
func m2() {
|
||||||
|
measure(rect{width: 3})
|
||||||
|
}
|
||||||
|
|
||||||
|
func M2() {
|
||||||
|
measure(rect{width: 3})
|
||||||
|
}
|
||||||
|
|
||||||
|
func runinterface() {
|
||||||
|
r := rect{width: 3, height: 4}
|
||||||
|
c := circle{radius: 5}
|
||||||
|
measure(r)
|
||||||
|
measure(c)
|
||||||
|
d := circle{radius: 10}
|
||||||
|
fmt.Println(d)
|
||||||
|
}
|
||||||
|
|
||||||
|
func main() {
|
||||||
|
M2()
|
||||||
|
m2()
|
||||||
|
runinterface()
|
||||||
|
}
|
@ -0,0 +1,12 @@
|
|||||||
|
package main
|
||||||
|
|
||||||
|
import "fmt"
|
||||||
|
|
||||||
|
func interfaceTest() {
|
||||||
|
r := rect{width: 3, height: 4}
|
||||||
|
c := circle{radius: 5}
|
||||||
|
measure(r)
|
||||||
|
measure(c)
|
||||||
|
d := circle{radius: 10}
|
||||||
|
fmt.Println(d)
|
||||||
|
}
|
@ -0,0 +1,98 @@
|
|||||||
|
local helpers = {}
|
||||||
|
local busted = require("plenary/busted")
|
||||||
|
|
||||||
|
local eq = assert.are.same
|
||||||
|
local cur_dir = vim.fn.expand("%:p:h")
|
||||||
|
-- local status = require("plenary.reload").reload_module("go.nvim")
|
||||||
|
-- status = require("plenary.reload").reload_module("nvim-treesitter")
|
||||||
|
|
||||||
|
-- local ulog = require('go.utils').log
|
||||||
|
describe("should run lsp reference", function()
|
||||||
|
-- vim.fn.readfile('minimal.vim')
|
||||||
|
-- vim.fn.writefile(vim.fn.readfile('fixtures/fmt/hello.go'), name)
|
||||||
|
-- status = require("plenary.reload").reload_module("go.nvim")
|
||||||
|
it("should show references", function()
|
||||||
|
|
||||||
|
local status = require("plenary.reload").reload_module("navigator")
|
||||||
|
local status = require("plenary.reload").reload_module("guihua")
|
||||||
|
|
||||||
|
vim.cmd([[packadd navigator.lua]])
|
||||||
|
vim.cmd([[packadd guihua.lua]])
|
||||||
|
local path = cur_dir .. "/tests/fixtures/interface.go" -- %:p:h ? %:p
|
||||||
|
local cmd = " silent exe 'e " .. path .. "'"
|
||||||
|
vim.cmd(cmd)
|
||||||
|
vim.cmd([[cd %:p:h]])
|
||||||
|
local bufn = vim.fn.bufnr("")
|
||||||
|
require'navigator'.setup({
|
||||||
|
debug = false, -- log output, set to true and log path: ~/.local/share/nvim/gh.log
|
||||||
|
code_action_icon = "A ",
|
||||||
|
width = 0.75, -- max width ratio (number of cols for the floating window) / (window width)
|
||||||
|
height = 0.3, -- max list window height, 0.3 by default
|
||||||
|
preview_height = 0.35, -- max height of preview windows
|
||||||
|
border = 'none'
|
||||||
|
})
|
||||||
|
|
||||||
|
vim.fn.setpos(".", {bufn, 15, 4, 0}) -- width
|
||||||
|
|
||||||
|
vim.bo.filetype = "go"
|
||||||
|
vim.lsp.buf.references()
|
||||||
|
eq(1, 1)
|
||||||
|
end)
|
||||||
|
it("reference handler should return items", function()
|
||||||
|
|
||||||
|
local status = require("plenary.reload").reload_module("navigator")
|
||||||
|
local status = require("plenary.reload").reload_module("guihua")
|
||||||
|
vim.cmd([[packadd navigator.lua]])
|
||||||
|
vim.cmd([[packadd guihua.lua]])
|
||||||
|
local path = cur_dir .. "/tests/fixtures/interface.go" -- %:p:h ? %:p
|
||||||
|
print(path)
|
||||||
|
local cmd = " silent exe 'e " .. path .. "'"
|
||||||
|
vim.cmd(cmd)
|
||||||
|
vim.cmd([[cd %:p:h]])
|
||||||
|
local bufn = vim.fn.bufnr("")
|
||||||
|
|
||||||
|
vim.fn.setpos(".", {bufn, 15, 4, 0}) -- width
|
||||||
|
|
||||||
|
vim.bo.filetype = "go"
|
||||||
|
require'navigator'.setup({
|
||||||
|
debug = false, -- log output, set to true and log path: ~/.local/share/nvim/gh.log
|
||||||
|
code_action_icon = "A ",
|
||||||
|
width = 0.75, -- max width ratio (number of cols for the floating window) / (window width)
|
||||||
|
height = 0.3, -- max list window height, 0.3 by default
|
||||||
|
preview_height = 0.35, -- max height of preview windows
|
||||||
|
border = 'none'
|
||||||
|
})
|
||||||
|
local result = {
|
||||||
|
{
|
||||||
|
range = {['end'] = {character = 6, line = 14}, start = {character = 1, line = 14}},
|
||||||
|
uri = "file://" .. cur_dir .. "/tests/fixtures/interface.go"
|
||||||
|
}, {
|
||||||
|
range = {['end'] = {character = 15, line = 24}, start = {character = 10, line = 24}},
|
||||||
|
uri = "file://" .. cur_dir .. "/tests/fixtures/interface.go"
|
||||||
|
}, {
|
||||||
|
range = {['end'] = {character = 17, line = 28}, start = {character = 12, line = 28}},
|
||||||
|
uri = "file://" .. cur_dir .. "/tests/fixtures/interface.go"
|
||||||
|
}, {
|
||||||
|
range = {['end'] = {character = 19, line = 51}, start = {character = 14, line = 51}},
|
||||||
|
uri = "file://" .. cur_dir .. "/tests/fixtures/interface.go"
|
||||||
|
}, {
|
||||||
|
range = {['end'] = {character = 19, line = 55}, start = {character = 14, line = 55}},
|
||||||
|
uri = "file://" .. cur_dir .. "/tests/fixtures/interface.go"
|
||||||
|
}, {
|
||||||
|
range = {['end'] = {character = 16, line = 59}, start = {character = 11, line = 59}},
|
||||||
|
|
||||||
|
uri = "file://" .. cur_dir .. "/tests/fixtures/interface.go"
|
||||||
|
}, {
|
||||||
|
range = {['end'] = {character = 16, line = 5}, start = {character = 11, line = 5}},
|
||||||
|
uri = "file://" .. cur_dir .. "/tests/fixtures/interface_test.go"
|
||||||
|
}
|
||||||
|
}
|
||||||
|
local win, items, width = require('navigator.reference').reference_handler(nil,
|
||||||
|
"textDocument/references",
|
||||||
|
result, 1, 1)
|
||||||
|
eq(win.ctrl.data[1].display_filename, "./interface.go")
|
||||||
|
eq(win.ctrl.data[2].range.start.line, 14)
|
||||||
|
eq(items[1].display_filename, "./interface.go")
|
||||||
|
eq(width, 60)
|
||||||
|
end)
|
||||||
|
end)
|
Loading…
Reference in New Issue