Artifact [e21bc31120]

Artifact e21bc311203eee145f14436e56b1b0d3bd66c78d:


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)
	}
}