Imported Upstream version 1.0.1

This commit is contained in:
Sébastien Delafond
2017-07-04 14:45:08 +02:00
parent 1ee35b841d
commit 4f12259bc0
5531 changed files with 1834599 additions and 742844 deletions
+58
View File
@@ -0,0 +1,58 @@
package query
import (
"fmt"
. "gopkg.in/check.v1"
)
type LexerSuite struct {
}
var _ = Suite(&LexerSuite{})
func (s *LexerSuite) TestLexing(c *C) {
_, ch := lex("query", "package (<< 1.3), $Source | !\"app\", 'd\"\\a\\'ta' {i386}")
c.Check(<-ch, Equals, item{typ: itemString, val: "package"})
c.Check(<-ch, Equals, item{typ: itemLeftParen, val: "("})
c.Check(<-ch, Equals, item{typ: itemLt, val: "<<"})
c.Check(<-ch, Equals, item{typ: itemString, val: "1.3"})
c.Check(<-ch, Equals, item{typ: itemRightParen, val: ")"})
c.Check(<-ch, Equals, item{typ: itemAnd, val: ","})
c.Check(<-ch, Equals, item{typ: itemString, val: "$Source"})
c.Check(<-ch, Equals, item{typ: itemOr, val: "|"})
c.Check(<-ch, Equals, item{typ: itemNot, val: "!"})
c.Check(<-ch, Equals, item{typ: itemString, val: "app"})
c.Check(<-ch, Equals, item{typ: itemAnd, val: ","})
c.Check(<-ch, Equals, item{typ: itemString, val: "d\"a'ta"})
c.Check(<-ch, Equals, item{typ: itemLeftCurly, val: "{"})
c.Check(<-ch, Equals, item{typ: itemString, val: "i386"})
c.Check(<-ch, Equals, item{typ: itemRightCurly, val: "}"})
c.Check(<-ch, Equals, item{typ: itemEOF, val: ""})
}
func (s *LexerSuite) TestConsume(c *C) {
l, _ := lex("query", "package (<< 1.3)")
c.Check(l.Current(), Equals, item{typ: itemString, val: "package"})
c.Check(l.Current(), Equals, item{typ: itemString, val: "package"})
l.Consume()
c.Check(l.Current(), Equals, item{typ: itemLeftParen, val: "("})
l.Consume()
c.Check(l.Current(), Equals, item{typ: itemLt, val: "<<"})
}
func (s *LexerSuite) TestString(c *C) {
l, _ := lex("query", "package (<< 1.3)")
c.Check(fmt.Sprintf("%s", l.Current()), Equals, "\"package\"")
l.Consume()
c.Check(fmt.Sprintf("%s", l.Current()), Equals, "(")
}
func (s *LexerSuite) TestError(c *C) {
l, _ := lex("query", "'package")
c.Check(fmt.Sprintf("%s", l.Current()), Equals, "error: unexpected eof in quoted string")
}