forked from torbiak/gopl
-
Notifications
You must be signed in to change notification settings - Fork 0
/
Copy pathcharcount_test.go
50 lines (48 loc) · 1.25 KB
/
charcount_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
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
package main
import (
"reflect"
"strings"
"testing"
)
func TestCharCount(t *testing.T) {
tests := []struct {
input string
runes map[rune]int
props map[string]int
sizes map[int]int
invalid int
}{
{
input: "Hi, 世.",
runes: map[rune]int{'H': 1, 'i': 1, ',': 1, ' ': 1, '世': 1, '.': 1},
props: map[string]int{
"Ideographic": 1,
"Pattern_Syntax": 2,
"Pattern_White_Space": 1,
"STerm": 1,
"Sentence_Terminal": 1,
"Soft_Dotted": 1,
"Terminal_Punctuation": 2,
"Unified_Ideograph": 1,
"White_Space": 1,
},
sizes: map[int]int{1: 5, 3: 1},
invalid: 0,
},
}
for _, test := range tests {
runes, props, sizes, invalid := charCount(strings.NewReader(test.input))
if !reflect.DeepEqual(runes, test.runes) {
t.Errorf("%q runes: got %v, want %v", test.input, runes, test.runes)
}
if !reflect.DeepEqual(props, test.props) {
t.Errorf("%q props: got %v, want %v", test.input, props, test.props)
}
if !reflect.DeepEqual(sizes, test.sizes) {
t.Errorf("%q sizes: got %v, want %v", test.input, sizes, test.sizes)
}
if invalid != test.invalid {
t.Errorf("%q invalid: got %v, want %v", test.input, invalid, test.invalid)
}
}
}