forked from getgauge/gauge
-
Notifications
You must be signed in to change notification settings - Fork 0
/
stepProcessor_test.go
198 lines (145 loc) · 7.1 KB
/
stepProcessor_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
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
121
122
123
124
125
126
127
128
129
130
131
132
133
134
135
136
137
138
139
140
141
142
143
144
145
146
147
148
149
150
151
152
153
154
155
156
157
158
159
160
161
162
163
164
165
166
167
168
169
170
171
172
173
174
175
176
177
178
179
180
181
182
183
184
185
186
187
188
189
190
191
192
193
194
195
196
197
198
package main
import (
. "gopkg.in/check.v1"
)
func (s *MySuite) TestParsingSimpleStep(c *C) {
parser := new(specParser)
specText := SpecBuilder().specHeading("Spec heading with hash ").scenarioHeading("Scenario Heading").step("sample step").String()
tokens, err := parser.generateTokens(specText)
c.Assert(err, IsNil)
c.Assert(len(tokens), Equals, 3)
stepToken := tokens[2]
c.Assert(stepToken.kind, Equals, stepKind)
c.Assert(stepToken.value, Equals, "sample step")
}
func (s *MySuite) TestParsingEmptyStepTextShouldThrowError(c *C) {
parser := new(specParser)
specText := SpecBuilder().specHeading("Spec heading with hash ").scenarioHeading("Scenario Heading").step("").String()
_, err := parser.generateTokens(specText)
c.Assert(err, NotNil)
c.Assert(err.Error(), Equals, "line no: 3, Step should not be blank")
}
func (s *MySuite) TestParsingStepWithParams(c *C) {
parser := new(specParser)
specText := SpecBuilder().specHeading("Spec heading with hash ").scenarioHeading("Scenario Heading").step("enter user \"john\"").String()
tokens, err := parser.generateTokens(specText)
c.Assert(err, IsNil)
c.Assert(len(tokens), Equals, 3)
stepToken := tokens[2]
c.Assert(stepToken.kind, Equals, stepKind)
c.Assert(stepToken.value, Equals, "enter user {static}")
c.Assert(len(stepToken.args), Equals, 1)
c.Assert(stepToken.args[0], Equals, "john")
}
func (s *MySuite) TestParsingStepWithParametersWithQuotes(c *C) {
parser := new(specParser)
specText := SpecBuilder().specHeading("Spec heading with hash ").scenarioHeading("Scenario Heading").step("\"param \\\"in quote\\\"\" step ").step("another * step with \"john 12 *-_{} \\\\ './;[]\" and \"second\"").String()
tokens, err := parser.generateTokens(specText)
c.Assert(err, IsNil)
c.Assert(len(tokens), Equals, 4)
firstStepToken := tokens[2]
c.Assert(firstStepToken.kind, Equals, stepKind)
c.Assert(firstStepToken.value, Equals, "{static} step")
c.Assert(len(firstStepToken.args), Equals, 1)
c.Assert(firstStepToken.args[0], Equals, "param \"in quote\"")
secondStepToken := tokens[3]
c.Assert(secondStepToken.kind, Equals, stepKind)
c.Assert(secondStepToken.value, Equals, "another * step with {static} and {static}")
c.Assert(len(secondStepToken.args), Equals, 2)
c.Assert(secondStepToken.args[0], Equals, "john 12 *-_{} \\ './;[]")
c.Assert(secondStepToken.args[1], Equals, "second")
}
func (s *MySuite) TestParsingStepWithUnmatchedOpeningQuote(c *C) {
parser := new(specParser)
specText := SpecBuilder().specHeading("Spec heading with hash ").scenarioHeading("Scenario Heading").step("sample step \"param").String()
_, err := parser.generateTokens(specText)
c.Assert(err, NotNil)
c.Assert(err.Error(), Equals, "line no: 3, String not terminated")
}
func (s *MySuite) TestParsingStepWithEscaping(c *C) {
parser := new(specParser)
specText := SpecBuilder().specHeading("Spec heading with hash ").scenarioHeading("Scenario Heading").step("step with \\").String()
tokens, err := parser.generateTokens(specText)
c.Assert(err, IsNil)
stepToken := tokens[2]
c.Assert(stepToken.value, Equals, "step with")
}
func (s *MySuite) TestParsingExceptionIfStepContainsReservedChars(c *C) {
parser := new(specParser)
specText := SpecBuilder().specHeading("Spec heading with hash ").scenarioHeading("Scenario Heading").step("step with {braces}").String()
_, err := parser.generateTokens(specText)
c.Assert(err, NotNil)
c.Assert(err.Error(), Equals, "line no: 3, '{' is a reserved character and should be escaped")
}
func (s *MySuite) TestParsingStepContainsEscapedReservedChars(c *C) {
parser := new(specParser)
specText := SpecBuilder().specHeading("Spec heading with hash ").scenarioHeading("Scenario Heading").step("step with \\{braces\\}").String()
tokens, err := parser.generateTokens(specText)
c.Assert(err, IsNil)
stepToken := tokens[2]
c.Assert(stepToken.value, Equals, "step with {braces}")
}
func (s *MySuite) TestParsingSimpleStepWithDynamicParameter(c *C) {
parser := new(specParser)
specText := SpecBuilder().specHeading("Spec heading with hash ").scenarioHeading("Scenario Heading").step("Step with \"static param\" and <name1>").String()
tokens, err := parser.generateTokens(specText)
c.Assert(err, IsNil)
c.Assert(len(tokens), Equals, 3)
stepToken := tokens[2]
c.Assert(stepToken.value, Equals, "Step with {static} and {dynamic}")
c.Assert(stepToken.args[0], Equals, "static param")
c.Assert(stepToken.args[1], Equals, "name1")
}
func (s *MySuite) TestParsingStepWithUnmatchedDynamicParameterCharacter(c *C) {
parser := new(specParser)
specText := SpecBuilder().specHeading("Spec heading with hash ").scenarioHeading("Scenario Heading").step("Step with \"static param\" and <name1").String()
_, err := parser.generateTokens(specText)
c.Assert(err, NotNil)
c.Assert(err.Error(), Equals, "line no: 3, Dynamic parameter not terminated")
}
func (s *MySuite) TestParsingContext(c *C) {
parser := new(specParser)
specText := SpecBuilder().specHeading("Spec heading with hash ").step("Context with \"param\"").scenarioHeading("Scenario Heading").String()
tokens, err := parser.generateTokens(specText)
c.Assert(err, IsNil)
contextToken := tokens[1]
c.Assert(contextToken.kind, Equals, stepKind)
c.Assert(contextToken.value, Equals, "Context with {static}")
c.Assert(contextToken.args[0], Equals, "param")
}
func (s *MySuite) TestParsingThrowsErrorWhenStepIsPresentWithoutStep(c *C) {
parser := new(specParser)
specText := SpecBuilder().step("step without spec heading").String()
tokens, err := parser.generateTokens(specText)
c.Assert(err, IsNil)
c.Assert(tokens[0].kind, Equals, stepKind)
c.Assert(tokens[0].value, Equals, "step without spec heading")
}
func (s *MySuite) TestParsingStepWithSimpleSpecialParameter(c *C) {
parser := new(specParser)
specText := SpecBuilder().specHeading("Spec heading with hash ").scenarioHeading("Scenario Heading").step("Step with special parameter <table:user.csv>").String()
tokens, err := parser.generateTokens(specText)
c.Assert(err, IsNil)
c.Assert(len(tokens), Equals, 3)
c.Assert(tokens[2].kind, Equals, stepKind)
c.Assert(tokens[2].value, Equals, "Step with special parameter {special}")
c.Assert(len(tokens[2].args), Equals, 1)
c.Assert(tokens[2].args[0], Equals, "table:user.csv")
}
func (s *MySuite) TestParsingStepWithSpecialParametersWithWhiteSpaces(c *C) {
parser := new(specParser)
specText := SpecBuilder().specHeading("Spec heading with hash ").step("Step with \"first\" and special parameter <table : user.csv>").step("Another with <name> and <file :something.txt>").String()
tokens, err := parser.generateTokens(specText)
c.Assert(err, IsNil)
c.Assert(len(tokens), Equals, 3)
c.Assert(tokens[1].kind, Equals, stepKind)
c.Assert(tokens[1].value, Equals, "Step with {static} and special parameter {special}")
c.Assert(len(tokens[1].args), Equals, 2)
c.Assert(tokens[1].args[0], Equals, "first")
c.Assert(tokens[1].args[1], Equals, "table : user.csv")
c.Assert(tokens[2].kind, Equals, stepKind)
c.Assert(tokens[2].value, Equals, "Another with {dynamic} and {special}")
c.Assert(len(tokens[2].args), Equals, 2)
c.Assert(tokens[2].args[0], Equals, "name")
c.Assert(tokens[2].args[1], Equals, "file :something.txt")
}