Best Gauge code snippet using parser.GenerateTokens
lex_test.go
Source:lex_test.go
...11)12func (s *MySuite) TestParsingSpecHeading(c *C) {13 parser := new(SpecParser)14 specText := newSpecBuilder().specHeading("Spec Heading").String()15 tokens, err := parser.GenerateTokens(specText, "")16 c.Assert(err, IsNil)17 c.Assert(len(tokens), Equals, 1)18 c.Assert(tokens[0].Kind, Equals, gauge.SpecKind)19 c.Assert(tokens[0].Value, Equals, "Spec Heading")20}21func (s *MySuite) TestParsingASingleStep(c *C) {22 parser := new(SpecParser)23 tokens, err := parser.GenerateTokens("* test step \"arg\" ", "")24 c.Assert(err, IsNil)25 c.Assert(len(tokens), Equals, 1)26 c.Assert(tokens[0].Kind, Equals, gauge.StepKind)27}28func (s *MySuite) TestParsingMultipleSpecHeading(c *C) {29 parser := new(SpecParser)30 specText := newSpecBuilder().specHeading("Spec Heading").specHeading("Another Spec Heading").String()31 tokens, err := parser.GenerateTokens(specText, "")32 c.Assert(err, IsNil)33 c.Assert(len(tokens), Equals, 2)34 c.Assert(tokens[0].Kind, Equals, gauge.SpecKind)35 c.Assert(tokens[0].Value, Equals, "Spec Heading")36 c.Assert(tokens[1].Kind, Equals, gauge.SpecKind)37 c.Assert(tokens[1].Value, Equals, "Another Spec Heading")38}39func (s *MySuite) TestParsingThrowErrorForEmptySpecHeading(c *C) {40 parser := new(SpecParser)41 specText := newSpecBuilder().specHeading("").text("dsfdsf").String()42 _, res, err := parser.Parse(specText, gauge.NewConceptDictionary(), "foo.spec")43 c.Assert(err, IsNil)44 c.Assert(len(res.ParseErrors) > 0, Equals, true)45 c.Assert(res.ParseErrors[0].Error(), Equals, "foo.spec:1 Spec heading should have at least one character => ''")46}47func (s *MySuite) TestParsingScenarioHeading(c *C) {48 parser := new(SpecParser)49 specText := newSpecBuilder().specHeading("Spec Heading").scenarioHeading("First scenario").String()50 tokens, err := parser.GenerateTokens(specText, "")51 c.Assert(err, IsNil)52 c.Assert(len(tokens), Equals, 2)53 c.Assert(tokens[1].Kind, Equals, gauge.ScenarioKind)54 c.Assert(tokens[1].Value, Equals, "First scenario")55}56func (s *MySuite) TestParsingThrowErrorForEmptyScenarioHeading(c *C) {57 parser := new(SpecParser)58 specText := newSpecBuilder().specHeading("Spec Heading").scenarioHeading("").String()59 _, errs := parser.GenerateTokens(specText, "foo.spec")60 c.Assert(len(errs) > 0, Equals, true)61 c.Assert(errs[0].Error(), Equals, "foo.spec:2 Scenario heading should have at least one character => ''")62}63func (s *MySuite) TestParsingScenarioWithoutSpecHeading(c *C) {64 parser := new(SpecParser)65 specText := newSpecBuilder().scenarioHeading("Scenario Heading").String()66 tokens, err := parser.GenerateTokens(specText, "")67 c.Assert(err, IsNil)68 c.Assert(len(tokens), Equals, 1)69 c.Assert(tokens[0].Kind, Equals, gauge.ScenarioKind)70}71func (s *MySuite) TestParsingComments(c *C) {72 parser := new(SpecParser)73 specText := newSpecBuilder().specHeading("Spec Heading").text("Hello i am a comment ").text("### A h3 comment").String()74 tokens, err := parser.GenerateTokens(specText, "")75 c.Assert(err, IsNil)76 c.Assert(len(tokens), Equals, 3)77 c.Assert(tokens[1].Kind, Equals, gauge.CommentKind)78 c.Assert(tokens[1].Value, Equals, "Hello i am a comment")79 c.Assert(tokens[2].Kind, Equals, gauge.CommentKind)80 c.Assert(tokens[2].Value, Equals, "### A h3 comment")81}82func (s *MySuite) TestParsingSpecHeadingWithUnderlineOneChar(c *C) {83 parser := new(SpecParser)84 specText := newSpecBuilder().text("Spec heading with underline ").text("=").String()85 tokens, err := parser.GenerateTokens(specText, "")86 c.Assert(err, IsNil)87 c.Assert(len(tokens), Equals, 1)88 c.Assert(tokens[0].Kind, Equals, gauge.SpecKind)89 c.Assert(tokens[0].Value, Equals, "Spec heading with underline")90}91func (s *MySuite) TestParsingSpecHeadingWithUnderlineMultipleChar(c *C) {92 parser := new(SpecParser)93 specText := newSpecBuilder().text("Spec heading with underline ").text("=====").String()94 tokens, err := parser.GenerateTokens(specText, "")95 c.Assert(err, IsNil)96 c.Assert(len(tokens), Equals, 1)97 c.Assert(tokens[0].Kind, Equals, gauge.SpecKind)98 c.Assert(tokens[0].Value, Equals, "Spec heading with underline")99}100func (s *MySuite) TestParsingCommentWithUnderlineAndInvalidCharacters(c *C) {101 parser := new(SpecParser)102 specText := newSpecBuilder().text("A comment that will be with invalid underline").text("===89s").String()103 tokens, err := parser.GenerateTokens(specText, "")104 c.Assert(err, IsNil)105 c.Assert(len(tokens), Equals, 2)106 c.Assert(tokens[0].Kind, Equals, gauge.CommentKind)107 c.Assert(tokens[0].Value, Equals, "A comment that will be with invalid underline")108 c.Assert(tokens[1].Kind, Equals, gauge.CommentKind)109 c.Assert(tokens[1].Value, Equals, "===89s")110}111func (s *MySuite) TestParsingScenarioHeadingWithUnderline(c *C) {112 parser := new(SpecParser)113 specText := newSpecBuilder().text("Spec heading with underline ").text("=").text("Scenario heading with underline").text("-").String()114 tokens, err := parser.GenerateTokens(specText, "")115 c.Assert(err, IsNil)116 c.Assert(len(tokens), Equals, 2)117 c.Assert(tokens[0].Kind, Equals, gauge.SpecKind)118 c.Assert(tokens[0].Value, Equals, "Spec heading with underline")119 c.Assert(tokens[1].Kind, Equals, gauge.ScenarioKind)120 c.Assert(tokens[1].Value, Equals, "Scenario heading with underline")121}122func (s *MySuite) TestParsingScenarioHeadingWithUnderlineMultipleChar(c *C) {123 parser := new(SpecParser)124 specText := newSpecBuilder().text("Spec heading with underline ").text("=").text("Scenario heading with underline").text("----").String()125 tokens, err := parser.GenerateTokens(specText, "")126 c.Assert(err, IsNil)127 c.Assert(len(tokens), Equals, 2)128 c.Assert(tokens[0].Kind, Equals, gauge.SpecKind)129 c.Assert(tokens[0].Value, Equals, "Spec heading with underline")130 c.Assert(tokens[1].Kind, Equals, gauge.ScenarioKind)131 c.Assert(tokens[1].Value, Equals, "Scenario heading with underline")132}133func (s *MySuite) TestParsingHeadingWithUnderlineAndHash(c *C) {134 parser := new(SpecParser)135 specText := newSpecBuilder().specHeading("Spec heading with hash ").text("=====").scenarioHeading("Scenario heading with hash").text("----").String()136 tokens, err := parser.GenerateTokens(specText, "")137 c.Assert(err, IsNil)138 c.Assert(len(tokens), Equals, 4)139 c.Assert(tokens[0].Kind, Equals, gauge.SpecKind)140 c.Assert(tokens[0].Value, Equals, "Spec heading with hash")141 c.Assert(tokens[1].Kind, Equals, gauge.CommentKind)142 c.Assert(tokens[1].Value, Equals, "=====")143 c.Assert(tokens[2].Kind, Equals, gauge.ScenarioKind)144 c.Assert(tokens[2].Value, Equals, "Scenario heading with hash")145 c.Assert(tokens[3].Kind, Equals, gauge.CommentKind)146 c.Assert(tokens[3].Value, Equals, "----")147}148func (s *MySuite) TestParseSpecTags(c *C) {149 parser := new(SpecParser)150 specText := newSpecBuilder().specHeading("Spec heading with hash ").tags("tag1", "tag2").scenarioHeading("Scenario Heading").String()151 tokens, err := parser.GenerateTokens(specText, "")152 c.Assert(err, IsNil)153 c.Assert(len(tokens), Equals, 3)154 c.Assert(tokens[1].Kind, Equals, gauge.TagKind)155 c.Assert(len(tokens[1].Args), Equals, 2)156 c.Assert(tokens[1].Args[0], Equals, "tag1")157 c.Assert(tokens[1].Args[1], Equals, "tag2")158 c.Assert(tokens[1].LineText(), Equals, "tags: tag1,tag2")159 c.Assert(tokens[1].Value, Equals, "tag1,tag2")160}161func (s *MySuite) TestParseSpecTagsWithSpace(c *C) {162 parser := new(SpecParser)163 specText := newSpecBuilder().specHeading("Spec heading with hash ").text(" tags :tag1,tag2").scenarioHeading("Scenario Heading").String()164 tokens, err := parser.GenerateTokens(specText, "")165 c.Assert(err, IsNil)166 c.Assert(len(tokens), Equals, 3)167 c.Assert(tokens[1].Kind, Equals, gauge.TagKind)168 c.Assert(len(tokens[1].Args), Equals, 2)169 c.Assert(tokens[1].Args[0], Equals, "tag1")170 c.Assert(tokens[1].Args[1], Equals, "tag2")171 c.Assert(tokens[1].LineText(), Equals, " tags :tag1,tag2")172 c.Assert(tokens[1].Value, Equals, "tag1,tag2")173}174func (s *MySuite) TestParseEmptyTags(c *C) {175 parser := new(SpecParser)176 specText := newSpecBuilder().specHeading("Spec heading with hash ").tags("tag1", "", "tag2", "").scenarioHeading("Scenario Heading").String()177 tokens, err := parser.GenerateTokens(specText, "")178 c.Assert(err, IsNil)179 c.Assert(len(tokens), Equals, 3)180 c.Assert(tokens[1].Kind, Equals, gauge.TagKind)181 c.Assert(len(tokens[1].Args), Equals, 2)182 c.Assert(tokens[1].Args[0], Equals, "tag1")183 c.Assert(tokens[1].Args[1], Equals, "tag2")184 c.Assert(tokens[1].LineText(), Equals, "tags: tag1,,tag2,")185 c.Assert(tokens[1].Value, Equals, "tag1,,tag2,")186}187func (s *MySuite) TestParseScenarioTags(c *C) {188 parser := new(SpecParser)189 specText := newSpecBuilder().specHeading("Spec heading with hash ").scenarioHeading("Scenario Heading").tags("tag1", "tag2").String()190 tokens, err := parser.GenerateTokens(specText, "")191 c.Assert(err, IsNil)192 c.Assert(len(tokens), Equals, 3)193 c.Assert(tokens[2].Kind, Equals, gauge.TagKind)194 c.Assert(len(tokens[2].Args), Equals, 2)195 c.Assert(tokens[2].Args[0], Equals, "tag1")196 c.Assert(tokens[2].Args[1], Equals, "tag2")197 c.Assert(tokens[2].LineText(), Equals, "tags: tag1,tag2")198 c.Assert(tokens[2].Value, Equals, "tag1,tag2")199}200func (s *MySuite) TestParseScenarioWithTagsInMultipleLines(c *C) {201 parser := new(SpecParser)202 specText := newSpecBuilder().specHeading("Spec heading with hash ").scenarioHeading("Scenario Heading").tags("tag1", "\ntag2").String()203 tokens, err := parser.GenerateTokens(specText, "")204 c.Assert(err, IsNil)205 c.Assert(len(tokens), Equals, 4)206 c.Assert(tokens[2].Kind, Equals, gauge.TagKind)207 c.Assert(len(tokens[2].Args), Equals, 1)208 c.Assert(tokens[2].Args[0], Equals, "tag1")209 c.Assert(tokens[2].LineText(), Equals, "tags: tag1,")210 c.Assert(tokens[2].Value, Equals, "tag1,")211 c.Assert(tokens[3].Args[0], Equals, "tag2")212 c.Assert(tokens[3].LineText(), Equals, "tag2")213 c.Assert(tokens[3].Value, Equals, "tag2")214}215func (s *MySuite) TestParseSpecTagsBeforeSpecHeading(c *C) {216 parser := new(SpecParser)217 specText := newSpecBuilder().tags("tag1 ").specHeading("Spec heading with hash ").String()218 tokens, err := parser.GenerateTokens(specText, "")219 c.Assert(err, IsNil)220 c.Assert(len(tokens), Equals, 2)221 c.Assert(tokens[0].Kind, Equals, gauge.TagKind)222 c.Assert(len(tokens[0].Args), Equals, 1)223 c.Assert(tokens[0].Args[0], Equals, "tag1")224 c.Assert(tokens[0].LineText(), Equals, "tags: tag1 ")225 c.Assert(tokens[0].Value, Equals, "tag1")226}227func (s *MySuite) TestParsingSimpleDataTable(c *C) {228 parser := new(SpecParser)229 specText := newSpecBuilder().specHeading("Spec heading").text("|name|id|").text("|---|---|").text("|john|123|").text("|james|007|").String()230 tokens, err := parser.GenerateTokens(specText, "")231 c.Assert(err, IsNil)232 c.Assert(len(tokens), Equals, 5)233 c.Assert(tokens[1].Kind, Equals, gauge.TableHeader)234 c.Assert(len(tokens[1].Args), Equals, 2)235 c.Assert(tokens[1].Args[0], Equals, "name")236 c.Assert(tokens[1].Args[1], Equals, "id")237 c.Assert(tokens[2].Kind, Equals, gauge.TableRow)238 c.Assert(len(tokens[2].Args), Equals, 2)239 c.Assert(tokens[2].Args[0], Equals, "---")240 c.Assert(tokens[2].Args[1], Equals, "---")241 c.Assert(tokens[3].Kind, Equals, gauge.TableRow)242 c.Assert(len(tokens[3].Args), Equals, 2)243 c.Assert(tokens[3].Args[0], Equals, "john")244 c.Assert(tokens[3].Args[1], Equals, "123")245 c.Assert(tokens[4].Kind, Equals, gauge.TableRow)246 c.Assert(len(tokens[4].Args), Equals, 2)247 c.Assert(tokens[4].Args[0], Equals, "james")248 c.Assert(tokens[4].Args[1], Equals, "007")249}250func (s *MySuite) TestParsingMultipleDataTable(c *C) {251 parser := new(SpecParser)252 specText := newSpecBuilder().specHeading("Spec heading").text("|name|id|").text("|john|123|").text("|james|007|").step("Example step").text("|user|role|").text("|root | admin|").String()253 tokens, err := parser.GenerateTokens(specText, "")254 c.Assert(err, IsNil)255 c.Assert(len(tokens), Equals, 7)256 c.Assert(tokens[1].Kind, Equals, gauge.TableHeader)257 c.Assert(len(tokens[1].Args), Equals, 2)258 c.Assert(tokens[1].Args[0], Equals, "name")259 c.Assert(tokens[1].Args[1], Equals, "id")260 c.Assert(tokens[2].Kind, Equals, gauge.TableRow)261 c.Assert(len(tokens[2].Args), Equals, 2)262 c.Assert(tokens[2].Args[0], Equals, "john")263 c.Assert(tokens[2].Args[1], Equals, "123")264 c.Assert(tokens[3].Kind, Equals, gauge.TableRow)265 c.Assert(len(tokens[3].Args), Equals, 2)266 c.Assert(tokens[3].Args[0], Equals, "james")267 c.Assert(tokens[3].Args[1], Equals, "007")268 c.Assert(tokens[5].Kind, Equals, gauge.TableHeader)269 c.Assert(len(tokens[5].Args), Equals, 2)270 c.Assert(tokens[5].Args[0], Equals, "user")271 c.Assert(tokens[5].Args[1], Equals, "role")272 c.Assert(tokens[6].Kind, Equals, gauge.TableRow)273 c.Assert(len(tokens[6].Args), Equals, 2)274 c.Assert(tokens[6].Args[0], Equals, "root")275 c.Assert(tokens[6].Args[1], Equals, "admin")276}277func (s *MySuite) TestParsingDataTableWithEmptyHeaderSeparatorRow(c *C) {278 parser := new(SpecParser)279 specText := newSpecBuilder().specHeading("Spec heading").text("|name|id|").text("|||").text("|john|123|").String()280 tokens, err := parser.GenerateTokens(specText, "")281 c.Assert(err, IsNil)282 c.Assert(len(tokens), Equals, 4)283 c.Assert(tokens[1].Kind, Equals, gauge.TableHeader)284 c.Assert(len(tokens[1].Args), Equals, 2)285 c.Assert(tokens[1].Args[0], Equals, "name")286 c.Assert(tokens[1].Args[1], Equals, "id")287 c.Assert(tokens[2].Kind, Equals, gauge.TableRow)288 c.Assert(len(tokens[2].Args), Equals, 2)289 c.Assert(tokens[2].Args[0], Equals, "")290 c.Assert(tokens[2].Args[1], Equals, "")291 c.Assert(tokens[3].Kind, Equals, gauge.TableRow)292 c.Assert(len(tokens[3].Args), Equals, 2)293 c.Assert(tokens[3].Args[0], Equals, "john")294 c.Assert(tokens[3].Args[1], Equals, "123")295}296func (s *MySuite) TestParsingDataTableRowEscapingPipe(c *C) {297 parser := new(SpecParser)298 specText := newSpecBuilder().specHeading("Spec heading").text("| name|id | address| phone|").text("| escape \\| pipe |second|third|").String()299 tokens, err := parser.GenerateTokens(specText, "")300 c.Assert(err, IsNil)301 c.Assert(len(tokens), Equals, 3)302 c.Assert(tokens[1].Kind, Equals, gauge.TableHeader)303 c.Assert(len(tokens[1].Args), Equals, 4)304 c.Assert(tokens[1].Args[0], Equals, "name")305 c.Assert(tokens[1].Args[1], Equals, "id")306 c.Assert(tokens[1].Args[2], Equals, "address")307 c.Assert(tokens[1].Args[3], Equals, "phone")308 c.Assert(tokens[2].Kind, Equals, gauge.TableRow)309 c.Assert(len(tokens[2].Args), Equals, 3)310 c.Assert(tokens[2].Args[0], Equals, "escape | pipe")311 c.Assert(tokens[2].Args[1], Equals, "second")312 c.Assert(tokens[2].Args[2], Equals, "third")313}314func (s *MySuite) TestParsingDataTableThrowsErrorWithEmptyHeader(c *C) {315 parser := new(SpecParser)316 specText := newSpecBuilder().specHeading("Spec heading").text("| name|id |||").text("| escape \\| pipe |second|third|second|").String()317 _, errs := parser.GenerateTokens(specText, "foo.spec")318 c.Assert(len(errs) > 0, Equals, true)319 c.Assert(errs[0].Error(), Equals, "foo.spec:2 Table header should not be blank => '| name|id |||'")320}321func (s *MySuite) TestParsingDataTableThrowsErrorWithSameColumnHeader(c *C) {322 parser := new(SpecParser)323 specText := newSpecBuilder().specHeading("Spec heading").text("| name|id|name|").text("|1|2|3|").String()324 _, errs := parser.GenerateTokens(specText, "foo.spec")325 c.Assert(len(errs) > 0, Equals, true)326 c.Assert(errs[0].Error(), Equals, "foo.spec:2 Table header cannot have repeated column values => '| name|id|name|'")327}328func (s *MySuite) TestParsingDataTableWithSeparatorAsHeader(c *C) {329 parser := new(SpecParser)330 specText := newSpecBuilder().specHeading("Spec heading").text("|---|--|-|").text("|---|--|-|").text("|---|--|-|").text("| escape \\| pipe |second|third|").String()331 tokens, err := parser.GenerateTokens(specText, "")332 c.Assert(err, IsNil)333 c.Assert(len(tokens), Equals, 5)334 c.Assert(tokens[1].Kind, Equals, gauge.TableHeader)335 c.Assert(len(tokens[1].Args), Equals, 3)336 c.Assert(tokens[1].Args[0], Equals, "---")337 c.Assert(tokens[1].Args[1], Equals, "--")338 c.Assert(tokens[1].Args[2], Equals, "-")339 c.Assert(tokens[2].Kind, Equals, gauge.TableRow)340 c.Assert(len(tokens[2].Args), Equals, 3)341 c.Assert(tokens[2].Args[0], Equals, "---")342 c.Assert(tokens[2].Args[1], Equals, "--")343 c.Assert(tokens[2].Args[2], Equals, "-")344}345func (s *MySuite) TestParsingSpecWithMultipleLines(c *C) {346 parser := new(SpecParser)347 specText := newSpecBuilder().specHeading("A spec heading").348 text("Hello, i am a comment").349 text(" ").350 step("Context step with \"param\" and <file:foo>").351 text("|a|b|c|").352 text("|--||").353 text("|a1|a2|a3|").354 tags("one", "two").355 scenarioHeading("First flow").356 tags("tag1", "tag2").357 step("first with \"fpp\" and <bar>").358 text("").359 text("Comment in scenario").360 step("<table:file.csv> and <another> with \"foo\"").361 scenarioHeading("First flow").362 step("another").String()363 tokens, err := parser.GenerateTokens(specText, "")364 c.Assert(err, IsNil)365 c.Assert(len(tokens), Equals, 15)366 c.Assert(tokens[0].Kind, Equals, gauge.SpecKind)367 c.Assert(tokens[1].Kind, Equals, gauge.CommentKind)368 c.Assert(tokens[2].Kind, Equals, gauge.CommentKind)369 c.Assert(tokens[3].Kind, Equals, gauge.StepKind)370 c.Assert(tokens[3].Value, Equals, "Context step with {static} and {special}")371 c.Assert(tokens[4].Kind, Equals, gauge.TableHeader)372 c.Assert(tokens[5].Kind, Equals, gauge.TableRow)373 c.Assert(tokens[6].Kind, Equals, gauge.TableRow)374 c.Assert(tokens[7].Kind, Equals, gauge.TagKind)375 c.Assert(tokens[8].Kind, Equals, gauge.ScenarioKind)376 c.Assert(tokens[9].Kind, Equals, gauge.TagKind)377 c.Assert(tokens[10].Kind, Equals, gauge.StepKind)378 c.Assert(tokens[10].Value, Equals, "first with {static} and {dynamic}")379 c.Assert(tokens[11].Kind, Equals, gauge.CommentKind)380 c.Assert(tokens[12].Kind, Equals, gauge.StepKind)381 c.Assert(tokens[12].Value, Equals, "{special} and {dynamic} with {static}")382 c.Assert(tokens[13].Kind, Equals, gauge.ScenarioKind)383 c.Assert(tokens[14].Kind, Equals, gauge.StepKind)384 c.Assert(tokens[14].Value, Equals, "another")385}386func (s *MySuite) TestParsingSimpleScenarioDataTable(c *C) {387 parser := new(SpecParser)388 specText := newSpecBuilder().specHeading("Spec heading").389 scenarioHeading("Scenario Heading").390 text("|name|id|").391 text("|---|---|").392 text("|john|123|").393 text("|james|007|").String()394 tokens, err := parser.GenerateTokens(specText, "")395 c.Assert(err, IsNil)396 c.Assert(len(tokens), Equals, 6)397 c.Assert(tokens[2].Kind, Equals, gauge.TableHeader)398 c.Assert(len(tokens[2].Args), Equals, 2)399 c.Assert(tokens[2].Args[0], Equals, "name")400 c.Assert(tokens[2].Args[1], Equals, "id")401 c.Assert(tokens[3].Kind, Equals, gauge.TableRow)402 c.Assert(len(tokens[3].Args), Equals, 2)403 c.Assert(tokens[3].Args[0], Equals, "---")404 c.Assert(tokens[3].Args[1], Equals, "---")405 c.Assert(tokens[4].Kind, Equals, gauge.TableRow)406 c.Assert(len(tokens[4].Args), Equals, 2)407 c.Assert(tokens[4].Args[0], Equals, "john")408 c.Assert(tokens[4].Args[1], Equals, "123")409 c.Assert(tokens[5].Kind, Equals, gauge.TableRow)410 c.Assert(len(tokens[5].Args), Equals, 2)411 c.Assert(tokens[5].Args[0], Equals, "james")412 c.Assert(tokens[5].Args[1], Equals, "007")413}414func (s *MySuite) TestParsingExternalScenarioDataTable(c *C) {415 parser := new(SpecParser)416 specText := newSpecBuilder().specHeading("Spec heading").417 scenarioHeading("Scenario Heading").418 text("table:data/foo.csv").String()419 tokens, err := parser.GenerateTokens(specText, "")420 c.Assert(err, IsNil)421 c.Assert(len(tokens), Equals, 3)422 c.Assert(tokens[2].Kind, Equals, gauge.DataTableKind)423}424func (s *MySuite) TestParsingStepWIthNewlineAndTableParam(c *C) {425 parser := new(SpecParser)426 specText := newSpecBuilder().427 step("step1").428 text("").429 tableHeader("foo|bar").430 tableRow("somerow|another").String()431 tokens, err := parser.GenerateTokens(specText, "")432 c.Assert(err, IsNil)433 c.Assert(len(tokens), Equals, 3)434 c.Assert(tokens[0].Kind, Equals, gauge.StepKind)435 c.Assert(tokens[1].Kind, Equals, gauge.TableHeader)436 c.Assert(tokens[2].Kind, Equals, gauge.TableRow)437}438func (s *MySuite) TestParsingMultilineStep(c *C) {439 env.AllowMultiLineStep = func() bool { return true }440 parser := new(SpecParser)441 specText := newSpecBuilder().442 step("step1").443 text("second line").String()444 tokens, err := parser.GenerateTokens(specText, "")445 c.Assert(err, IsNil)446 c.Assert(len(tokens), Equals, 1)447 c.Assert(tokens[0].Kind, Equals, gauge.StepKind)448 c.Assert(tokens[0].Value, Equals, "step1 second line")449}450func (s *MySuite) TestParsingMultilineStepWithParams(c *C) {451 env.AllowMultiLineStep = func() bool { return true }452 parser := new(SpecParser)453 specText := newSpecBuilder().454 step("step1").455 text("second line \"foo\"").456 text("third line <bar>").String()457 tokens, err := parser.GenerateTokens(specText, "")458 c.Assert(err, IsNil)459 c.Assert(len(tokens), Equals, 1)460 c.Assert(tokens[0].Kind, Equals, gauge.StepKind)461 c.Assert(tokens[0].Value, Equals, "step1 second line {static} third line {dynamic}")462 c.Assert(len(tokens[0].Args), Equals, 2)463}464func (s *MySuite) TestParsingMultilineStepWithTableParam(c *C) {465 env.AllowMultiLineStep = func() bool { return true }466 parser := new(SpecParser)467 specText := newSpecBuilder().468 step("step1").469 text("second line").470 text("").471 tableHeader("foo|bar").472 tableRow("somerow|another").String()473 tokens, err := parser.GenerateTokens(specText, "")474 c.Assert(err, IsNil)475 c.Assert(len(tokens), Equals, 3)476 c.Assert(tokens[0].Kind, Equals, gauge.StepKind)477 c.Assert(tokens[1].Kind, Equals, gauge.TableHeader)478 c.Assert(tokens[2].Kind, Equals, gauge.TableRow)479}480func (s *MySuite) TestParsingMultilineStepScenarioNext(c *C) {481 env.AllowMultiLineStep = func() bool { return true }482 parser := new(SpecParser)483 specText := newSpecBuilder().484 step("step1").485 text("Scenario1").486 text("---------").String()487 tokens, err := parser.GenerateTokens(specText, "")488 c.Assert(err, IsNil)489 c.Assert(len(tokens), Equals, 2)490 c.Assert(tokens[0].Kind, Equals, gauge.StepKind)491 c.Assert(tokens[0].Value, Equals, "step1 Scenario1")492 c.Assert(tokens[1].Kind, Equals, gauge.CommentKind)493}494func (s *MySuite) TestParsingMultilineStepWithSpecNext(c *C) {495 env.AllowMultiLineStep = func() bool { return true }496 parser := new(SpecParser)497 specText := newSpecBuilder().498 step("step1").499 text("Concept1").500 text("========").String()501 tokens, err := parser.GenerateTokens(specText, "")502 c.Assert(err, IsNil)503 c.Assert(len(tokens), Equals, 2)504 c.Assert(tokens[0].Kind, Equals, gauge.StepKind)505 c.Assert(tokens[0].Value, Equals, "step1 Concept1")506 c.Assert(tokens[1].Kind, Equals, gauge.CommentKind)507}508func (s *MySuite) TestParsingSpecWithTearDownSteps(c *C) {509 parser := new(SpecParser)510 specText := newSpecBuilder().specHeading("A spec heading").511 text("Hello, i am a comment").512 scenarioHeading("First flow").513 step("another").514 text("_____").515 step("step1").516 step("step2").String()517 tokens, err := parser.GenerateTokens(specText, "")518 c.Assert(err, IsNil)519 c.Assert(len(tokens), Equals, 7)520 c.Assert(tokens[0].Kind, Equals, gauge.SpecKind)521 c.Assert(tokens[1].Kind, Equals, gauge.CommentKind)522 c.Assert(tokens[2].Kind, Equals, gauge.ScenarioKind)523 c.Assert(tokens[3].Kind, Equals, gauge.StepKind)524 c.Assert(tokens[3].Value, Equals, "another")525 c.Assert(tokens[4].Kind, Equals, gauge.TearDownKind)526 c.Assert(tokens[5].Kind, Equals, gauge.StepKind)527 c.Assert(tokens[5].Value, Equals, "step1")528 c.Assert(tokens[6].Kind, Equals, gauge.StepKind)529 c.Assert(tokens[6].Value, Equals, "step2")530}...
stepParser_test.go
Source:stepParser_test.go
...17)18func (s *MySuite) TestParsingSimpleStep(c *C) {19 parser := new(SpecParser)20 specText := SpecBuilder().specHeading("Spec heading with hash ").scenarioHeading("Scenario Heading").step("sample step").String()21 tokens, err := parser.GenerateTokens(specText, "")22 c.Assert(err, IsNil)23 c.Assert(len(tokens), Equals, 3)24 stepToken := tokens[2]25 c.Assert(stepToken.Kind, Equals, gauge.StepKind)26 c.Assert(stepToken.Value, Equals, "sample step")27}28func (s *MySuite) TestParsingEmptyStepTextShouldThrowError(c *C) {29 parser := new(SpecParser)30 specText := SpecBuilder().specHeading("Spec heading with hash ").scenarioHeading("Scenario Heading").step("").String()31 _, errs := parser.GenerateTokens(specText, "foo.spec")32 c.Assert(len(errs) > 0, Equals, true)33 c.Assert(errs[0].Error(), Equals, "foo.spec:3 Step should not be blank => ''")34}35func (s *MySuite) TestParsingStepWithParams(c *C) {36 parser := new(SpecParser)37 specText := SpecBuilder().specHeading("Spec heading with hash ").scenarioHeading("Scenario Heading").step("enter user \"john\"").String()38 tokens, err := parser.GenerateTokens(specText, "")39 c.Assert(err, IsNil)40 c.Assert(len(tokens), Equals, 3)41 stepToken := tokens[2]42 c.Assert(stepToken.Kind, Equals, gauge.StepKind)43 c.Assert(stepToken.Value, Equals, "enter user {static}")44 c.Assert(len(stepToken.Args), Equals, 1)45 c.Assert(stepToken.Args[0], Equals, "john")46}47func (s *MySuite) TestParsingStepWithParametersWithQuotes(c *C) {48 parser := new(SpecParser)49 specText := SpecBuilder().specHeading("Spec heading with hash ").scenarioHeading("Scenario Heading").step("\"param \\\"in quote\\\"\" step ").step("another * step with \"john 12 *-_{} \\\\ './;[]\" and \"second\"").String()50 tokens, err := parser.GenerateTokens(specText, "")51 c.Assert(err, IsNil)52 c.Assert(len(tokens), Equals, 4)53 firstStepToken := tokens[2]54 c.Assert(firstStepToken.Kind, Equals, gauge.StepKind)55 c.Assert(firstStepToken.Value, Equals, "{static} step")56 c.Assert(len(firstStepToken.Args), Equals, 1)57 c.Assert(firstStepToken.Args[0], Equals, "param \"in quote\"")58 secondStepToken := tokens[3]59 c.Assert(secondStepToken.Kind, Equals, gauge.StepKind)60 c.Assert(secondStepToken.Value, Equals, "another * step with {static} and {static}")61 c.Assert(len(secondStepToken.Args), Equals, 2)62 c.Assert(secondStepToken.Args[0], Equals, "john 12 *-_{} \\ './;[]")63 c.Assert(secondStepToken.Args[1], Equals, "second")64}65func (s *MySuite) TestParsingStepWithUnmatchedOpeningQuote(c *C) {66 parser := new(SpecParser)67 specText := SpecBuilder().specHeading("Spec heading with hash ").scenarioHeading("Scenario Heading").step("sample step \"param").String()68 _, errs := parser.GenerateTokens(specText, "foo.spec")69 c.Assert(len(errs) > 0, Equals, true)70 c.Assert(errs[0].Error(), Equals, "foo.spec:3 String not terminated => 'sample step \"param'")71}72func (s *MySuite) TestParsingStepWithEscaping(c *C) {73 parser := new(SpecParser)74 specText := SpecBuilder().specHeading("Spec heading with hash ").scenarioHeading("Scenario Heading").step("step with \\").String()75 tokens, err := parser.GenerateTokens(specText, "")76 c.Assert(err, IsNil)77 stepToken := tokens[2]78 c.Assert(stepToken.Value, Equals, "step with")79}80func (s *MySuite) TestParsingExceptionIfStepContainsReservedChars(c *C) {81 parser := new(SpecParser)82 specText := SpecBuilder().specHeading("Spec heading with hash ").scenarioHeading("Scenario Heading").step("step with {braces}").String()83 _, errs := parser.GenerateTokens(specText, "foo.spec")84 c.Assert(len(errs) > 0, Equals, true)85 c.Assert(errs[0].Error(), Equals, "foo.spec:3 '{' is a reserved character and should be escaped => 'step with {braces}'")86}87func (s *MySuite) TestParsingStepContainsEscapedReservedChars(c *C) {88 parser := new(SpecParser)89 specText := SpecBuilder().specHeading("Spec heading with hash ").scenarioHeading("Scenario Heading").step("step with \\{braces\\}").String()90 tokens, err := parser.GenerateTokens(specText, "")91 c.Assert(err, IsNil)92 stepToken := tokens[2]93 c.Assert(stepToken.Value, Equals, "step with {braces}")94}95func (s *MySuite) TestParsingSimpleStepWithDynamicParameter(c *C) {96 parser := new(SpecParser)97 specText := SpecBuilder().specHeading("Spec heading with hash ").scenarioHeading("Scenario Heading").step("Step with \"static param\" and <name1>").String()98 tokens, err := parser.GenerateTokens(specText, "")99 c.Assert(err, IsNil)100 c.Assert(len(tokens), Equals, 3)101 stepToken := tokens[2]102 c.Assert(stepToken.Value, Equals, "Step with {static} and {dynamic}")103 c.Assert(stepToken.Args[0], Equals, "static param")104 c.Assert(stepToken.Args[1], Equals, "name1")105}106func (s *MySuite) TestParsingStepWithUnmatchedDynamicParameterCharacter(c *C) {107 parser := new(SpecParser)108 specText := SpecBuilder().specHeading("Spec heading with hash ").scenarioHeading("Scenario Heading").step("Step with \"static param\" and <name1").String()109 _, errs := parser.GenerateTokens(specText, "foo.spec")110 c.Assert(len(errs) > 0, Equals, true)111 c.Assert(errs[0].Error(), Equals, "foo.spec:3 Dynamic parameter not terminated => 'Step with \"static param\" and <name1'")112}113func (s *MySuite) TestParsingContext(c *C) {114 parser := new(SpecParser)115 specText := SpecBuilder().specHeading("Spec heading with hash ").step("Context with \"param\"").scenarioHeading("Scenario Heading").String()116 tokens, err := parser.GenerateTokens(specText, "")117 c.Assert(err, IsNil)118 contextToken := tokens[1]119 c.Assert(contextToken.Kind, Equals, gauge.StepKind)120 c.Assert(contextToken.Value, Equals, "Context with {static}")121 c.Assert(contextToken.Args[0], Equals, "param")122}123func (s *MySuite) TestParsingThrowsErrorWhenStepIsPresentWithoutStep(c *C) {124 parser := new(SpecParser)125 specText := SpecBuilder().step("step without spec heading").String()126 tokens, err := parser.GenerateTokens(specText, "")127 c.Assert(err, IsNil)128 c.Assert(tokens[0].Kind, Equals, gauge.StepKind)129 c.Assert(tokens[0].Value, Equals, "step without spec heading")130}131func (s *MySuite) TestParsingStepWithSimpleSpecialParameter(c *C) {132 parser := new(SpecParser)133 specText := SpecBuilder().specHeading("Spec heading with hash ").scenarioHeading("Scenario Heading").step("Step with special parameter <table:user.csv>").String()134 tokens, err := parser.GenerateTokens(specText, "")135 c.Assert(err, IsNil)136 c.Assert(len(tokens), Equals, 3)137 c.Assert(tokens[2].Kind, Equals, gauge.StepKind)138 c.Assert(tokens[2].Value, Equals, "Step with special parameter {special}")139 c.Assert(len(tokens[2].Args), Equals, 1)140 c.Assert(tokens[2].Args[0], Equals, "table:user.csv")141}142func (s *MySuite) TestParsingStepWithSpecialParametersWithWhiteSpaces(c *C) {143 parser := new(SpecParser)144 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()145 tokens, err := parser.GenerateTokens(specText, "")146 c.Assert(err, IsNil)147 c.Assert(len(tokens), Equals, 3)148 c.Assert(tokens[1].Kind, Equals, gauge.StepKind)149 c.Assert(tokens[1].Value, Equals, "Step with {static} and special parameter {special}")150 c.Assert(len(tokens[1].Args), Equals, 2)151 c.Assert(tokens[1].Args[0], Equals, "first")152 c.Assert(tokens[1].Args[1], Equals, "table : user.csv")153 c.Assert(tokens[2].Kind, Equals, gauge.StepKind)154 c.Assert(tokens[2].Value, Equals, "Another with {dynamic} and {special}")155 c.Assert(len(tokens[2].Args), Equals, 2)156 c.Assert(tokens[2].Args[0], Equals, "name")157 c.Assert(tokens[2].Args[1], Equals, "file :something.txt")158}159func (s *MySuite) TestParsingStepWithStaticParamHavingEscapeChar(c *C) {...
GenerateTokens
Using AI Code Generation
1import (2func main() {3 fmt.Println("Hello World")4 p.GenerateTokens()5}6import (7func main() {8 fmt.Println("Hello World")9 p.GenerateTokens()10}
GenerateTokens
Using AI Code Generation
1import (2func main() {3 parser := parser.NewParser("test.txt")4 parser.GenerateTokens()5 fmt.Println(parser.Tokens)6}7import (8type Parser struct {9}10func NewParser(file string) *Parser {11 return &Parser{Tokens: []string{}}12}13func (p *Parser) GenerateTokens() {14 file, err := os.Open("test.txt")15 if err != nil {16 fmt.Println("Error in opening file: ", err)17 }18 defer file.Close()19 scanner := bufio.NewScanner(file)20 for scanner.Scan() {21 line := scanner.Text()22 words := strings.Fields(line)23 for _, word := range words {24 p.Tokens = append(p.Tokens, word)25 }26 }27}28import "fmt"29func main() {30 fmt.Println("Hello, World!")31}32func add(a int, b int) int {33}
GenerateTokens
Using AI Code Generation
1import (2func main() {3 fmt.Println("Hello World")4 parserObj.GenerateTokens("1.txt")5}6import (7func main() {8 fmt.Println("Hello World")9 parserObj.GenerateTokens("2.txt")10}11import (12func main() {13 fmt.Println("Hello World")14 parserObj.GenerateTokens("3.txt")15}16import (17func main() {18 fmt.Println("Hello World")19 parserObj.GenerateTokens("4.txt")20}21import (22func main() {23 fmt.Println("Hello World")24 parserObj.GenerateTokens("5.txt")25}26import (27func main() {28 fmt.Println("Hello World")29 parserObj.GenerateTokens("6.txt")30}31import (32func main() {33 fmt.Println("Hello World")34 parserObj.GenerateTokens("7.txt")35}36import (37func main() {38 fmt.Println("Hello World")39 parserObj.GenerateTokens("8.txt")40}41import (42func main() {43 fmt.Println("Hello World")44 parserObj.GenerateTokens("9.txt")45}
GenerateTokens
Using AI Code Generation
1import (2func main() {3 p := parser.Parser{}4 var s = stack.New()5 p.GenerateTokens("test.go", s)6 for s.Len() > 0 {7 fmt.Println(s.Pop())8 }9}10import (11func main() {12 p := parser.Parser{}13 var s = stack.New()14 p.GenerateTokens("test.go", s)15 p.GenerateAST(s)16 fmt.Println(p.AST)17}18import (19func main() {20 p := parser.Parser{}21 var s = stack.New()22 p.GenerateTokens("test.go", s)23 p.GenerateAST(s)24 p.GenerateCFG()25 fmt.Println(p.CFG)26}27import (28func main() {29 p := parser.Parser{}30 var s = stack.New()31 p.GenerateTokens("test.go", s)32 p.GenerateAST(s)33 p.GenerateCFG()34 p.GenerateICG()35 fmt.Println(p.ICG)36}37import (38func main() {39 p := parser.Parser{}40 var s = stack.New()41 p.GenerateTokens("test.go", s)42 p.GenerateAST(s)43 p.GenerateCFG()44 p.GenerateICG()
GenerateTokens
Using AI Code Generation
1import (2func main() {3 parser := new(parser.Parser)4 parser.Init("test.txt")5 tokens := parser.GenerateTokens()6 for _, token := range tokens {7 fmt.Println(token)8 }9}
GenerateTokens
Using AI Code Generation
1import (2type Token struct {3}4type Parser struct {5}6func NewParser(inputFile string, outputFile string) *Parser {7 parser := new(Parser)8 parser.tokens = make([]Token, 0)9 parser.keywords = []string{"if", "else", "while", "for", "int", "float", "char", "bool", "true", "false", "string", "return", "break", "continue"}10 parser.operators = []string{"+", "-", "*", "/", "%", "=", ">", "<", "!", "&", "|", "++", "--", "+=", "-=", "*=", "/=", "%=", "==", "!=", ">=", "<=", "&&", "||"}11 parser.delimiters = []string{"(", ")", "{", "}", "[", "]", ";", ",", "."}12 parser.specialSymbols = []string{"\"", "\\", " ", "\t", "\n"}13}14func (parser *Parser) isKeyword(str string) bool {15 for _, keyword := range parser.keywords {16 if str == keyword {17 }18 }19}20func (parser *Parser) isOperator(str string) bool {21 for _, operator := range parser.operators {22 if str == operator {23 }24 }25}26func (parser *Parser
GenerateTokens
Using AI Code Generation
1import (2func main() {3 p := parser.NewParser()4 l := lexer.NewLexer()5 p.GenerateTokens(l)6 fmt.Println(l.Tokens)7}8import (9func main() {10 p := parser.NewParser()11 l := lexer.NewLexer()12 p.GenerateTokens(l)13 fmt.Println(l.Tokens)14}15import (16func main() {17 p := parser.NewParser()18 l := lexer.NewLexer()19 p.GenerateTokens(l)20 fmt.Println(l.Tokens)21}22import (23func main() {24 p := parser.NewParser()25 l := lexer.NewLexer()26 p.GenerateTokens(l)27 fmt.Println(l.Tokens)28}29import (30func main() {31 p := parser.NewParser()
Learn to execute automation testing from scratch with LambdaTest Learning Hub. Right from setting up the prerequisites to run your first automation test, to following best practices and diving deeper into advanced test scenarios. LambdaTest Learning Hubs compile a list of step-by-step guides to help you be proficient with different test automation frameworks i.e. Selenium, Cypress, TestNG etc.
You could also refer to video tutorials over LambdaTest YouTube channel to get step by step demonstration from industry experts.
Get 100 minutes of automation test minutes FREE!!