diff --git a/platforms/keyboard/README.md b/platforms/keyboard/README.md index 079a1c24..896467ad 100644 --- a/platforms/keyboard/README.md +++ b/platforms/keyboard/README.md @@ -5,7 +5,7 @@ This module implements support for keyboard events, wrapping the `stty` utility. ## How to Install ``` -go get github.com/hybridgroup/gobot && go install github.com/hybridgroup/gobot/platforms/ardrone +go get github.com/hybridgroup/gobot && go install github.com/hybridgroup/gobot/platforms/keyboard ``` ## How to Use diff --git a/platforms/keyboard/keyboard_test.go b/platforms/keyboard/keyboard_test.go new file mode 100644 index 00000000..a60ed824 --- /dev/null +++ b/platforms/keyboard/keyboard_test.go @@ -0,0 +1,47 @@ +package keyboard + +import ( + "testing" + + "github.com/hybridgroup/gobot/gobottest" +) + +func TestParseSpace(t *testing.T) { + gobottest.Assert(t, Parse(bytes{32, 0, 0}).Key, Spacebar) +} + +func TestParseEscape(t *testing.T) { + gobottest.Assert(t, Parse(bytes{27, 0, 0}).Key, Escape) +} + +func TestParseNotEscape(t *testing.T) { + gobottest.Refute(t, Parse(bytes{27, 91, 65}).Key, Escape) +} + +func TestParseNumberKeys(t *testing.T) { + gobottest.Assert(t, Parse(bytes{48, 0, 0}).Key, 48) + gobottest.Assert(t, Parse(bytes{50, 0, 0}).Key, 50) + gobottest.Assert(t, Parse(bytes{57, 0, 0}).Key, 57) +} + +func TestParseAlphaKeys(t *testing.T) { + gobottest.Assert(t, Parse(bytes{97, 0, 0}).Key, 97) + gobottest.Assert(t, Parse(bytes{101, 0, 0}).Key, 101) + gobottest.Assert(t, Parse(bytes{122, 0, 0}).Key, 122) +} + +func TestParseNotAlphaKeys(t *testing.T) { + gobottest.Refute(t, Parse(bytes{132, 0, 0}).Key, 132) +} + +func TestParseArrowKeys(t *testing.T) { + gobottest.Assert(t, Parse(bytes{27, 91, 65}).Key, 65) + gobottest.Assert(t, Parse(bytes{27, 91, 66}).Key, 66) + gobottest.Assert(t, Parse(bytes{27, 91, 67}).Key, 67) + gobottest.Assert(t, Parse(bytes{27, 91, 68}).Key, 68) +} + +func TestParseNotArrowKeys(t *testing.T) { + gobottest.Refute(t, Parse(bytes{27, 91, 65}).Key, Escape) + gobottest.Refute(t, Parse(bytes{27, 91, 70}).Key, 70) +}