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