turbo-editors/turbo-corepublic Fork 0
v1.0.0
Commits
Clone
git clone https://git.rickub.com/turbo-editors/turbo-core.git
git clone ssh://git@rickub.com/turbo-editors/turbo-core.git

Host key fingerprint (ed25519): SHA256:iycHnxEyq0Q7uyVpB7JlznP0G7JrTPXLYRcAU5CSLhc — verify it before your first connect.

diagnostics_test.go · 83 lines · 3.1 KBGo Blame HistoryRaw
🛟 Updated. 28d5985 k33g 20h ago1package app
2
3import (
4 "path/filepath"
5 "testing"
6
📦 Turbo Core f3ade8d k33g 13h ago7 "rickub.com/turbo-editors/turbo-core/lsp"
🛟 Updated. 28d5985 k33g 20h ago8)
9
10func TestDiagnosticsAreFoundForAFileOpenedByARelativePath(t *testing.T) {
11 // Found by driving the real editor against a real gopls: the Problems
12 // window listed two errors and the gutter showed none, because the two
13 // sides spell the file differently. A server publishes absolute URIs; a
14 // buffer opened as "turbo-go main.go" holds the relative path it was
15 // given. The status bar had been failing the same way since long before
16 // the marks existed, silently, because an editor with no error to show and
17 // an editor that cannot find the error look identical.
18 project := t.TempDir()
19 t.Chdir(project)
20 t.Setenv(testProfile().SnippetDirEnvVar(), t.TempDir())
21 a, _ := newTestApp(t)
22
23 writeTestFile(t, filepath.Join(project, "main.go"), "package main\n\nfunc main() { x }\n")
24 a.Open("main.go") // relative, as the command line gives it
25
26 a.language.receiveDiagnostics(filepath.Join(project, "main.go"), []lsp.Diagnostic{
27 {Message: "undefined: x", Severity: lsp.SeverityError, Range: lsp.Range{Start: lsp.Position{Line: 2}}},
28 })
29 a.Tick()
30
31 if _, found := a.language.FirstError(a.ActiveView().Buffer().Path()); !found {
32 t.Errorf("no error found for %q, though one was published for the same file",
33 a.ActiveView().Buffer().Path())
34 }
35 if got := a.ActiveView().Marks()[2]; got == 0 {
36 t.Errorf("line 3 is unmarked, though an error was published for it")
37 }
38}
39
40func TestDiagnosticsAreFoundWhicheverWaySpelt(t *testing.T) {
41 // Both directions, since either side may be the relative one.
42 project := t.TempDir()
43 t.Chdir(project)
44 a, _ := newTestApp(t)
45
46 a.language.receiveDiagnostics("main.go", []lsp.Diagnostic{{Message: "relative in"}})
47 if got := a.language.Diagnostics(filepath.Join(project, "main.go")); len(got) != 1 {
48 t.Errorf("published relative, read absolute: got %d diagnostics", len(got))
49 }
50
51 a.language.receiveDiagnostics(filepath.Join(project, "other.go"), []lsp.Diagnostic{{Message: "absolute in"}})
52 if got := a.language.Diagnostics("other.go"); len(got) != 1 {
53 t.Errorf("published absolute, read relative: got %d diagnostics", len(got))
54 }
55}
56
57func TestKnowsDoesNotDependOnTheSpellingOfThePath(t *testing.T) {
58 // The map of open documents is keyed the same way as the diagnostics:
59 // absolute. Keyed by whatever string DidOpen was given, a file opened as
60 // "main.go" would not be known as "/project/main.go" — and saving, which
61 // asks Knows to decide between announcing a document and reporting a
62 // write, would announce the same document twice.
63 project := t.TempDir()
64 t.Chdir(project)
65 a, _ := newTestApp(t)
66 client, _ := newFakeLanguage(t, a)
67 connectLanguage(a, client)
68
69 a.language.DidOpen("main.go", "package main\n")
70
71 absolute := filepath.Join(project, "main.go")
72 if !a.language.Knows(absolute) {
73 t.Errorf("opened as %q, not known as %q", "main.go", absolute)
74 }
75 if !a.language.Knows("main.go") {
76 t.Errorf("opened as %q, not known under that very spelling", "main.go")
77 }
78
79 a.language.DidClose(absolute)
80 if a.language.Knows("main.go") {
81 t.Errorf("closed as %q, still known as %q", absolute, "main.go")
82 }
83}