-
Notifications
You must be signed in to change notification settings - Fork 8
/
file_test.go
56 lines (44 loc) · 1.14 KB
/
file_test.go
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
// Copyright 2014 The lime Authors.
// Use of this source code is governed by a 2-clause
// BSD-style license that can be found in the LICENSE file.
package commands
import (
"path/filepath"
"testing"
"github.com/limetext/backend"
)
func TestNewFile(t *testing.T) {
ed := backend.GetEditor()
w := ed.NewWindow()
defer w.Close()
l := len(w.Views())
ed.CommandHandler().RunWindowCommand(w, "new_file", nil)
if len(w.Views()) != l+1 {
t.Errorf("Expected %d views, but got %d", l+1, len(w.Views()))
}
for _, v := range w.Views() {
v.SetScratch(true)
v.Close()
}
}
func TestOpenFile(t *testing.T) {
var fe front
const testPath = "file_test.go"
fe.files = []string{testPath}
ed := backend.GetEditor()
ed.SetFrontend(&fe)
w := ed.NewWindow()
defer w.Close()
l := len(w.Views())
ed.CommandHandler().RunWindowCommand(w, "prompt_open_file", nil)
if len(w.Views()) != l+1 {
t.Fatalf("Expected %d views, but got %d", l+1, len(w.Views()))
}
exp, err := filepath.Abs(testPath)
if err != nil {
exp = testPath
}
if w.Views()[l].FileName() != exp {
t.Errorf("Expected %s as FileName, but got %s", testPath, w.Views()[l].FileName())
}
}