MyGoland 首次提交:Go 轻量 IDE
- 编辑器:多标签、语法高亮、gopls 全套(补全/诊断/跳转/重命名/代码动作/内联提示/签名大纲) - 调试:Delve DAP(断点/条件断点/变量树/表达式求值/goroutine 列表) - 测试:结果树、覆盖率行着色、失败跳源码、-run 精确运行、行号可跑标记 - Git:状态着色、选择性暂存提交、pull/push、历史并排对比 - 本地历史 + 自动快照 + 崩溃恢复、会话/光标恢复 - 全局搜索替换(预览+确认,GBK 安全)、多终端、gopls 崩溃自愈 - 设计文档与验证记录见 docs/plans/
This commit is contained in:
commit
a80c0f886a
220 files changed
+20784
No files matched your search
@@ -0,0 +1,86 @@
|
||||
package lsp
|
||||
|
||||
import (
|
||||
"runtime"
|
||||
"testing"
|
||||
)
|
||||
|
||||
func TestPathURIRoundTrip(t *testing.T) {
|
||||
var path string
|
||||
if runtime.GOOS == "windows" {
|
||||
path = `D:\WorkSpaces\测试\main.go`
|
||||
} else {
|
||||
path = "/home/user/测试/main.go"
|
||||
}
|
||||
uri := PathToURI(path)
|
||||
got := URIToPath(uri)
|
||||
if got != path {
|
||||
t.Fatalf("round trip: got %q want %q (uri %q)", got, path, uri)
|
||||
}
|
||||
}
|
||||
|
||||
func TestOffsetPositionCJK(t *testing.T) {
|
||||
text := "package main\n\nfunc 你好() {\n\tprintln(1)\n}\n"
|
||||
// 第二行开头(换行后)应是 Line 1, Character 0。
|
||||
off := len("package main\n")
|
||||
if got := OffsetToPosition(text, off); got != (Position{Line: 1, Character: 0}) {
|
||||
t.Fatalf("line start: %+v", got)
|
||||
}
|
||||
// "func " 之后是 4 个 ASCII 字符,中文每个占 1 个 UTF-16 码元。
|
||||
off2 := len("package main\n\nfunc ")
|
||||
if got := OffsetToPosition(text, off2); got != (Position{Line: 2, Character: 5}) {
|
||||
t.Fatalf("after func: %+v", got)
|
||||
}
|
||||
// 中文后位置:5 + 2 = 7。
|
||||
off3 := off2 + len("你好")
|
||||
if got := OffsetToPosition(text, off3); got != (Position{Line: 2, Character: 7}) {
|
||||
t.Fatalf("after cjk: %+v", got)
|
||||
}
|
||||
if back := PositionToOffset(text, Position{Line: 2, Character: 7}); back != off3 {
|
||||
t.Fatalf("back: got %d want %d", back, off3)
|
||||
}
|
||||
}
|
||||
|
||||
func TestLenSurrogatePair(t *testing.T) {
|
||||
// 表情符号占 2 个 UTF-16 码元。
|
||||
if got := UTF16Len("a😀b"); got != 4 {
|
||||
t.Fatalf("UTF16Len: got %d want 4", got)
|
||||
}
|
||||
if got := UTF16ToByte("a😀b", 3); got != len("a😀") {
|
||||
t.Fatalf("UTF16ToByte: got %d want %d", got, len("a😀"))
|
||||
}
|
||||
}
|
||||
|
||||
func TestDiffChange(t *testing.T) {
|
||||
tests := []struct {
|
||||
name string
|
||||
old, new string
|
||||
text string
|
||||
ok bool
|
||||
}{
|
||||
{"insert", "package main\n", "package main\n\n", "\n", true},
|
||||
{"replace cjk", "var 甲 = 1", "var 乙 = 1", "乙", true},
|
||||
{"delete", "abc\ndef", "abc", "", true},
|
||||
{"same", "abc", "abc", "", false},
|
||||
}
|
||||
for _, tt := range tests {
|
||||
t.Run(tt.name, func(t *testing.T) {
|
||||
r, text, ok := DiffChange(tt.old, tt.new)
|
||||
if ok != tt.ok {
|
||||
t.Fatalf("ok: got %v want %v", ok, tt.ok)
|
||||
}
|
||||
if !ok {
|
||||
return
|
||||
}
|
||||
if text != tt.text {
|
||||
t.Fatalf("text: got %q want %q", text, tt.text)
|
||||
}
|
||||
// 用 range 把改动应用回 old,结果必须等于 new。
|
||||
start := PositionToOffset(tt.old, r.Start)
|
||||
end := PositionToOffset(tt.old, r.End)
|
||||
if applied := tt.old[:start] + text + tt.old[end:]; applied != tt.new {
|
||||
t.Fatalf("apply: got %q want %q", applied, tt.new)
|
||||
}
|
||||
})
|
||||
}
|
||||
}
|
||||
Reference in new issue
Block a user