-
Notifications
You must be signed in to change notification settings - Fork 1
/
end_test.go
56 lines (47 loc) · 1.55 KB
/
end_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
// 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 parser_test
import (
. "github.com/onsi/ginkgo"
. "github.com/onsi/gomega"
"github.com/conflowio/parsley/data"
"github.com/conflowio/parsley/parser"
"github.com/conflowio/parsley/parsley"
"github.com/conflowio/parsley/parsley/parsleyfakes"
)
var _ = Describe("End", func() {
var (
p = parser.End()
r *parsleyfakes.FakeReader
ctx *parsley.Context
)
BeforeEach(func() {
r = &parsleyfakes.FakeReader{}
ctx = parsley.NewContext(parsley.NewFileSet(), r)
})
Context("when at the end of the input", func() {
It("should return with an EOF node", func() {
r.IsEOFReturns(true)
r.PosReturns(parsley.Pos(2))
res, curtailingParsers, err := p.Parse(ctx, data.EmptyIntMap, 2)
Expect(curtailingParsers).To(Equal(data.EmptyIntSet))
Expect(res).To(Equal(parser.EndNode(parsley.Pos(2))))
Expect(err).ToNot(HaveOccurred())
})
})
Context("when not at the end of the input", func() {
It("should return with a nil result", func() {
r.IsEOFReturns(false)
r.PosReturns(parsley.Pos(2))
res, curtailingParsers, err := p.Parse(ctx, data.EmptyIntMap, 1)
Expect(curtailingParsers).To(Equal(data.EmptyIntSet))
Expect(res).To(BeNil())
Expect(err).To(HaveOccurred())
Expect(err.Error()).To(Equal("was expecting the end of input"))
Expect(err.Pos()).To(Equal(parsley.Pos(1)))
})
})
})