Fix Thing parsing for record IDs
This commit is contained in:
parent
1390c56501
commit
97513cdb65
3 changed files with 47 additions and 4 deletions
|
@ -674,7 +674,7 @@ type Thing struct {
|
||||||
func ParseThing(val string) *Thing {
|
func ParseThing(val string) *Thing {
|
||||||
r := strings.NewReader(val)
|
r := strings.NewReader(val)
|
||||||
s := newScanner(r)
|
s := newScanner(r)
|
||||||
if t, _, v := s.scanIdiom(); t == THING {
|
if t, _, v := s.scanThing(); t == THING {
|
||||||
return v.(*Thing)
|
return v.(*Thing)
|
||||||
}
|
}
|
||||||
return nil
|
return nil
|
||||||
|
|
|
@ -756,7 +756,7 @@ func (s *scanner) scanNumber(chp ...rune) (tok Token, lit string, val interface{
|
||||||
if chn := s.next(); chn == '+' {
|
if chn := s.next(); chn == '+' {
|
||||||
tok = DOUBLE
|
tok = DOUBLE
|
||||||
buf.WriteRune(chn)
|
buf.WriteRune(chn)
|
||||||
} else if ch == '-' {
|
} else if chn == '-' {
|
||||||
tok = DOUBLE
|
tok = DOUBLE
|
||||||
buf.WriteRune(chn)
|
buf.WriteRune(chn)
|
||||||
} else {
|
} else {
|
||||||
|
@ -765,7 +765,10 @@ func (s *scanner) scanNumber(chp ...rune) (tok Token, lit string, val interface{
|
||||||
case 's', 'h', 'd', 'w':
|
case 's', 'h', 'd', 'w':
|
||||||
tok = DURATION
|
tok = DURATION
|
||||||
case 'n', 'u', 'µ', 'm':
|
case 'n', 'u', 'µ', 'm':
|
||||||
if chn := s.next(); chn == 's' {
|
tok = DURATION
|
||||||
|
if chn := s.next(); chn == eof {
|
||||||
|
break
|
||||||
|
} else if chn == 's' {
|
||||||
tok = DURATION
|
tok = DURATION
|
||||||
buf.WriteRune(chn)
|
buf.WriteRune(chn)
|
||||||
} else if ch == 'm' {
|
} else if ch == 'm' {
|
||||||
|
@ -975,7 +978,7 @@ func (s *scanner) part() (tok Token, lit string, val interface{}) {
|
||||||
tok = ILLEGAL
|
tok = ILLEGAL
|
||||||
}
|
}
|
||||||
|
|
||||||
if tok != IDENT && tok != NUMBER && tok != DOUBLE {
|
if tok != IDENT && tok != NUMBER && tok != DOUBLE && tok != DURATION {
|
||||||
tok = ILLEGAL
|
tok = ILLEGAL
|
||||||
}
|
}
|
||||||
|
|
||||||
|
|
|
@ -180,6 +180,46 @@ func TestMain(t *testing.T) {
|
||||||
|
|
||||||
}
|
}
|
||||||
|
|
||||||
|
func Test_Parse_IDs(t *testing.T) {
|
||||||
|
|
||||||
|
Convey("All IDs should parse correctly", t, func() {
|
||||||
|
So(ParseThing("test:tester"), ShouldResemble, &Thing{
|
||||||
|
TB: "test",
|
||||||
|
ID: string("tester"),
|
||||||
|
})
|
||||||
|
So(ParseThing("test:123456"), ShouldResemble, &Thing{
|
||||||
|
TB: "test",
|
||||||
|
ID: float64(123456),
|
||||||
|
})
|
||||||
|
So(ParseThing("test:abcdef"), ShouldResemble, &Thing{
|
||||||
|
TB: "test",
|
||||||
|
ID: string("abcdef"),
|
||||||
|
})
|
||||||
|
So(ParseThing("test:a1b2c3"), ShouldResemble, &Thing{
|
||||||
|
TB: "test",
|
||||||
|
ID: string("a1b2c3"),
|
||||||
|
})
|
||||||
|
So(ParseThing("test:1a2b3c"), ShouldResemble, &Thing{
|
||||||
|
TB: "test",
|
||||||
|
ID: string("1a2b3c"),
|
||||||
|
})
|
||||||
|
So(ParseThing("test:4m9sms"), ShouldResemble, &Thing{
|
||||||
|
TB: "test",
|
||||||
|
ID: string("4m9sms"),
|
||||||
|
})
|
||||||
|
So(ParseThing("test:4m98m85ms"), ShouldResemble, &Thing{
|
||||||
|
TB: "test",
|
||||||
|
ID: string("4m98m85ms"),
|
||||||
|
})
|
||||||
|
So(ParseThing("test:00s5w36sm"), ShouldResemble, &Thing{
|
||||||
|
TB: "test",
|
||||||
|
ID: string("00s5w36sm"),
|
||||||
|
})
|
||||||
|
})
|
||||||
|
|
||||||
|
}
|
||||||
|
|
||||||
|
|
||||||
// Ensure the parser can parse a multi-statement query.
|
// Ensure the parser can parse a multi-statement query.
|
||||||
func Test_Parse_General(t *testing.T) {
|
func Test_Parse_General(t *testing.T) {
|
||||||
|
|
||||||
|
|
Loading…
Reference in a new issue