From 2900e6acdcb6e181c850152734e45762614b05a2 Mon Sep 17 00:00:00 2001 From: Aleksey Lobanov Date: Fri, 25 Mar 2016 22:26:40 +0300 Subject: [PATCH] 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