Debian Codegraph @

shiny/screen/screen_test.go

raw symbols SCIP
1 // Copyright 2017 The Go Authors. All rights reserved.
2 // Use of this source code is governed by a BSD-style
3 // license that can be found in the LICENSE file.
4
5 package screen
6
7 import (
8 "testing"
9 )
10
11 func TestSanitizeUTF8(t *testing.T) {
12 const n = 8
13
14 testCases := []struct {
15 s, want string
16 }{
17 {"", ""},
18 {"a", "a"},
19 {"a\x00", "a"},
20 {"a\x80", "a"},
21 {"\x00a", ""},
22 {"\x80a", ""},
23 {"abc", "abc"},
24 {"foo b\x00r qux", "foo b"},
25 {"foo b\x80r qux", "foo b"},
26 {"foo b\xffr qux", "foo b"},
27
28 // "\xc3\xa0" is U+00E0 LATIN SMALL LETTER A WITH GRAVE.
29 {"\xc3\xa0pqrs", "\u00e0pqrs"},
30 {"a\xc3\xa0pqrs", "a\u00e0pqrs"},
31 {"ab\xc3\xa0pqrs", "ab\u00e0pqrs"},
32 {"abc\xc3\xa0pqrs", "abc\u00e0pqr"},
33 {"abcd\xc3\xa0pqrs", "abcd\u00e0pq"},
34 {"abcde\xc3\xa0pqrs", "abcde\u00e0p"},
35 {"abcdef\xc3\xa0pqrs", "abcdef\u00e0"},
36 {"abcdefg\xc3\xa0pqrs", "abcdefg"},
37 {"abcdefgh\xc3\xa0pqrs", "abcdefgh"},
38 {"abcdefghi\xc3\xa0pqrs", "abcdefgh"},
39 {"abcdefghij\xc3\xa0pqrs", "abcdefgh"},
40
41 // "世" is "\xe4\xb8\x96".
42 // "界" is "\xe7\x95\x8c".
43 {"H 世界", "H 世界"},
44 {"Hi 世界", "Hi 世"},
45 {"Hello 世界", "Hello "},
46 }
47
48 for _, tc := range testCases {
49 if got := sanitizeUTF8(tc.s, n); got != tc.want {
50 t.Errorf("sanitizeUTF8(%q): got %q, want %q", tc.s, got, tc.want)
51 }
52 }
53 }