Skip to content

Commit

Permalink
Merge branch 'improve-windows-support'
Browse files Browse the repository at this point in the history
  • Loading branch information
itchyny committed Apr 13, 2018
2 parents e0d4fc7 + dc1c9ac commit 1fdf7a5
Show file tree
Hide file tree
Showing 4 changed files with 35 additions and 7 deletions.
4 changes: 4 additions & 0 deletions cmdline/cmdline_test.go
Expand Up @@ -2,6 +2,7 @@ package cmdline

import (
"reflect"
"runtime"
"testing"

"github.com/itchyny/bed/event"
Expand Down Expand Up @@ -430,6 +431,9 @@ func TestCmdlineExecuteGoto(t *testing.T) {
}

func TestCmdlineComplete(t *testing.T) {
if runtime.GOOS == "windows" {
t.Skip("skip on Windows")
}
c := NewCmdline()
c.completor = newCompletor(&mockFilesystem{})
eventCh, cmdlineCh, redrawCh := make(chan event.Event), make(chan event.Event), make(chan struct{})
Expand Down
23 changes: 17 additions & 6 deletions cmdline/completor_test.go
@@ -1,6 +1,8 @@
package cmdline

import (
"path/filepath"
"runtime"
"testing"
)

Expand Down Expand Up @@ -35,8 +37,8 @@ func TestCompletorCompleteFilepath(t *testing.T) {
for i := 0; i < 4; i++ {
cmdline = c.complete(cmdline, cmd, prefix, arg, true)
}
if cmdline != "new editor/" {
t.Errorf("cmdline should be %q but got %q", "new editor/", cmdline)
if cmdline != "new editor"+string(filepath.Separator) {
t.Errorf("cmdline should be %q but got %q", "new editor"+string(filepath.Separator), cmdline)
}
if c.target != "new " {
t.Errorf("completion target should be %q but got %q", "new ", c.target)
Expand Down Expand Up @@ -113,8 +115,8 @@ func TestCompletorCompleteFilepathKeepPrefix(t *testing.T) {
cmdline := " : : : new C"
cmd, _, prefix, arg, _ := parse([]rune(cmdline))
cmdline = c.complete(cmdline, cmd, prefix, arg, true)
if cmdline != " : : : new cmdline/" {
t.Errorf("cmdline should be %q but got %q", " : : : new cmdline/", cmdline)
if cmdline != " : : : new cmdline"+string(filepath.Separator) {
t.Errorf("cmdline should be %q but got %q", " : : : new cmdline"+string(filepath.Separator), cmdline)
}
if c.target != " : : : new C" {
t.Errorf("completion target should be %q but got %q", " : : : new C", c.target)
Expand All @@ -124,8 +126,8 @@ func TestCompletorCompleteFilepathKeepPrefix(t *testing.T) {
}

cmdline = c.complete(cmdline, cmd, prefix, arg, true)
if cmdline != " : : : new common/" {
t.Errorf("cmdline should be %q but got %q", " : : : new common/", cmdline)
if cmdline != " : : : new common"+string(filepath.Separator) {
t.Errorf("cmdline should be %q but got %q", " : : : new common"+string(filepath.Separator), cmdline)
}
if c.index != 1 {
t.Errorf("completion index should be %d but got %d", 1, c.index)
Expand All @@ -142,6 +144,9 @@ func TestCompletorCompleteFilepathKeepPrefix(t *testing.T) {
}

func TestCompletorCompleteFilepathHomedir(t *testing.T) {
if runtime.GOOS == "windows" {
t.Skip("skip on Windows")
}
c := newCompletor(&mockFilesystem{})
cmdline := "vnew ~/"
cmd, _, prefix, arg, _ := parse([]rune(cmdline))
Expand Down Expand Up @@ -186,6 +191,9 @@ func TestCompletorCompleteFilepathHomedir(t *testing.T) {
}

func TestCompletorCompleteFilepathHomedirDot(t *testing.T) {
if runtime.GOOS == "windows" {
t.Skip("skip on Windows")
}
c := newCompletor(&mockFilesystem{})
cmdline := "vnew ~/."
cmd, _, prefix, arg, _ := parse([]rune(cmdline))
Expand All @@ -210,6 +218,9 @@ func TestCompletorCompleteFilepathHomedirDot(t *testing.T) {
}

func TestCompletorCompleteFilepathRoot(t *testing.T) {
if runtime.GOOS == "windows" {
t.Skip("skip on Windows")
}
c := newCompletor(&mockFilesystem{})
cmdline := "e /"
cmd, _, prefix, arg, _ := parse([]rune(cmdline))
Expand Down
4 changes: 4 additions & 0 deletions editor/editor_test.go
Expand Up @@ -4,6 +4,7 @@ import (
"fmt"
"io/ioutil"
"os"
"runtime"
"strconv"
"strings"
"sync"
Expand Down Expand Up @@ -95,6 +96,9 @@ func TestEditorOpenEmptyWriteQuit(t *testing.T) {
}

func TestEditorOpenWriteQuit(t *testing.T) {
if runtime.GOOS == "windows" {
t.Skip("skip on Windows")
}
ui := newTestUI()
editor := NewEditor(ui, window.NewManager(), cmdline.NewCmdline())
if err := editor.Init(); err != nil {
Expand Down
11 changes: 10 additions & 1 deletion window/manager.go
Expand Up @@ -437,7 +437,7 @@ func (m *Manager) writeFile(r *event.Range, name string) (string, int64, error)
if name == "" {
return name, 0, errors.New("no file name")
}
if runtime.GOOS == "windows" && name == window.filename {
if runtime.GOOS == "windows" && m.opened(name) {
return name, 0, errors.New("cannot overwrite the original file on Windows")
}
var err error
Expand Down Expand Up @@ -473,6 +473,15 @@ func (m *Manager) filePerm(name string) os.FileMode {
return os.FileMode(0644)
}

func (m *Manager) opened(name string) bool {
for _, f := range m.files {
if f.name == name {
return true
}
}
return false
}

// Close the Manager.
func (m *Manager) Close() {
for _, f := range m.files {
Expand Down

0 comments on commit 1fdf7a5

Please sign in to comment.