第 9 项。原报告 4.5 判断「编辑器无右键菜单」是错的:框架 ui/editor 自带完整菜单(跳转定义、剪切/复制/粘贴、全选、切换注释、选区/转换/ 折叠三个子菜单),State.ContextMenu 只是留给应用层的追加点。所以本次 不重造菜单,只往那个追加点里填应用层独有的 16 项: - gopls:代码动作、查找引用、重命名符号(要求 Go 文件 + LSP 在线, 改文本的还要求非只读) - 编辑:格式化文档、在文件中查找 - 测试:运行光标处的测试 / 当前包(只在 _test.go 出现,普通文件里挂 一个永远点不动的项是噪音,而它一旦可点又会退化成跑全部测试) - 定位:在项目树中定位、在资源管理器中显示、本地历史 - 剪贴板:复制相对路径 / 绝对路径 菜单项造在纯函数 editorMenuItems(editorMenuCap) 里,可用性由 goFile/lspReady/inRoot/onDisk/readOnly 五个事实决定;条件插入容易留下 连着两条分隔线或末尾挂一条,统一由 compactEditorMenu 收口。 验证不止单测:TestEditorMenuShowsInEditor 用 ui.NewTester 真把编辑器 渲染出来、真右击、读 tt.Menu() 的菜单文案,再 ChooseMenuItem 走完 「菜单 → 动作 → 剪贴板」整条链路,并断言灰掉的项点不动。框架文档明确 说右键菜单不能用 automation 插座驱动,所以走 Tester 这条路。 顺带一次 gofmt -w 把全仓 gofmt -l 清空(13 个文件,多是 CRLF 与文档 注释空格),并更正报告 4.5、补齐执行状态。 其余"本周做"项(回收站删除、参数引号切分 + Env/WorkDir、日志轮转、 标签同名区分)一并入库。
64 lines
1.8 KiB
Go
64 lines
1.8 KiB
Go
package app
|
|
|
|
import (
|
|
"testing"
|
|
|
|
"github.com/egoist/mygo/ui/editor"
|
|
)
|
|
|
|
func docAt(p string) *Doc { return &Doc{path: p, buf: editor.NewBuffer("")} }
|
|
|
|
// TestTabLabelUnique 没有重名就只显示文件名。
|
|
func TestTabLabelUnique(t *testing.T) {
|
|
a := &App{docs: []*Doc{docAt("/w/main.go"), docAt("/w/util.go")}}
|
|
if got := a.tabLabel(a.docs[0]); got != "main.go" {
|
|
t.Fatalf("got %q", got)
|
|
}
|
|
}
|
|
|
|
// TestTabLabelSameName 同名时带上能区分的那一层目录。
|
|
func TestTabLabelSameName(t *testing.T) {
|
|
a := &App{docs: []*Doc{docAt("/w/a/main.go"), docAt("/w/b/main.go")}}
|
|
if got := a.tabLabel(a.docs[0]); got != "a/main.go" {
|
|
t.Fatalf("第一个标签 = %q, 想要 a/main.go", got)
|
|
}
|
|
if got := a.tabLabel(a.docs[1]); got != "b/main.go" {
|
|
t.Fatalf("第二个标签 = %q, 想要 b/main.go", got)
|
|
}
|
|
}
|
|
|
|
// TestTabLabelDeeper 一层不够时继续往上取。
|
|
func TestTabLabelDeeper(t *testing.T) {
|
|
a := &App{docs: []*Doc{
|
|
docAt("/w/internal/x/main.go"),
|
|
docAt("/w/cmd/x/main.go"),
|
|
}}
|
|
got0 := a.tabLabel(a.docs[0])
|
|
got1 := a.tabLabel(a.docs[1])
|
|
if got0 == got1 {
|
|
t.Fatalf("两个标签仍重名:%q", got0)
|
|
}
|
|
if got0 != "internal/x/main.go" {
|
|
t.Fatalf("got %q", got0)
|
|
}
|
|
}
|
|
|
|
// TestTabLabelWindowsPath Windows 反斜杠路径也要正确切段。
|
|
func TestTabLabelWindowsPath(t *testing.T) {
|
|
a := &App{docs: []*Doc{
|
|
docAt(`D:\w\a\main.go`),
|
|
docAt(`D:\w\b\main.go`),
|
|
}}
|
|
if got := a.tabLabel(a.docs[0]); got != "a/main.go" {
|
|
t.Fatalf("got %q", got)
|
|
}
|
|
}
|
|
|
|
// TestTabLabelCaseInsensitive 大小写不同的同名文件也算重名(Windows 语义)。
|
|
func TestTabLabelCaseInsensitive(t *testing.T) {
|
|
a := &App{docs: []*Doc{docAt("/w/a/Main.go"), docAt("/w/b/main.go")}}
|
|
if got := a.tabLabel(a.docs[0]); got == "Main.go" {
|
|
t.Fatalf("大小写同名应加目录区分,got %q", got)
|
|
}
|
|
}
|