Add tests for NoMatch struct

This commit is contained in:
Daisuke Maki 2014-08-26 12:32:34 +09:00
parent 46f5714cf5
commit 4379a963c2

View file

@ -1,6 +1,9 @@
package peco
import "testing"
import (
"strings"
"testing"
)
// some little test to validate ansi strips function
func TestANSIColorStrip(t *testing.T) {
@ -21,3 +24,38 @@ func TestANSIColorStrip(t *testing.T) {
t.Errorf("expected String = 'x1b[01;34mthe answer to life is x1b[0;42m42' , got '%s'", test)
}
}
func TestNewNoMatch(t *testing.T) {
var m *NoMatch
m = NewNoMatch("Hello, World!", false)
if m.Indices() != nil {
t.Errorf("NoMatch.Indices() must always return nil")
}
nullsepCheck := func(buf string) {
m = NewNoMatch(buf, true)
if m.Buffer() != buf {
t.Errorf("m.Buffer() should return '%s', got %s", buf, m.Buffer())
}
if sepLoc := strings.Index(buf, "\000"); sepLoc > -1 {
if m.Line() != buf[0:sepLoc] {
t.Errorf("m.Line() should return '%s', got '%s'", buf[0:sepLoc], m.Line())
}
if m.Output() != buf[sepLoc+1:] {
t.Errorf("m.Output() should return '%s', got '%s'", buf[sepLoc+1:], m.Output())
}
} else {
if m.Line() != m.Buffer() {
t.Errorf("m.Line() should return '%s', got '%s'", m.Buffer(), m.Line())
}
if m.Output() != m.Buffer() {
t.Errorf("m.Output() should return '%s', got '%s'", m.Buffer(), m.Output())
}
}
}
nullsepCheck("Hello, World!")
nullsepCheck("Hello, World!\000Hello, peco!")
}