From: David Symonds Date: Wed, 19 Sep 2012 22:11:07 +0000 (+1000) Subject: misc/vim: fix Drop for imports after the first group. X-Git-Tag: go1.1rc2~2398 X-Git-Url: http://www.git.cypherpunks.su/?a=commitdiff_plain;h=adcf0a2aa06ec1424b4d51d2b7ce043a60d29361;p=gostls13.git misc/vim: fix Drop for imports after the first group. Previously, an import block such as import ( "net" "stack" ) would not permit ":Drop stack" to work because we were aborting the scan early, which is only correct when Import is in operation. R=golang-dev, franciscossouza CC=golang-dev https://golang.org/cl/6532053 --- diff --git a/misc/vim/ftplugin/go/import.vim b/misc/vim/ftplugin/go/import.vim index 6ed5dd49d1..8cf89291e5 100644 --- a/misc/vim/ftplugin/go/import.vim +++ b/misc/vim/ftplugin/go/import.vim @@ -96,7 +96,7 @@ function! s:SwitchImport(enabled, localname, path) let linestr = getline(line) let m = matchlist(getline(line), '^\()\|\(\s\+\)\(\S*\s*\)"\(.\+\)"\)') if empty(m) - if siteprefix == "" + if siteprefix == "" && a:enabled " must be in the first group break endif diff --git a/misc/vim/ftplugin/go/test.sh b/misc/vim/ftplugin/go/test.sh index bc32718df5..a6e31d8a3c 100755 --- a/misc/vim/ftplugin/go/test.sh +++ b/misc/vim/ftplugin/go/test.sh @@ -22,36 +22,53 @@ EOF fail=0 -# usage: test_one new_import pattern +# usage: test_one command pattern # Pattern is a PCRE expression that will match across lines. test_one() { - echo 2>&1 -n "Import $1: " + echo 2>&1 -n "$1: " vim -e -s -u /dev/null -U /dev/null --noplugin -c "source import.vim" \ - -c "Import $1" -c 'wq! test.go' base.go + -c "$1" -c 'wq! test.go' base.go # ensure blank lines are treated correctly if ! gofmt test.go | cmp test.go; then echo 2>&1 "gofmt conflict" - gofmt test.go | diff -u test.go - | sed "s/^/\t/" 2>&1 + gofmt test.go | diff -u test.go - | sed "s/^/ /" 2>&1 fail=1 return fi if ! grep -P -q "(?s)$2" test.go; then echo 2>&1 "$2 did not match" - cat test.go | sed "s/^/\t/" 2>&1 + cat test.go | sed "s/^/ /" 2>&1 fail=1 return fi echo 2>&1 "ok" } -test_one baz '"baz".*"bytes"' -test_one io/ioutil '"io".*"io/ioutil".*"net"' -test_one myc '"io".*"myc".*"net"' # prefix of a site prefix -test_one nat '"io".*"nat".*"net"' -test_one net/http '"net".*"net/http".*"mycorp/foo"' -test_one zoo '"net".*"zoo".*"mycorp/foo"' -test_one mycorp/bar '"net".*"mycorp/bar".*"mycorp/foo"' -test_one mycorp/goo '"net".*"mycorp/foo".*"mycorp/goo"' +# Tests for Import + +test_one "Import baz" '"baz".*"bytes"' +test_one "Import io/ioutil" '"io".*"io/ioutil".*"net"' +test_one "Import myc" '"io".*"myc".*"net"' # prefix of a site prefix +test_one "Import nat" '"io".*"nat".*"net"' +test_one "Import net/http" '"net".*"net/http".*"mycorp/foo"' +test_one "Import zoo" '"net".*"zoo".*"mycorp/foo"' +test_one "Import mycorp/bar" '"net".*"mycorp/bar".*"mycorp/foo"' +test_one "Import mycorp/goo" '"net".*"mycorp/foo".*"mycorp/goo"' + +# Tests for Drop + +cat > base.go <