-
Notifications
You must be signed in to change notification settings - Fork 1
Expand file tree
/
Copy pathcrlf_test.go
More file actions
65 lines (58 loc) · 1.89 KB
/
Copy pathcrlf_test.go
File metadata and controls
65 lines (58 loc) · 1.89 KB
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
package command
import (
"io"
"strings"
"testing"
"testing/iotest"
)
func TestCRLFReaderWithCRLF(t *testing.T) {
r := crlfReader(io.NopCloser(strings.NewReader("line1\r\nline2\r\n")))
if got, err := io.ReadAll(r); err != nil {
t.Errorf("ReadAll() error = %v", err)
} else if want := "line1\nline2\n"; string(got) != want {
t.Errorf("ReadAll() = %q, want %q", got, want)
}
}
func TestCRLFReaderWithCR(t *testing.T) {
r := crlfReader(io.NopCloser(strings.NewReader("line1\rline2\r")))
if got, err := io.ReadAll(r); err != nil {
t.Errorf("ReadAll() error = %v", err)
} else if want := "line1\nline2\n"; string(got) != want {
t.Errorf("ReadAll() = %q, want %q", got, want)
}
}
func TestCRLFReaderWithLF(t *testing.T) {
r := crlfReader(io.NopCloser(strings.NewReader("line1\nline2\n")))
if got, err := io.ReadAll(r); err != nil {
t.Errorf("ReadAll() error = %v", err)
} else if want := "line1\nline2\n"; string(got) != want {
t.Errorf("ReadAll() = %q, want %q", got, want)
}
}
func TestCRLFReaderWithMixed(t *testing.T) {
r := crlfReader(io.NopCloser(strings.NewReader("unix\nwin\r\nmac\rend")))
if got, err := io.ReadAll(r); err != nil {
t.Errorf("ReadAll() error = %v", err)
} else if want := "unix\nwin\nmac\nend"; string(got) != want {
t.Errorf("ReadAll() = %q, want %q", got, want)
}
}
func TestCRLFReaderWithSplitCRLF(t *testing.T) {
r := iotest.OneByteReader(strings.NewReader("test\r\ndata"))
wrapped := crlfReader(io.NopCloser(r))
if got, err := io.ReadAll(wrapped); err != nil {
t.Errorf("ReadAll() error = %v", err)
} else if want := "test\ndata"; string(got) != want {
t.Errorf("ReadAll() = %q, want %q", got, want)
}
}
func TestCRLFReaderClose(t *testing.T) {
var closed closeTracker
wrapped := crlfReader(&closed)
if err := wrapped.Close(); err != nil {
t.Errorf("Close() error = %v", err)
}
if !closed {
t.Error("Close() did not call underlying Close()")
}
}