Diff

Differences From Artifact [e21bc31120]:

To Artifact [8530a31260]:


1
2
3
4
5

6
7
8
9
10
11
12
1
2
3
4
5
6
7
8
9
10
11
12
13





+







package ioutil

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

func TestWriter(t *testing.T) {
	var (
		input  []byte = []byte{0, 1, 2, 3, 4, 5, 6, 7}
		output []byte
41
42
43
44
45
46
47














































42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94







+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
	// 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 TestMinReader(t *testing.T) {
	var (
		input  []byte = []byte{0, 1, 2, 3, 4, 5, 6, 7}
		output []byte = make([]byte, 16)

		reader *bytes.Reader = bytes.NewReader(input)
		min    io.Reader     = MinReader(reader, 4)
	)

	// Expecting a read count of 2
	count, err := min.Read(output[:2])
	if count != 2 {
		t.Error("Invalid read count from MinReader", count)
	}
	if err != nil {
		t.Error("Unexpected error from MinReader", err)
	}

	// Expecting a read count of 2 as it should have 2 bytes in its buffer
	count, err = min.Read(output[:3])
	if count != 2 {
		t.Error("Invalid read count from MinReader", count)
	}
	if err != nil {
		t.Error("Unexpected error from MinReader", err)
	}

	// Expecting a read count of 4 as the buffer should be empty
	count, err = min.Read(output[:4])
	if count != 4 {
		t.Error("Invalid read count from MinReader", count)
	}
	if err != nil {
		t.Error("Unexpected error from MinReader", err)
	}

	// Expecting a read count of 0 with an EOF as the buffer should be empty
	count, err = min.Read(output[:4])
	if count != 0 {
		t.Error("Invalid read count from MinReader", count)
	}
	if err != io.EOF {
		t.Error("Unexpected error from MinReader", err)
	}
}