From 4379a963c226189682abdb2bc9d13dfa82adfc64 Mon Sep 17 00:00:00 2001 From: Daisuke Maki Date: Tue, 26 Aug 2014 12:32:34 +0900 Subject: [PATCH] Add tests for NoMatch struct --- matchers_test.go | 40 +++++++++++++++++++++++++++++++++++++++- 1 file changed, 39 insertions(+), 1 deletion(-) diff --git a/matchers_test.go b/matchers_test.go index 4eb023b..7c1f120 100644 --- a/matchers_test.go +++ b/matchers_test.go @@ -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!") +}