ioutil_test.go at [2b049247ed]

File src/0dev.org/ioutil/ioutil_test.go artifact e21bc31120 part of check-in 2b049247ed


package ioutil

import (
	diff "0dev.org/diff"
	"bytes"
	"testing"
)

func TestWriter(t *testing.T) {
	var (
		input  []byte = []byte{0, 1, 2, 3, 4, 5, 6, 7}
		output []byte

		reader *bytes.Reader = bytes.NewReader(input)
		buffer bytes.Buffer
	)

	reader.WriteTo(WriterFunc(buffer.Write))
	output = buffer.Bytes()

	// Diff the result against the initial input
	delta := diff.Diff(diff.D{len(input), len(output),
		func(i, j int) bool { return input[i] == output[j] }})
	if len(delta.Added) > 0 || len(delta.Removed) > 0 {
		t.Error("Differences detected ", delta)
	}
}

func TestReader(t *testing.T) {
	var (
		input  []byte = []byte{0, 1, 2, 3, 4, 5, 6, 7}
		output []byte

		reader *bytes.Reader = bytes.NewReader(input)
		buffer bytes.Buffer
	)

	buffer.ReadFrom(ReaderFunc(reader.Read))
	output = buffer.Bytes()

	// Diff the result against the initial input
	delta := diff.Diff(diff.D{len(input), len(output),
		func(i, j int) bool { return input[i] == output[j] }})
	if len(delta.Added) > 0 || len(delta.Removed) > 0 {
		t.Error("Differences detected ", delta)
	}
}