@@ -68,65 +68,42 @@ index 0000000..3be2928`,
68
68
}
69
69
70
70
func TestLineReader_ReadLine (t * testing.T ) {
71
- tests := []struct {
72
- name string
73
- input string
74
- want []string
75
- }{
76
- {
77
- name : "empty" ,
78
- input : "" ,
79
- want : []string {},
80
- },
81
- {
82
- name : "single_line" ,
83
- input : "@@ -0,0 +1,62 @@" ,
84
- want : []string {"@@ -0,0 +1,62 @@" },
85
- },
86
- {
87
- name : "single_lf_terminated_line" ,
88
- input : "@@ -0,0 +1,62 @@\n " ,
89
- want : []string {"@@ -0,0 +1,62 @@" },
90
- },
91
- {
92
- name : "single_crlf_terminated_line" ,
93
- input : "@@ -0,0 +1,62 @@\r \n " ,
94
- want : []string {"@@ -0,0 +1,62 @@" },
95
- },
96
- {
97
- name : "multi_line" ,
98
- input : `diff --git a/test.go b/test.go
71
+ input := `diff --git a/test.go b/test.go
99
72
new file mode 100644
100
- index 0000000..3be2928` ,
101
- want : []string {
102
- "diff --git a/test.go b/test.go" ,
103
- "new file mode 100644" ,
104
- "index 0000000..3be2928" ,
105
- },
106
- },
73
+ index 0000000..3be2928
74
+
75
+
76
+ `
77
+
78
+ in := newLineReader (strings .NewReader (input ))
79
+ out := []string {}
80
+ for i := 0 ; i < 4 ; i ++ {
81
+ l , err := in .readLine ()
82
+ if err != nil {
83
+ t .Fatal (err )
84
+ }
85
+ out = append (out , string (l ))
107
86
}
108
- for _ , test := range tests {
109
- t .Run (test .name , func (t * testing.T ) {
110
- in := newLineReader (strings .NewReader (test .input ))
111
- out := []string {}
112
- for {
113
- l , err := in .readLine ()
114
- if err == io .EOF {
115
- break
116
- }
117
- if err != nil {
118
- t .Fatal (err )
119
- }
120
- out = append (out , string (l ))
121
- }
122
- if ! reflect .DeepEqual (test .want , out ) {
123
- t .Errorf ("read lines not equal: want %v, got %v" , test .want , out )
124
- }
125
- })
87
+
88
+ wantOut := strings .Split (input , "\n " )[0 :4 ]
89
+ if ! reflect .DeepEqual (wantOut , out ) {
90
+ t .Errorf ("read lines not equal: want %v, got %v" , wantOut , out )
91
+ }
92
+
93
+ _ , err := in .readLine ()
94
+ if err != nil {
95
+ t .Fatal (err )
96
+ }
97
+ if in .cachedNextLineErr != io .EOF {
98
+ t .Fatalf ("lineReader has wrong cachedNextLineErr: %s" , in .cachedNextLineErr )
99
+ }
100
+ _ , err = in .readLine ()
101
+ if err != io .EOF {
102
+ t .Fatalf ("readLine did not return io.EOF: %s" , err )
126
103
}
127
104
}
128
105
129
- func TestLineReader_NextLineStartsWith (t * testing.T ) {
106
+ func TestLineReader_NextLine (t * testing.T ) {
130
107
input := `aaa rest of line
131
108
bbbrest of line
132
109
ccc rest of line`
0 commit comments