File: lex_test.go

package info (click to toggle)
aptly 1.6.2-2
  • links: PTS, VCS
  • area: main
  • in suites: forky, sid
  • size: 49,928 kB
  • sloc: python: 10,398; sh: 252; makefile: 184
file content (54 lines) | stat: -rw-r--r-- 1,878 bytes parent folder | download | duplicates (6)
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
51
52
53
54
package query

import . "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(l.Current().String(), Equals, "\"package\"")
	l.Consume()
	c.Check(l.Current().String(), Equals, "(")
}

func (s *LexerSuite) TestError(c *C) {
	l, _ := lex("query", "'package")

	c.Check(l.Current().String(), Equals, "error: unexpected eof in quoted string")
}