-
Notifications
You must be signed in to change notification settings - Fork 1
/
Copy pathterminal_node_test.go
64 lines (52 loc) · 1.65 KB
/
terminal_node_test.go
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
55
56
57
58
59
60
61
62
63
64
// Copyright (c) 2017 Opsidian Ltd.
//
// This Source Code Form is subject to the terms of the Mozilla Public
// License, v. 2.0. If a copy of the MPL was not distributed with this
// file, You can obtain one at http://mozilla.org/MPL/2.0/.
package ast_test
import (
. "github.com/onsi/ginkgo"
. "github.com/onsi/gomega"
"github.com/conflowio/parsley/ast"
"github.com/conflowio/parsley/parsley"
)
var _ = Describe("TerminalNode", func() {
var (
node *ast.TerminalNode
token = "TEST"
value = "some value"
schema = "string"
pos = parsley.Pos(1)
readerPos = parsley.Pos(2)
)
JustBeforeEach(func() {
node = ast.NewTerminalNode(schema, token, value, pos, readerPos)
})
Describe("Methods", func() {
It("Token() should return with the token value", func() {
Expect(node.Token()).To(Equal(token))
})
It("Schema() should return with the value's type", func() {
Expect(node.Schema()).To(Equal(schema))
})
It("EvaluateNode() should return with the value", func() {
nodeValue := node.Value()
Expect(nodeValue).To(Equal(value))
})
It("Pos() should return with the token value", func() {
Expect(node.Pos()).To(Equal(pos))
})
It("ReaderPos() should return with the reader position", func() {
Expect(node.ReaderPos()).To(Equal(readerPos))
})
It("SetReaderPos() should modify the reader position", func() {
node.SetReaderPos(func(pos parsley.Pos) parsley.Pos {
return parsley.Pos(pos + 1)
})
Expect(node.ReaderPos()).To(Equal(parsley.Pos(3)))
})
It("String() should return with a readable representation", func() {
Expect(node.String()).To(Equal("TEST{some value, 1..2}"))
})
})
})