Files
MyGolandRelease/internal/app/debug_test.go
T
zerorigin a80c0f886a MyGoland 首次提交:Go 轻量 IDE
- 编辑器:多标签、语法高亮、gopls 全套(补全/诊断/跳转/重命名/代码动作/内联提示/签名大纲)
- 调试:Delve DAP(断点/条件断点/变量树/表达式求值/goroutine 列表)
- 测试:结果树、覆盖率行着色、失败跳源码、-run 精确运行、行号可跑标记
- Git:状态着色、选择性暂存提交、pull/push、历史并排对比
- 本地历史 + 自动快照 + 崩溃恢复、会话/光标恢复
- 全局搜索替换(预览+确认,GBK 安全)、多终端、gopls 崩溃自愈
- 设计文档与验证记录见 docs/plans/
2026-11-04 16:37:05 +08:00

79 lines
1.9 KiB
Go

package app
import "testing"
func TestVisibleVarsFlatten(t *testing.T) {
s := &debugSession{
children: map[int][]debugVar{
10: {
{Name: "X", Type: "int", Value: "1", Ref: 0},
{Name: "Y", Type: "string", Value: "\"a\"", Ref: 11, HasChildren: true},
},
11: {
{Name: "len", Type: "int", Value: "1"},
},
},
expanded: map[int]bool{},
roots: []debugVar{
{Name: "n", Type: "int", Value: "0"},
{Name: "s", Type: "struct", Value: "{...}", Ref: 10, HasChildren: true},
},
}
a := &App{}
got := a.visibleVars(s)
if len(got) != 2 {
t.Fatalf("未展开时应只有 2 个根变量,实际 %d: %+v", len(got), got)
}
if got[0].Name != "n" || got[0].Depth != 0 {
t.Fatalf("第一个变量异常: %+v", got[0])
}
s.expanded[10] = true
got = a.visibleVars(s)
if len(got) != 4 {
t.Fatalf("展开一层后应有 4 行,实际 %d: %+v", len(got), got)
}
if got[2].Name != "X" || got[2].Depth != 1 {
t.Fatalf("子变量缩进不对: %+v", got[2])
}
if got[3].Name != "Y" || got[3].Depth != 1 {
t.Fatalf("子变量缩进不对: %+v", got[3])
}
s.expanded[11] = true
got = a.visibleVars(s)
if len(got) != 5 {
t.Fatalf("展开两层后应有 5 行,实际 %d: %+v", len(got), got)
}
if got[4].Name != "len" || got[4].Depth != 2 {
t.Fatalf("二级缩进不对: %+v", got[4])
}
}
func TestSortInts(t *testing.T) {
xs := []int{9, 3, 12, 3}
sortInts(xs)
want := []int{3, 3, 9, 12}
for i := range want {
if xs[i] != want[i] {
t.Fatalf("排序结果 %v,期望 %v", xs, want)
}
}
}
func TestSkipFile(t *testing.T) {
cases := map[string]bool{
"__debug_bin.exe": true,
"__debug_bin123.exe": true,
"main.go": false,
"app.exe": true,
"greeter_test.go": false,
}
for name, want := range cases {
if got := skipFile(name); got != want {
t.Fatalf("skipFile(%q) = %v,期望 %v", name, got, want)
}
}
}