Skip to content

Commit 4fa5dbd

Browse files
committed
test: add missing short code tests
1 parent 65a599b commit 4fa5dbd

File tree

2 files changed

+46
-4
lines changed

2 files changed

+46
-4
lines changed

features/keys/short.go

Lines changed: 4 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -3,17 +3,17 @@ package keys
33
import "github.com/mishamyrt/nuga-lib/layout"
44

55
// FromShortKeyCode converts short code to full code
6-
func FromShortKeyCode(code byte) uint32 {
6+
func FromShortKeyCode(code uint8) uint32 {
77
return uint32(code) << 24
88
}
99

1010
// ToShortKeyCode converts full code to short code
11-
func ToShortKeyCode(code uint32) byte {
11+
func ToShortKeyCode(code uint32) uint8 {
1212
return byte(code >> 24)
1313
}
1414

1515
// FindKeyNameByShortCode finds key name by short code
16-
func FindKeyNameByShortCode(code byte) layout.KeyName {
16+
func FindKeyNameByShortCode(code uint8) layout.KeyName {
1717
for k, v := range layout.Keys {
1818
if ToShortKeyCode(v.Code) == code {
1919
return k
@@ -23,7 +23,7 @@ func FindKeyNameByShortCode(code byte) layout.KeyName {
2323
}
2424

2525
// FindShortKeyCode finds key short code by name
26-
func FindShortKeyCode(name layout.KeyName) byte {
26+
func FindShortKeyCode(name layout.KeyName) uint8 {
2727
code := layout.FindKeyCode(name)
2828
return ToShortKeyCode(code)
2929
}

features/keys/short_test.go

Lines changed: 42 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -5,6 +5,7 @@ import (
55
"testing"
66

77
"github.com/mishamyrt/nuga-lib/features/keys"
8+
"github.com/mishamyrt/nuga-lib/layout"
89
)
910

1011
func TestFromShortKeyCode(t *testing.T) {
@@ -48,3 +49,44 @@ func TestToShortKeyCode(t *testing.T) {
4849
})
4950
}
5051
}
52+
53+
func TestFindKeyNameByShortCode(t *testing.T) {
54+
tests := []struct {
55+
code byte
56+
expected layout.KeyName
57+
}{
58+
{0x10, layout.KeyM},
59+
{0x1C, layout.KeyY},
60+
{0x15, layout.KeyR},
61+
{0x17, layout.KeyT},
62+
{0x99, layout.KeyNone},
63+
}
64+
for _, tt := range tests {
65+
t.Run(fmt.Sprintf("%#x", tt.code), func(t *testing.T) {
66+
result := keys.FindKeyNameByShortCode(tt.code)
67+
if result != tt.expected {
68+
t.Errorf("FindKeyNameByShortCode(%#x): expected %s, got %s", tt.code, tt.expected, result)
69+
}
70+
})
71+
}
72+
}
73+
74+
func TestFindShortKeyCode(t *testing.T) {
75+
tests := []struct {
76+
name layout.KeyName
77+
expected byte
78+
}{
79+
{layout.KeyM, 0x10},
80+
{layout.KeyY, 0x1C},
81+
{layout.KeyR, 0x15},
82+
{layout.KeyT, 0x17},
83+
}
84+
for _, tt := range tests {
85+
t.Run(string(tt.name), func(t *testing.T) {
86+
result := keys.FindShortKeyCode(tt.name)
87+
if result != tt.expected {
88+
t.Errorf("FindShortKeyCode(%s): expected %#x, got %#x", tt.name, tt.expected, result)
89+
}
90+
})
91+
}
92+
}

0 commit comments

Comments
 (0)