Skip to content

Commit

Permalink
More tests for pipes.
Browse files Browse the repository at this point in the history
  • Loading branch information
maxim2266 committed Aug 24, 2017
1 parent f095920 commit 6b0a3b3
Showing 1 changed file with 29 additions and 1 deletion.
30 changes: 29 additions & 1 deletion strit_test.go
Original file line number Diff line number Diff line change
Expand Up @@ -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)
Expand All @@ -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))
Expand All @@ -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) {
Expand Down

0 comments on commit 6b0a3b3

Please sign in to comment.