2013-03-24 17:31:18 -04:00
|
|
|
package packer
|
|
|
|
|
|
|
|
import (
|
|
|
|
"bytes"
|
|
|
|
"cgl.tideland.biz/asserts"
|
2013-03-24 17:47:59 -04:00
|
|
|
"testing"
|
2013-03-24 17:31:18 -04:00
|
|
|
)
|
|
|
|
|
2013-04-20 21:55:02 -04:00
|
|
|
func testUi() *ReaderWriterUi {
|
|
|
|
return &ReaderWriterUi{
|
|
|
|
new(bytes.Buffer),
|
|
|
|
new(bytes.Buffer),
|
|
|
|
}
|
|
|
|
}
|
2013-03-24 17:31:18 -04:00
|
|
|
|
|
|
|
func TestReaderWriterUi_Say(t *testing.T) {
|
|
|
|
assert := asserts.NewTestingAsserts(t, true)
|
|
|
|
|
2013-04-20 21:55:02 -04:00
|
|
|
bufferUi := testUi()
|
|
|
|
|
2013-03-24 17:31:18 -04:00
|
|
|
bufferUi.Say("foo")
|
|
|
|
assert.Equal(readWriter(bufferUi), "foo", "basic output")
|
|
|
|
|
|
|
|
bufferUi.Say("%d", 5)
|
|
|
|
assert.Equal(readWriter(bufferUi), "5", "formatting")
|
|
|
|
}
|
|
|
|
|
|
|
|
// This reads the output from the bytes.Buffer in our test object
|
|
|
|
// and then resets the buffer.
|
|
|
|
func readWriter(ui *ReaderWriterUi) (result string) {
|
|
|
|
buffer := ui.Writer.(*bytes.Buffer)
|
|
|
|
result = buffer.String()
|
|
|
|
buffer.Reset()
|
|
|
|
return
|
|
|
|
}
|