- 编辑器:多标签、语法高亮、gopls 全套(补全/诊断/跳转/重命名/代码动作/内联提示/签名大纲) - 调试:Delve DAP(断点/条件断点/变量树/表达式求值/goroutine 列表) - 测试:结果树、覆盖率行着色、失败跳源码、-run 精确运行、行号可跑标记 - Git:状态着色、选择性暂存提交、pull/push、历史并排对比 - 本地历史 + 自动快照 + 崩溃恢复、会话/光标恢复 - 全局搜索替换(预览+确认,GBK 安全)、多终端、gopls 崩溃自愈 - 设计文档与验证记录见 docs/plans/
92 lines
2.3 KiB
Go
92 lines
2.3 KiB
Go
package app
|
|
|
|
import (
|
|
"encoding/json"
|
|
"testing"
|
|
)
|
|
|
|
func newBPApp() *App {
|
|
return &App{bps: map[string]map[int]breakpoint{}}
|
|
}
|
|
|
|
func TestToggleBreakpoint(t *testing.T) {
|
|
a := newBPApp()
|
|
a.toggleBreakpoint("a.go", 3)
|
|
if _, ok := a.bps["a.go"][3]; !ok {
|
|
t.Fatal("应当加上断点")
|
|
}
|
|
if !a.bps["a.go"][3].Enabled {
|
|
t.Fatal("新断点默认启用")
|
|
}
|
|
a.toggleBreakpoint("a.go", 3)
|
|
if _, ok := a.bps["a.go"][3]; ok {
|
|
t.Fatal("再点一次应当删除")
|
|
}
|
|
if _, ok := a.bps["a.go"]; ok {
|
|
t.Fatal("文件下没有断点时应把整个条目删掉,避免脏 map")
|
|
}
|
|
}
|
|
|
|
func TestBreakpointConditionAndEnable(t *testing.T) {
|
|
a := newBPApp()
|
|
a.toggleBreakpoint("a.go", 5)
|
|
a.setBreakpointCond("a.go", 5, "i == 3")
|
|
a.setBreakpointEnabled("a.go", 5, false)
|
|
|
|
bp := a.bps["a.go"][5]
|
|
if bp.Cond != "i == 3" || bp.Enabled {
|
|
t.Fatalf("条件/启用状态没设上: %+v", bp)
|
|
}
|
|
|
|
// 对不存在的断点操作不应 panic 也不应凭空创建
|
|
a.setBreakpointCond("a.go", 9, "x")
|
|
if _, ok := a.bps["a.go"][9]; ok {
|
|
t.Fatal("不该给不存在的断点设条件")
|
|
}
|
|
}
|
|
|
|
func TestAllBreakpointsSorted(t *testing.T) {
|
|
a := newBPApp()
|
|
a.toggleBreakpoint("b.go", 2)
|
|
a.toggleBreakpoint("a.go", 9)
|
|
a.toggleBreakpoint("a.go", 4)
|
|
|
|
got := a.allBreakpoints()
|
|
if len(got) != 3 {
|
|
t.Fatalf("应有 3 个断点,实际 %d", len(got))
|
|
}
|
|
if got[0].Path != "a.go" || got[0].Line != 4 ||
|
|
got[1].Path != "a.go" || got[1].Line != 9 ||
|
|
got[2].Path != "b.go" || got[2].Line != 2 {
|
|
t.Fatalf("排序不对: %+v", got)
|
|
}
|
|
}
|
|
|
|
func TestDeleteBreakpoint(t *testing.T) {
|
|
a := newBPApp()
|
|
a.toggleBreakpoint("a.go", 1)
|
|
a.deleteBreakpoint("a.go", 1)
|
|
if len(a.bps) != 0 {
|
|
t.Fatalf("删完应当清空: %+v", a.bps)
|
|
}
|
|
}
|
|
|
|
// TestBPJSONBackCompat 老会话里断点是纯行号数组,升级后不能丢。
|
|
func TestBPJSONBackCompat(t *testing.T) {
|
|
var old []bpJSON
|
|
if err := json.Unmarshal([]byte(`[3,7]`), &old); err != nil {
|
|
t.Fatal(err)
|
|
}
|
|
if len(old) != 2 || old[0].Line != 3 || !old[0].Enabled {
|
|
t.Fatalf("旧格式应解析成启用状态的断点: %+v", old)
|
|
}
|
|
|
|
var neu []bpJSON
|
|
if err := json.Unmarshal([]byte(`[{"line":5,"cond":"i>0","enabled":false}]`), &neu); err != nil {
|
|
t.Fatal(err)
|
|
}
|
|
if len(neu) != 1 || neu[0].Line != 5 || neu[0].Cond != "i>0" || neu[0].Enabled {
|
|
t.Fatalf("新格式解析不对: %+v", neu)
|
|
}
|
|
}
|