begin testing feature parsing
Этот коммит содержится в:
родитель
97b6998348
коммит
421f9d3e11
2 изменённых файлов: 35 добавлений и 3 удалений
|
@ -86,7 +86,7 @@ func Parse(path string) (*Feature, error) {
|
|||
|
||||
// reads tokens into AST and skips comments or new lines
|
||||
func (p *parser) next() *lexer.Token {
|
||||
if p.ast.tail.value.Type == lexer.EOF {
|
||||
if p.ast.tail != nil && p.ast.tail.value.Type == lexer.EOF {
|
||||
return p.ast.tail.value // has reached EOF, do not record it more than once
|
||||
}
|
||||
tok := p.lx.Next()
|
||||
|
@ -99,9 +99,10 @@ func (p *parser) next() *lexer.Token {
|
|||
|
||||
// peaks into next token, skips comments or new lines
|
||||
func (p *parser) peek() *lexer.Token {
|
||||
if tok := p.lx.Peek(); tok.OfType(lexer.COMMENT, lexer.NEW_LINE) {
|
||||
p.next()
|
||||
if tok := p.lx.Peek(); !tok.OfType(lexer.COMMENT, lexer.NEW_LINE) {
|
||||
return tok
|
||||
}
|
||||
p.next()
|
||||
return p.peek()
|
||||
}
|
||||
|
||||
|
|
31
gherkin/parse_feature_test.go
Обычный файл
31
gherkin/parse_feature_test.go
Обычный файл
|
@ -0,0 +1,31 @@
|
|||
package gherkin
|
||||
|
||||
import (
|
||||
"strings"
|
||||
"testing"
|
||||
|
||||
"github.com/l3pp4rd/go-behat/gherkin/lexer"
|
||||
)
|
||||
|
||||
var testFeatureSamples = map[string]string{
|
||||
"full": `Feature: gherkin parser
|
||||
in order to run features
|
||||
as gherkin lexer
|
||||
I need to be able to parse a feature`,
|
||||
"only_title": `Feature: gherkin`,
|
||||
}
|
||||
|
||||
func Test_normal_feature_parsing(t *testing.T) {
|
||||
p := &parser{
|
||||
lx: lexer.New(strings.NewReader(testFeatureSamples["full"])),
|
||||
path: "some.feature",
|
||||
ast: newAST(),
|
||||
}
|
||||
ft, err := p.parseFeature()
|
||||
if err != nil {
|
||||
t.Fatalf("unexpected error: %s", err)
|
||||
}
|
||||
if ft.Title != "gherkin parser" {
|
||||
t.Fatalf("the feature title '%s' was not expected", ft.Title)
|
||||
}
|
||||
}
|
Загрузка…
Создание таблицы
Сослаться в новой задаче