-
-
Notifications
You must be signed in to change notification settings - Fork 2
/
queue_test.go
35 lines (31 loc) · 710 Bytes
/
queue_test.go
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
package main
import (
"reflect"
"strconv"
"strings"
"testing"
)
func TestQueueReadLine(t *testing.T) {
tests := []struct {
input string
splitChar byte
want []string
}{
{"one\ttwo", '\t', []string{"one", "two"}},
{"one\ntwo", '\n', []string{"one", "two"}},
{"one\rtwo", '\r', []string{"one", "two"}},
{"abc", 'b', []string{"a", "c"}},
}
for i, tt := range tests {
t.Run(strconv.Itoa(i), func(t *testing.T) {
lines := []string{}
queue := newQueue(strings.NewReader(tt.input), tt.splitChar, 1)
for got := range queue.ch {
lines = append(lines, got)
}
if !reflect.DeepEqual(lines, tt.want) {
t.Fatalf("Got: %#v Want: %#v", lines, tt.want)
}
})
}
}