OLD | NEW |
1 // Copyright 2011 The Go Authors. All rights reserved. | 1 // Copyright 2011 The Go Authors. All rights reserved. |
2 // Use of this source code is governed by a BSD-style | 2 // Use of this source code is governed by a BSD-style |
3 // license that can be found in the LICENSE file. | 3 // license that can be found in the LICENSE file. |
4 | 4 |
5 package terminal | 5 package terminal |
6 | 6 |
7 import ( | 7 import ( |
8 "io" | 8 "io" |
9 "testing" | 9 "testing" |
10 ) | 10 ) |
(...skipping 123 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
134 line: "a", | 134 line: "a", |
135 }, | 135 }, |
136 { | 136 { |
137 in: "ab\x1b[D\013\r", | 137 in: "ab\x1b[D\013\r", |
138 line: "a", | 138 line: "a", |
139 }, | 139 }, |
140 { | 140 { |
141 in: "Ξεσκεπάζω\r", | 141 in: "Ξεσκεπάζω\r", |
142 line: "Ξεσκεπάζω", | 142 line: "Ξεσκεπάζω", |
143 }, | 143 }, |
| 144 { |
| 145 in: "£\r\x1b[A\177\r", // non-ASCII char, enter, up,
backspace. |
| 146 line: "", |
| 147 throwAwayLines: 1, |
| 148 }, |
| 149 { |
| 150 in: "£\r££\x1b[A\x1b[B\177\r", // non-ASCII char, en
ter, 2x non-ASCII, up, down, backspace, enter. |
| 151 line: "£", |
| 152 throwAwayLines: 1, |
| 153 }, |
144 } | 154 } |
145 | 155 |
146 func TestKeyPresses(t *testing.T) { | 156 func TestKeyPresses(t *testing.T) { |
147 for i, test := range keyPressTests { | 157 for i, test := range keyPressTests { |
148 for j := 1; j < len(test.in); j++ { | 158 for j := 1; j < len(test.in); j++ { |
149 c := &MockTerminal{ | 159 c := &MockTerminal{ |
150 toSend: []byte(test.in), | 160 toSend: []byte(test.in), |
151 bytesPerRead: j, | 161 bytesPerRead: j, |
152 } | 162 } |
153 ss := NewTerminal(c, "> ") | 163 ss := NewTerminal(c, "> ") |
(...skipping 24 matching lines...) Expand all Loading... |
178 ss := NewTerminal(c, "> ") | 188 ss := NewTerminal(c, "> ") |
179 pw, _ := ss.ReadPassword("> ") | 189 pw, _ := ss.ReadPassword("> ") |
180 if pw != "password" { | 190 if pw != "password" { |
181 t.Fatalf("failed to read password, got %s", pw) | 191 t.Fatalf("failed to read password, got %s", pw) |
182 } | 192 } |
183 line, _ := ss.ReadLine() | 193 line, _ := ss.ReadLine() |
184 if len(line) > 0 { | 194 if len(line) > 0 { |
185 t.Fatalf("password was saved in history") | 195 t.Fatalf("password was saved in history") |
186 } | 196 } |
187 } | 197 } |
OLD | NEW |