prefixed_writer_test.go 784 B

12345678910111213141516171819202122232425262728293031323334353637383940414243
  1. package gexec_test
  2. import (
  3. "bytes"
  4. . "github.com/onsi/gomega/gexec"
  5. . "github.com/onsi/ginkgo"
  6. . "github.com/onsi/gomega"
  7. )
  8. var _ = Describe("PrefixedWriter", func() {
  9. var buffer *bytes.Buffer
  10. var writer *PrefixedWriter
  11. BeforeEach(func() {
  12. buffer = &bytes.Buffer{}
  13. writer = NewPrefixedWriter("[p]", buffer)
  14. })
  15. It("should emit the prefix on newlines", func() {
  16. writer.Write([]byte("abc"))
  17. writer.Write([]byte("def\n"))
  18. writer.Write([]byte("hij\n"))
  19. writer.Write([]byte("\n\n"))
  20. writer.Write([]byte("klm\n\nnop"))
  21. writer.Write([]byte(""))
  22. writer.Write([]byte("qrs"))
  23. writer.Write([]byte("\ntuv\nwx"))
  24. writer.Write([]byte("yz\n\n"))
  25. Expect(buffer.String()).Should(Equal(`[p]abcdef
  26. [p]hij
  27. [p]
  28. [p]
  29. [p]klm
  30. [p]
  31. [p]nopqrs
  32. [p]tuv
  33. [p]wxyz
  34. [p]
  35. `))
  36. })
  37. })