Added booleans ...that was boring.
This commit is contained in:
parent
c29afaeacc
commit
1c8f5ffe7e
|
@ -0,0 +1,19 @@
|
||||||
|
package parser
|
||||||
|
|
||||||
|
import (
|
||||||
|
"git.makaay.nl/mauricem/go-parsekit/parse"
|
||||||
|
)
|
||||||
|
|
||||||
|
var (
|
||||||
|
// Booleans are just the tokens you're used to. Always lowercase.
|
||||||
|
trueOrFalse = a.Str("true").Or(a.Str("false"))
|
||||||
|
)
|
||||||
|
|
||||||
|
func (t *parser) startBoolean(p *parse.API) {
|
||||||
|
switch {
|
||||||
|
case p.Accept(tok.Boolean(nil, trueOrFalse)):
|
||||||
|
t.emitCommand(csetBoolVal, p.Result().Value(0).(bool))
|
||||||
|
default:
|
||||||
|
p.Expected("true or false")
|
||||||
|
}
|
||||||
|
}
|
|
@ -0,0 +1,20 @@
|
||||||
|
package parser
|
||||||
|
|
||||||
|
import (
|
||||||
|
"testing"
|
||||||
|
)
|
||||||
|
|
||||||
|
func TestBoolean(t *testing.T) {
|
||||||
|
for _, test := range []parseTest{
|
||||||
|
{``, []string{`Error: unexpected end of file (expected true or false) at start of file`}},
|
||||||
|
{`true`, []string{`boolean(true)`}},
|
||||||
|
{`false`, []string{`boolean(false)`}},
|
||||||
|
{`yes`, []string{`Error: unexpected input (expected true or false) at start of file`}},
|
||||||
|
{`no`, []string{`Error: unexpected input (expected true or false) at start of file`}},
|
||||||
|
{`1`, []string{`Error: unexpected input (expected true or false) at start of file`}},
|
||||||
|
{`0`, []string{`Error: unexpected input (expected true or false) at start of file`}},
|
||||||
|
} {
|
||||||
|
p := &parser{}
|
||||||
|
testParseHandler(t, p, p.startBoolean, test)
|
||||||
|
}
|
||||||
|
}
|
Loading…
Reference in New Issue