Skip to content

Commit

Permalink
reduce unused Regexp compile
Browse files Browse the repository at this point in the history
  • Loading branch information
haya14busa committed Sep 19, 2016
1 parent b12279c commit 64a3a04
Show file tree
Hide file tree
Showing 2 changed files with 0 additions and 61 deletions.
15 changes: 0 additions & 15 deletions go/vimlfunc.go
Original file line number Diff line number Diff line change
Expand Up @@ -66,12 +66,10 @@ var patVim2Go = map[string]string{
}

var patVim2GoRegh = make(map[string]*regexp.Regexp)
var patVim2GoRegq = make(map[string]*regexp.Regexp)

func init() {
for k, v := range patVim2Go {
patVim2GoRegh[k] = regexp.MustCompile(v)
patVim2GoRegq[k] = regexp.MustCompile("(?i)" + v)
}
}

Expand All @@ -84,12 +82,6 @@ func viml_empty(obj interface{}) bool {
func viml_equalci(a, b string) bool {
return strings.ToLower(a) == strings.ToLower(b)
}
func viml_eqreg(s, reg string) bool {
if r, ok := patVim2GoRegq[reg]; ok {
return r.MatchString(s)
}
panic(fmt.Errorf("NotImplemented viml_eqreg for %v", reg))
}

func viml_eqregh(s, reg string) bool {
if r, ok := patVim2GoRegh[reg]; ok {
Expand All @@ -98,13 +90,6 @@ func viml_eqregh(s, reg string) bool {
panic("NotImplemented viml_eqregh")
}

func viml_eqregq(s, reg string) bool {
if r, ok := patVim2GoRegq[reg]; ok {
return r.MatchString(s)
}
panic("NotImplemented viml_eqregq")
}

func viml_escape(s string, chars string) string {
r := ""
for _, c := range s {
Expand Down
46 changes: 0 additions & 46 deletions go/vimlfunc_test.go
Original file line number Diff line number Diff line change
Expand Up @@ -5,34 +5,6 @@ import (
"testing"
)

func TestViml_eqreg(t *testing.T) {
tests := []struct {
in string
reg string
want bool
}{
{in: ``, reg: "^\\s*\\\\", want: false},
{in: `hoge`, reg: "^\\s*\\\\", want: false},
{in: ` \ hoge`, reg: "^\\s*\\\\", want: true},
{in: `\`, reg: "^\\s*\\\\", want: true},

// ^++
{in: `++hoge`, reg: "^++", want: true},
{in: `hoge`, reg: "^++", want: false},

// case
{in: `deletel`, reg: "\\v^d%[elete][lp]$", want: true},
{in: `deleteL`, reg: "\\v^d%[elete][lp]$", want: true},
{in: `++bad=keep`, reg: "^++bad=keep", want: true},
{in: `++bad=KEEP`, reg: "^++bad=keep", want: true},
}
for _, tt := range tests {
if got := viml_eqreg(tt.in, tt.reg); got != tt.want {
t.Errorf("viml_eqreg(%q, %q) = %v, want %v", tt.in, tt.reg, got, tt.want)
}
}
}

func TestViml_eqregh(t *testing.T) {
tests := []struct {
in string
Expand All @@ -51,24 +23,6 @@ func TestViml_eqregh(t *testing.T) {
}
}

func TestViml_eqregq(t *testing.T) {
tests := []struct {
in string
reg string
want bool
}{
{in: `deletel`, reg: "\\v^d%[elete][lp]$", want: true},
{in: `deleteL`, reg: "\\v^d%[elete][lp]$", want: true},
{in: `++bad=keep`, reg: "^++bad=keep", want: true},
{in: `++bad=KEEP`, reg: "^++bad=keep", want: true},
}
for _, tt := range tests {
if got := viml_eqregq(tt.in, tt.reg); got != tt.want {
t.Errorf("viml_eqregq(%q, %q) = %v, want %v", tt.in, tt.reg, got, tt.want)
}
}
}

func TestViml_printf(t *testing.T) {
tests := []struct {
f string
Expand Down

0 comments on commit 64a3a04

Please sign in to comment.