forked from getgauge/gauge
-
Notifications
You must be signed in to change notification settings - Fork 0
/
processor.go
120 lines (101 loc) · 3.2 KB
/
processor.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
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
103
104
105
106
107
108
109
110
111
112
113
114
115
116
117
118
119
120
// Copyright 2015 ThoughtWorks, Inc.
// This file is part of Gauge.
// Gauge is free software: you can redistribute it and/or modify
// it under the terms of the GNU General Public License as published by
// the Free Software Foundation, either version 3 of the License, or
// (at your option) any later version.
// Gauge is distributed in the hope that it will be useful,
// but WITHOUT ANY WARRANTY; without even the implied warranty of
// MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
// GNU General Public License for more details.
// You should have received a copy of the GNU General Public License
// along with Gauge. If not, see <http://www.gnu.org/licenses/>.
package parser
import (
"bytes"
"fmt"
"strings"
"github.com/getgauge/gauge/gauge"
)
func processSpec(parser *SpecParser, token *Token) ([]error, bool) {
return []error{}, false
}
func processTearDown(parser *SpecParser, token *Token) ([]error, bool) {
if len(token.Value) < 3 {
return []error{fmt.Errorf("Teardown should have at least three underscore characters")}, true
}
return []error{}, false
}
func processDataTable(parser *SpecParser, token *Token) ([]error, bool) {
if len(strings.TrimSpace(strings.Replace(token.Value, "table:", "", 1))) == 0 {
return []error{fmt.Errorf("Table location not specified")}, true
}
return []error{}, false
}
func processScenario(parser *SpecParser, token *Token) ([]error, bool) {
if len(strings.TrimSpace(token.Value)) < 1 {
return []error{fmt.Errorf("Scenario heading should have at least one character")}, true
}
parser.clearState()
return []error{}, false
}
func processComment(parser *SpecParser, token *Token) ([]error, bool) {
parser.clearState()
addStates(&parser.currentState, commentScope)
return []error{}, false
}
func processTag(parser *SpecParser, token *Token) ([]error, bool) {
parser.clearState()
tokens := splitAndTrimTags(token.Value)
for _, tagValue := range tokens {
if len(tagValue) > 0 {
token.Args = append(token.Args, tagValue)
}
}
return []error{}, false
}
func processTable(parser *SpecParser, token *Token) ([]error, bool) {
var buffer bytes.Buffer
shouldEscape := false
var errs []error
for i, element := range token.Value {
if i == 0 {
continue
}
if shouldEscape {
buffer.WriteRune(element)
shouldEscape = false
continue
}
if element == '\\' {
shouldEscape = true
continue
} else if element == '|' {
trimmedValue := strings.TrimSpace(buffer.String())
if token.Kind == gauge.TableHeader {
if len(trimmedValue) == 0 {
errs = append(errs, fmt.Errorf("Table header should not be blank"))
} else if arrayContains(token.Args, trimmedValue) {
errs = append(errs, fmt.Errorf("Table header cannot have repeated column values"))
}
}
token.Args = append(token.Args, trimmedValue)
buffer.Reset()
} else {
buffer.WriteRune(element)
}
}
if !isInState(parser.currentState, tableScope) {
addStates(&parser.currentState, tableScope)
} else {
addStates(&parser.currentState, tableDataScope)
}
return errs, false
}
func splitAndTrimTags(tag string) []string {
listOfTags := strings.Split(tag, ",")
for i, aTag := range listOfTags {
listOfTags[i] = strings.TrimSpace(aTag)
}
return listOfTags
}