Debian Codegraph @

tty/utf16_test.go

raw symbols SCIP
1 // Copyright 2026 The TCell Authors
2 //
3 // Licensed under the Apache License, Version 2.0 (the "License");
4 // you may not use this file except in compliance with the License.
5 // You may obtain a copy of the License at
6 //
7 // http://www.apache.org/licenses/LICENSE-2.0
8 //
9 // Unless required by applicable law or agreed to in writing, software
10 // distributed under the License is distributed on an "AS IS" BASIS,
11 // WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
12 // See the License for the specific language governing permissions and
13 // limitations under the License.
14
15 package tty
16
17 import (
18 "reflect"
19 "testing"
20 )
21
22 func TestDecodeUTF16Rune(t *testing.T) {
23 tests := []struct {
24 name string
25 in []rune
26 want []rune
27 }{
28 {
29 name: "bmp rune",
30 in: []rune{'A'},
31 want: []rune{'A'},
32 },
33 {
34 name: "valid surrogate pair",
35 in: []rune{0xD83D, 0xDE00},
36 want: []rune{'😀'},
37 },
38 {
39 name: "orphaned high before bmp",
40 in: []rune{0xD83D, ' '},
41 want: []rune{'�', ' '},
42 },
43 {
44 name: "orphaned high before high",
45 in: []rune{0xD83D, 0xD83D, 0xDE00},
46 want: []rune{'�', '😀'},
47 },
48 {
49 name: "orphaned low",
50 in: []rune{0xDE00},
51 want: []rune{'�'},
52 },
53 }
54
55 for _, tt := range tests {
56 t.Run(tt.name, func(t *testing.T) {
57 var surrogate rune
58 var got []rune
59 for _, wc := range tt.in {
60 got = append(got, decodeUTF16Rune(&surrogate, wc)...)
61 }
62 if !reflect.DeepEqual(got, tt.want) {
63 t.Fatalf("decodeUTF16Rune(%U) = %U, want %U", tt.in, got, tt.want)
64 }
65 })
66 }
67 }