From 6b0a3b35203898424a343a64c592be7cf27cabd5 Mon Sep 17 00:00:00 2001 From: Maxim Date: Thu, 24 Aug 2017 19:07:33 +0100 Subject: [PATCH] More tests for pipes. --- strit_test.go | 30 +++++++++++++++++++++++++++++- 1 file changed, 29 insertions(+), 1 deletion(-) diff --git a/strit_test.go b/strit_test.go index 1d5acd9..07d42c5 100644 --- a/strit_test.go +++ b/strit_test.go @@ -303,7 +303,7 @@ func TestPipe(t *testing.T) { const str = "aaa\nbbb\nccc" - res, err := FromString(str).Pipe("cat").Join("\n") + res, err := FromString(str).Pipe("cat").Pipe("cat").Pipe("cat").Join("\n") if err != nil { t.Error(err) @@ -323,6 +323,7 @@ func TestPipeTermination(t *testing.T) { const msg = "Just an error" + // termination at the end of the pipe err := FromString("aaa\nbbb\nccc").Pipe("cat")(func(s []byte) error { if bytes.Compare(s, []byte("aaa")) != 0 { return fmt.Errorf("Invalid string in callback: %q", string(s)) @@ -340,6 +341,33 @@ func TestPipeTermination(t *testing.T) { t.Errorf("Unexpected error: %q instead of %q", err.Error(), msg) return } + + // termination before pipe + iter := Iter(func(fn Func) error { + if err := fn([]byte("aaa")); err != nil { + return err + } + + return errors.New(msg) + }) + + err = iter.Pipe("cat")(func(s []byte) error { + if bytes.Compare(s, []byte("aaa")) != 0 { + return fmt.Errorf("Invalid string in callback: %q", string(s)) + } + + return nil + }) + + if err == nil { + t.Error("Missing error") + return + } + + if err.Error() != msg { + t.Errorf("Unexpected error: %q instead of %q", err.Error(), msg) + return + } } func TestNullTerminatedStrings(t *testing.T) {