-
Notifications
You must be signed in to change notification settings - Fork 4
Expand file tree
/
Copy pathread_test.go
More file actions
126 lines (118 loc) · 2.05 KB
/
read_test.go
File metadata and controls
126 lines (118 loc) · 2.05 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
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
95
96
97
98
99
100
101
102
103
104
105
106
107
108
109
110
111
112
113
114
115
116
117
118
119
120
121
122
123
124
125
126
package readline
import (
"testing"
)
func TestRemoveNonPrintableChars(t *testing.T) {
tests := []struct {
Slice string
Expected string
}{
{
Slice: "",
Expected: "",
},
{
Slice: "a",
Expected: "a",
},
{
Slice: "abc",
Expected: "abc",
},
{
Slice: "\t",
Expected: "\t",
},
{
Slice: "\ta",
Expected: "\ta",
},
{
Slice: "a\t",
Expected: "a\t",
},
{
Slice: "a\tb",
Expected: "a\tb",
},
{
Slice: "a\tb\tc",
Expected: "a\tb\tc",
},
{
Slice: "a\t\tb\t\tc",
Expected: "a\t\tb\t\tc",
},
// non printable
{
Slice: "\x16",
Expected: "",
},
{
Slice: "\x16a",
Expected: "a",
},
{
Slice: "a\x16",
Expected: "a",
},
{
Slice: "a\x16b",
Expected: "ab",
},
{
Slice: "a\x16b\x16c",
Expected: "abc",
},
{
Slice: "a\x16\x16b\x16\x16c",
Expected: "abc",
},
// unicode
{
Slice: "世界",
Expected: "世界",
},
{
Slice: "\x16世\x16界\x16",
Expected: "世界",
},
{
Slice: "\x16世界\x16世界\x16",
Expected: "世界世界",
},
{
Slice: "\x16\x16世界\x16\x16世界\x16\x16",
Expected: "世界世界",
},
{
Slice: "😀😁😂",
Expected: "😀😁😂",
},
{
Slice: "\x16😀\x16😁\x16😂",
Expected: "😀😁😂",
},
{
Slice: "\x16😀😁😂\x16😀😁😂\x16",
Expected: "😀😁😂😀😁😂",
},
{
Slice: "\x16\x16😀😁😂\x16\x16😀😁😂\x16\x16",
Expected: "😀😁😂😀😁😂",
},
}
for i, test := range tests {
s := []byte(test.Slice)
actual := string(s[:removeNonPrintableChars(s)])
if test.Expected != actual {
t.Errorf("Expected does not match actual in test %d", i)
t.Logf(" Slice: '%s'", test.Slice)
t.Logf(" Expected: '%s'", test.Expected)
t.Logf(" Actual: '%s'", actual)
t.Logf(" s bytes: '%v'", []byte(test.Slice))
t.Logf(" e bytes: '%v'", []byte(test.Expected))
t.Logf(" a bytes: '%v'", []byte(actual))
}
}
}