From d2f98137cf6d2491f1a8cba8828fe4971be6a24e Mon Sep 17 00:00:00 2001 From: Aleksey Lobanov Date: Fri, 25 Mar 2016 22:08:35 +0300 Subject: [PATCH 1/2] Added GetKeymapFromOutput skeleton --- src/main.go | 4 ++++ 1 file changed, 4 insertions(+) diff --git a/src/main.go b/src/main.go index c864228..a47e01b 100644 --- a/src/main.go +++ b/src/main.go @@ -14,6 +14,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 { From 2900e6acdcb6e181c850152734e45762614b05a2 Mon Sep 17 00:00:00 2001 From: Aleksey Lobanov Date: Fri, 25 Mar 2016 22:26:40 +0300 Subject: [PATCH 2/2] Added basic tests for GetKeymapFromOutput --- src/main_test.go | 29 +++++++++++++++++++++++++++++ 1 file changed, 29 insertions(+) diff --git a/src/main_test.go b/src/main_test.go index fda0ec8..5086f3e 100644 --- a/src/main_test.go +++ b/src/main_test.go @@ -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