-
Notifications
You must be signed in to change notification settings - Fork 0
Expand file tree
/
Copy pathcommand_parser_test.go
More file actions
50 lines (46 loc) · 1.09 KB
/
command_parser_test.go
File metadata and controls
50 lines (46 loc) · 1.09 KB
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
package gobot
import (
"testing"
)
func TestParseSimpleCommand(t *testing.T) {
i := "SIMPLE"
command, err := Parse(i)
if err != nil {
t.Errorf("Error returned while parsing simple command %s", err)
}
if command.Command != i {
t.Errorf("Expected parser to return Command %s, but instead returned %s", i, command.Command)
}
}
func TestParseCommandReturnsArgs(t *testing.T) {
i := "SIMPLE X,Y,Z"
command, err := Parse(i)
if err != nil {
t.Errorf("Error returned while parsing simple command %s", err)
t.Fail()
return
}
if len(command.Args) != 3 {
t.Errorf("Expected Args to have a len() of 2, got %b", len(command.Args))
t.Fail()
return
}
if command.Args[0] != "X" {
t.Errorf("Arg 0 was not X, it was %s", command.Args[0])
t.Fail()
}
if command.Args[1] != "Y" {
t.Errorf("Arg 1 was not Y, it was %s", command.Args[1])
t.Fail()
}
if command.Args[2] != "Z" {
t.Errorf("Arg 2 was not Z, it was %s", command.Args[2])
t.Fail()
}
}
func TestEmptyCommandInvalid(t *testing.T) {
_, err := Parse("")
if err == nil {
t.Errorf("Expected empty command to be invalid")
}
}