fix bug with empty boot command.

This commit is contained in:
Matthew Hooker 2018-04-21 11:40:47 -07:00
parent bcbee45bf9
commit e4bd30e53d
No known key found for this signature in database
GPG Key ID: 7B5F933D9CE8C6A1
2 changed files with 10 additions and 1 deletions

View File

@ -75,11 +75,14 @@ func (s expressionSequence) Validate() (errs []error) {
// GenerateExpressionSequence generates a sequence of expressions from the // GenerateExpressionSequence generates a sequence of expressions from the
// given command. This is the primary entry point to the boot command parser. // given command. This is the primary entry point to the boot command parser.
func GenerateExpressionSequence(command string) (expressionSequence, error) { func GenerateExpressionSequence(command string) (expressionSequence, error) {
seq := expressionSequence{}
if command == "" {
return seq, nil
}
got, err := ParseReader("", strings.NewReader(command)) got, err := ParseReader("", strings.NewReader(command))
if err != nil { if err != nil {
return nil, err return nil, err
} }
seq := expressionSequence{}
for _, exp := range got.([]interface{}) { for _, exp := range got.([]interface{}) {
seq = append(seq, exp.(expression)) seq = append(seq, exp.(expression))
} }

View File

@ -138,3 +138,9 @@ func Test_validation(t *testing.T) {
} }
} }
} }
func Test_empty(t *testing.T) {
exp, err := GenerateExpressionSequence("")
assert.NoError(t, err, "should have parsed an empty input okay.")
assert.Len(t, exp, 0)
}