Merge branch 'master' of github.com:AlekseyLobanov/gokeystat

This commit is contained in:
Dmitry Lyukov
2016-03-25 22:47:37 +03:00
2 changed files with 33 additions and 0 deletions

View File

@@ -15,6 +15,10 @@ const (
KEYBOARD_BUFER_SIZE = 10000
)
func GetKeymapFromOutput(buf []byte) map[uint8]string {
return make(map[uint8]string)
}
// Extract pressed keys from bufer buf
// It returns slice with key numbers in the same order
func GetKeyNumsFromOutput(buf []byte) []uint8 {

View File

@@ -6,6 +6,35 @@ import (
"testing"
)
func TestGetKeymapFromOutput(t *testing.T) {
var buf []byte
var keymap map[uint8]string
const test1 = "keycode 19 = 0 parenright 0 parenright\n" +
"keycode 20 = minus underscore minus underscore\n" +
"keycode 21 = equal plus equal plus"
result1 := map[uint8]string{19: "0", 20: "minus", 21: "equal"}
const test2 = "keycode 119 = Delete NoSymbol Delete\n" +
"keycode 120 =\n" +
"keycode 121 = XF86AudioMute NoSymbol XF86AudioMute"
result2 := map[uint8]string{119: "Delete", 121: "XF86AudioMute"}
// Test1. Simple
buf = []byte(test1)
keymap = GetKeymapFromOutput(buf)
if !reflect.DeepEqual(keymap, result1) {
t.Fail()
}
// Test2. With empty keys
buf = []byte(test2)
keymap = GetKeymapFromOutput(buf)
if !reflect.DeepEqual(keymap, result2) {
t.Fail()
}
}
func TestGetKeyNumsFromOutput(t *testing.T) {
var buf []byte
var keyNums []uint8