[keyboard] Adds more test coverage and fixes README install instructions

Signed-off-by: deadprogram <ron@hybridgroup.com>
This commit is contained in:
deadprogram 2016-05-24 10:34:22 -07:00
parent 050f6c0570
commit 9aad23b3c3
2 changed files with 48 additions and 1 deletions

View File

@ -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

View File

@ -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)
}