turbo-editors/turbo-corepublic Fork 0
v0.9.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.

🛟 Updated. 28d5985 · on v0.9.0 · k33g · 19h ago
save_test.go · 97 lines · 3.2 KBGo Blame HistoryRaw
 1
 2
 3
 4
 5
 6
 7
 8
 9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
package app

import (
	"path/filepath"
	"testing"
)

// These tests cover what saving says to the language server. The defect they
// were written against: a window that started Untitled gains its path through
// Save As, afterSave sent only didSave, and a server ignores didSave for a
// document it was never told is open — so the window had no completion until
// the editor was restarted.

func TestSavingAnUntitledWindowAnnouncesItsDocument(t *testing.T) {
	project := t.TempDir()
	t.Chdir(project)
	a, _ := newTestApp(t)
	client, server := newFakeLanguage(t, a)
	connectLanguage(a, client)
	a.Tick() // the start-up announcement runs, and finds nothing to tell

	a.NewFile()
	typeText(a, "package main")
	path := filepath.Join(project, "main.go")
	a.save(a.ActiveView(), path)

	waitForMethod(t, server, "textDocument/didOpen")
	if got := server.methodCount("textDocument/didSave"); got != 0 {
		t.Errorf("didSave was sent %d times for a document the server was never told is open", got)
	}
	if !a.language.Knows(path) {
		t.Errorf("after the save, the server still does not know %q", path)
	}
}

func TestSaveAsUnderANewNameClosesTheOldDocument(t *testing.T) {
	project := t.TempDir()
	t.Chdir(project)
	a, _ := newTestApp(t)
	client, server := newFakeLanguage(t, a)
	connectLanguage(a, client)

	writeTestFile(t, filepath.Join(project, "old.go"), "package main\n")
	a.Open("old.go")
	waitForMethod(t, server, "textDocument/didOpen")

	newPath := filepath.Join(project, "new.go")
	a.save(a.ActiveView(), newPath)

	waitForMethod(t, server, "textDocument/didClose")
	if a.language.Knows("old.go") {
		t.Errorf("the old document is still open on the server after Save As gave the buffer a new name")
	}
	if !a.language.Knows(newPath) {
		t.Errorf("the new document was never announced to the server")
	}
}

func TestSaveAsToTheSamePathClosesNothing(t *testing.T) {
	// Save As offered the file's own name and the user accepted it: that is a
	// write, not a rename, however the dialog spelt the path.
	project := t.TempDir()
	t.Chdir(project)
	a, _ := newTestApp(t)
	client, server := newFakeLanguage(t, a)
	connectLanguage(a, client)

	writeTestFile(t, filepath.Join(project, "main.go"), "package main\n")
	a.Open("main.go") // relative, as the command line gives it
	waitForMethod(t, server, "textDocument/didOpen")

	a.save(a.ActiveView(), filepath.Join(project, "main.go")) // absolute, as the dialog gives it

	waitForMethod(t, server, "textDocument/didSave")
	if got := server.methodCount("textDocument/didClose"); got != 0 {
		t.Errorf("didClose was sent %d times for a save that renamed nothing", got)
	}
}

func TestSavingAKnownDocumentReportsTheWrite(t *testing.T) {
	project := t.TempDir()
	t.Chdir(project)
	a, _ := newTestApp(t)
	client, server := newFakeLanguage(t, a)
	connectLanguage(a, client)

	writeTestFile(t, filepath.Join(project, "main.go"), "package main\n")
	a.Open("main.go")
	waitForMethod(t, server, "textDocument/didOpen")

	a.save(a.ActiveView(), a.ActiveView().Buffer().Path())

	waitForMethod(t, server, "textDocument/didSave")
	if got := server.methodCount("textDocument/didOpen"); got != 1 {
		t.Errorf("didOpen was sent %d times; saving an open document must not re-announce it", got)
	}
}