How to use AddConcepts method of parser Package

Best Gauge code snippet using parser.AddConcepts

conceptParser_test.go

Source:conceptParser_test.go Github

copy

Full Screen

...32 step2Text := "test concept step 2"33 step1 := &gauge.Step{Value: step1Text, LineNo: 1, IsConcept: true, LineText: step1Text}34 step2 := &gauge.Step{Value: step2Text, LineNo: 4, IsConcept: true, LineText: step2Text}35 path, _ := filepath.Abs(filepath.Join("testdata", "concept.cpt"))36 concepts, errs, err := AddConcepts([]string{path}, dictionary)37 c.Assert(err, IsNil)38 c.Assert(len(concepts), Equals, 2)39 c.Assert(len(errs), Equals, 0)40 assertStepEqual(c, dictionary.ConceptsMap[step1Text].ConceptStep, step1)41 c.Assert(dictionary.ConceptsMap[step1Text].FileName, Equals, path)42 assertStepEqual(c, dictionary.ConceptsMap[step2Text].ConceptStep, step2)43 c.Assert(dictionary.ConceptsMap[step2Text].FileName, Equals, path)44}45func (s *MySuite) TestConceptDictionaryAddDuplicateConcept(c *C) {46 dictionary := gauge.NewConceptDictionary()47 path, _ := filepath.Abs(filepath.Join("testdata", "err", "cpt", "duplicate_concept.cpt"))48 concepts, errs, err := AddConcepts([]string{path}, dictionary)49 c.Assert(err, IsNil)50 c.Assert(len(concepts), Equals, 2)51 c.Assert(len(errs) > 0, Equals, true)52 c.Assert(hasParseError("Duplicate concept definition found", path, 1, errs), Equals, true)53 c.Assert(hasParseError("Duplicate concept definition found", path, 4, errs), Equals, true)54}55func hasParseError(eMessage, fileName string, lineNo int, errs []ParseError) bool {56 for _, e := range errs {57 if e.Message == eMessage && e.FileName == fileName && e.LineNo == lineNo {58 return true59 }60 }61 return false62}63func (s *MySuite) TestDuplicateConceptsinMultipleFile(c *C) {64 dictionary := gauge.NewConceptDictionary()65 cpt1, _ := filepath.Abs(filepath.Join("testdata", "err", "cpt", "concept.cpt"))66 cpt2, _ := filepath.Abs(filepath.Join("testdata", "err", "cpt", "duplicate.cpt"))67 AddConcepts([]string{cpt1}, dictionary)68 concepts, errs, err := AddConcepts([]string{cpt2}, dictionary)69 c.Assert(err, IsNil)70 c.Assert(len(concepts), Equals, 2)71 c.Assert(len(errs), Equals, 4)72 c.Assert(hasParseError("Duplicate concept definition found", cpt1, 1, errs), Equals, true)73 c.Assert(hasParseError("Duplicate concept definition found", cpt1, 4, errs), Equals, true)74 c.Assert(hasParseError("Duplicate concept definition found", cpt2, 1, errs), Equals, true)75 c.Assert(hasParseError("Duplicate concept definition found", cpt2, 4, errs), Equals, true)76}77func (s *MySuite) TestCreateConceptDictionaryGivesAllParseErrors(c *C) {78 config.ProjectRoot, _ = filepath.Abs(filepath.Join("testdata", "err", "cpt"))79 _, res, err := CreateConceptsDictionary()80 c.Assert(err, IsNil)81 c.Assert(res.Ok, Equals, false)82 c.Assert(len(res.ParseErrors), Equals, 9)83}84func (s *MySuite) TestCreateConceptDictionary(c *C) {85 config.ProjectRoot, _ = filepath.Abs(filepath.Join("testdata", "dir1"))86 dict, res, err := CreateConceptsDictionary()87 c.Assert(err, IsNil)88 c.Assert(res.Ok, Equals, true)89 c.Assert(dict, NotNil)90 c.Assert(len(dict.ConceptsMap), Equals, 1)91}92func (s *MySuite) TestConceptDictionaryWithNestedConcepts(c *C) {93 dictionary := gauge.NewConceptDictionary()94 path, _ := filepath.Abs(filepath.Join("testdata", "nested_concept.cpt"))95 AddConcepts([]string{path}, dictionary)96 concept := dictionary.Search("test concept step 1")97 c.Assert(len(concept.ConceptStep.ConceptSteps), Equals, 1)98 actualNestedConcept := concept.ConceptStep.ConceptSteps[0]99 c.Assert(actualNestedConcept.IsConcept, Equals, true)100 c.Assert(len(actualNestedConcept.ConceptSteps), Equals, 1)101 c.Assert(actualNestedConcept.ConceptSteps[0].Value, Equals, "step 2")102}103func (s *MySuite) TestConceptDictionaryWithNestedConceptsWithDynamicParameters(c *C) {104 conceptDictionary := gauge.NewConceptDictionary()105 path, _ := filepath.Abs(filepath.Join("testdata", "dynamic_param_concept.cpt"))106 AddConcepts([]string{path}, conceptDictionary)107 concept := conceptDictionary.Search("create user {} {} and {}")108 c.Assert(len(concept.ConceptStep.ConceptSteps), Equals, 1)109 actualNestedConcept := concept.ConceptStep.ConceptSteps[0]110 c.Assert(actualNestedConcept.IsConcept, Equals, true)111 c.Assert(len(actualNestedConcept.ConceptSteps), Equals, 2)112 c.Assert(actualNestedConcept.ConceptSteps[0].Value, Equals, "add id {}")113 c.Assert(actualNestedConcept.ConceptSteps[0].Args[0].ArgType, Equals, gauge.Dynamic)114 c.Assert(actualNestedConcept.ConceptSteps[0].Args[0].Value, Equals, "userid")115 c.Assert(actualNestedConcept.ConceptSteps[1].Value, Equals, "add name {}")116 c.Assert(actualNestedConcept.ConceptSteps[1].Args[0].ArgType, Equals, gauge.Dynamic)117 c.Assert(actualNestedConcept.ConceptSteps[1].Args[0].Value, Equals, "username")118}119func (s *MySuite) TestConceptDictionaryWithNestedConceptsWithStaticParameters(c *C) {120 conceptDictionary := gauge.NewConceptDictionary()121 path, _ := filepath.Abs(filepath.Join("testdata", "static_param_concept.cpt"))122 AddConcepts([]string{path}, conceptDictionary)123 concept := conceptDictionary.Search("create user {} {} and {}")124 c.Assert(len(concept.ConceptStep.ConceptSteps), Equals, 2)125 actualNestedConcept := concept.ConceptStep.ConceptSteps[0]126 c.Assert(actualNestedConcept.IsConcept, Equals, true)127 c.Assert(actualNestedConcept.Args[0].ArgType, Equals, gauge.Dynamic)128 c.Assert(actualNestedConcept.Args[0].Value, Equals, "user-id")129 c.Assert(actualNestedConcept.Args[1].ArgType, Equals, gauge.Static)130 c.Assert(actualNestedConcept.Args[1].Value, Equals, "static-value")131 useridArg, _ := actualNestedConcept.Lookup.GetArg("userid")132 usernameArg, _ := actualNestedConcept.Lookup.GetArg("username")133 c.Assert(useridArg.Value, Equals, "user-id")134 c.Assert(useridArg.ArgType, Equals, gauge.Dynamic)135 c.Assert(usernameArg.Value, Equals, "static-value")136 c.Assert(usernameArg.ArgType, Equals, gauge.Static)137 c.Assert(len(actualNestedConcept.ConceptSteps), Equals, 2)138 c.Assert(actualNestedConcept.ConceptSteps[0].Value, Equals, "add id {}")139 c.Assert(actualNestedConcept.ConceptSteps[0].Args[0].ArgType, Equals, gauge.Dynamic)140 c.Assert(actualNestedConcept.ConceptSteps[0].Args[0].Value, Equals, "userid")141 c.Assert(actualNestedConcept.ConceptSteps[1].Value, Equals, "add name {}")142 c.Assert(actualNestedConcept.ConceptSteps[1].Args[0].ArgType, Equals, gauge.Dynamic)143 c.Assert(actualNestedConcept.ConceptSteps[1].Args[0].Value, Equals, "username")144}145func (s *MySuite) TestConceptHavingItemsWithComments(c *C) {146 conceptDictionary := gauge.NewConceptDictionary()147 path, _ := filepath.Abs(filepath.Join("testdata", "dynamic_param_concept.cpt"))148 AddConcepts([]string{path}, conceptDictionary)149 concept := conceptDictionary.Search("create user {} {} and {}")150 c.Assert(len(concept.ConceptStep.Items), Equals, 3)151 c.Assert(concept.ConceptStep.Items[2].(*gauge.Comment).Value, Equals, "Comments")152 concept = conceptDictionary.Search("assign id {} and name {}")153 c.Assert(len(concept.ConceptStep.Items), Equals, 4)154 c.Assert(concept.ConceptStep.Items[3].(*gauge.Comment).Value, Equals, "Comment1")155}156func (s *MySuite) TestConceptHavingItemsWithTablesAndComments(c *C) {157 conceptDictionary := gauge.NewConceptDictionary()158 path, _ := filepath.Abs(filepath.Join("testdata", "tabular_concept.cpt"))159 AddConcepts([]string{path}, conceptDictionary)160 concept := conceptDictionary.Search("my concept {}")161 c.Assert(len(concept.ConceptStep.Items), Equals, 3)162 c.Assert(len(concept.ConceptStep.PreComments), Equals, 1)163 c.Assert(concept.ConceptStep.PreComments[0].Value, Equals, "COMMENT")164 c.Assert(concept.ConceptStep.Items[2].(*gauge.Comment).Value, Equals, " comment")165}166func (s *MySuite) TestMultiLevelConcept(c *C) {167 conceptDictionary := gauge.NewConceptDictionary()168 path, _ := filepath.Abs(filepath.Join("testdata", "nested_concept2.cpt"))169 AddConcepts([]string{path}, conceptDictionary)170 actualTopLevelConcept := conceptDictionary.Search("top level concept")171 c.Assert(len(actualTopLevelConcept.ConceptStep.ConceptSteps), Equals, 2)172 actualNestedConcept := actualTopLevelConcept.ConceptStep.ConceptSteps[0]173 c.Assert(actualNestedConcept.IsConcept, Equals, true)174 c.Assert(len(actualNestedConcept.ConceptSteps), Equals, 2)175 c.Assert(actualNestedConcept.ConceptSteps[0].Value, Equals, "another nested concept")176 c.Assert(actualNestedConcept.ConceptSteps[1].Value, Equals, "normal step 2")177 c.Assert(actualTopLevelConcept.ConceptStep.ConceptSteps[1].Value, Equals, "normal step 1")178 actualAnotherNestedConcept := conceptDictionary.Search("another nested concept")179 c.Assert(len(actualAnotherNestedConcept.ConceptStep.ConceptSteps), Equals, 1)180 step := actualAnotherNestedConcept.ConceptStep.ConceptSteps[0]181 c.Assert(step.IsConcept, Equals, false)182 c.Assert(step.Value, Equals, "normal step 3")183 nestedConcept2 := conceptDictionary.Search("nested concept")184 c.Assert(len(nestedConcept2.ConceptStep.ConceptSteps), Equals, 2)185 actualAnotherNestedConcept2 := nestedConcept2.ConceptStep.ConceptSteps[0]186 c.Assert(actualAnotherNestedConcept2.IsConcept, Equals, true)187 c.Assert(len(actualAnotherNestedConcept2.ConceptSteps), Equals, 1)188 c.Assert(actualAnotherNestedConcept2.ConceptSteps[0].Value, Equals, "normal step 3")189 c.Assert(nestedConcept2.ConceptStep.ConceptSteps[1].Value, Equals, "normal step 2")190}191func (s *MySuite) TestParsingSimpleConcept(c *C) {192 parser := new(ConceptParser)193 concepts, parseRes := parser.Parse("# my concept \n * first step \n * second step ", "")194 c.Assert(len(parseRes.ParseErrors), Equals, 0)195 c.Assert(len(concepts), Equals, 1)196 concept := concepts[0]197 c.Assert(concept.IsConcept, Equals, true)198 c.Assert(len(concept.ConceptSteps), Equals, 2)199 c.Assert(concept.ConceptSteps[0].Value, Equals, "first step")200 c.Assert(concept.ConceptSteps[1].Value, Equals, "second step")201}202func (s *MySuite) TestParsingConceptRetainsStepSuffix(c *C) {203 parser := new(ConceptParser)204 concepts, parseRes := parser.Parse("# my concept \n * first step \n * second step \n\n", "")205 c.Assert(len(parseRes.ParseErrors), Equals, 0)206 c.Assert(len(concepts), Equals, 1)207 concept := concepts[0]208 c.Assert(concept.IsConcept, Equals, true)209 c.Assert(len(concept.ConceptSteps), Equals, 2)210 c.Assert(concept.ConceptSteps[0].Value, Equals, "first step")211 c.Assert(concept.ConceptSteps[1].Value, Equals, "second step")212 c.Assert(concept.ConceptSteps[0].Suffix, Equals, "")213 c.Assert(concept.ConceptSteps[1].Suffix, Equals, "\n")214}215func (s *MySuite) TestErrorParsingConceptHeadingWithStaticOrSpecialParameter(c *C) {216 parser := new(ConceptParser)217 _, parseRes := parser.Parse("# my concept with \"parameter\" \n * first step \n * second step ", "foo.spec")218 c.Assert(len(parseRes.ParseErrors), Not(Equals), 0)219 c.Assert(parseRes.ParseErrors[0].Error(), Equals, "foo.spec:1 Concept heading can have only Dynamic Parameters => 'my concept with \"parameter\"'")220 _, parseRes = parser.Parse("# my concept with <table: foo> \n * first step \n * second step ", "foo2.spec")221 c.Assert(len(parseRes.ParseErrors), Not(Equals), 0)222 c.Assert(parseRes.ParseErrors[0].Error(), Equals, "foo2.spec:1 Dynamic parameter <table: foo> could not be resolved => 'my concept with <table: foo>'")223}224func (s *MySuite) TestErrorParsingConceptWithoutHeading(c *C) {225 parser := new(ConceptParser)226 _, parseRes := parser.Parse("* first step \n * second step ", "")227 c.Assert(len(parseRes.ParseErrors), Not(Equals), 0)228 c.Assert(parseRes.ParseErrors[0].Message, Equals, "Step is not defined inside a concept heading")229}230func (s *MySuite) TestErrorParsingConceptWithoutSteps(c *C) {231 parser := new(ConceptParser)232 _, parseRes := parser.Parse("# my concept with \n", "")233 c.Assert(len(parseRes.ParseErrors), Not(Equals), 0)234 c.Assert(parseRes.ParseErrors[0].Message, Equals, "Concept should have atleast one step")235}236func (s *MySuite) TestParsingSimpleConceptWithParameters(c *C) {237 parser := new(ConceptParser)238 concepts, parseRes := parser.Parse("# my concept with <param0> and <param1> \n * first step using <param0> \n * second step using \"value\" and <param1> ", "")239 c.Assert(len(parseRes.ParseErrors), Equals, 0)240 c.Assert(len(concepts), Equals, 1)241 concept := concepts[0]242 c.Assert(concept.IsConcept, Equals, true)243 c.Assert(len(concept.ConceptSteps), Equals, 2)244 // c.Assert(len(concept.Lookup.paramValue), Equals, 2)245 c.Assert(concept.Lookup.ContainsArg("param0"), Equals, true)246 c.Assert(concept.Lookup.ContainsArg("param1"), Equals, true)247 firstConcept := concept.ConceptSteps[0]248 c.Assert(firstConcept.Value, Equals, "first step using {}")249 c.Assert(len(firstConcept.Args), Equals, 1)250 c.Assert(firstConcept.Args[0].ArgType, Equals, gauge.Dynamic)251 c.Assert(firstConcept.Args[0].Value, Equals, "param0")252 secondConcept := concept.ConceptSteps[1]253 c.Assert(secondConcept.Value, Equals, "second step using {} and {}")254 c.Assert(len(secondConcept.Args), Equals, 2)255 c.Assert(secondConcept.Args[0].ArgType, Equals, gauge.Static)256 c.Assert(secondConcept.Args[0].Value, Equals, "value")257 c.Assert(secondConcept.Args[1].ArgType, Equals, gauge.Dynamic)258 c.Assert(secondConcept.Args[1].Value, Equals, "param1")259}260func (s *MySuite) TestErrorParsingConceptStepWithInvalidParameters(c *C) {261 parser := new(ConceptParser)262 _, parseRes := parser.Parse("# my concept with <param0> and <param1> \n * first step using <param3> \n * second step using \"value\" and <param1> ", "")263 c.Assert(len(parseRes.ParseErrors), Not(Equals), 0)264 c.Assert(parseRes.ParseErrors[0].Message, Equals, "Dynamic parameter <param3> could not be resolved")265}266func (s *MySuite) TestParsingMultipleConcept(c *C) {267 parser := new(ConceptParser)268 concepts, parseRes := parser.Parse("# my concept \n * first step \n * second step \n# my second concept \n* next step\n # my third concept <param0>\n * next step <param0> and \"value\"\n ", "")269 c.Assert(len(parseRes.ParseErrors), Equals, 0)270 c.Assert(len(concepts), Equals, 3)271 firstConcept := concepts[0]272 secondConcept := concepts[1]273 thirdConcept := concepts[2]274 c.Assert(firstConcept.IsConcept, Equals, true)275 c.Assert(len(firstConcept.ConceptSteps), Equals, 2)276 c.Assert(firstConcept.ConceptSteps[0].Value, Equals, "first step")277 c.Assert(firstConcept.ConceptSteps[1].Value, Equals, "second step")278 c.Assert(secondConcept.IsConcept, Equals, true)279 c.Assert(len(secondConcept.ConceptSteps), Equals, 1)280 c.Assert(secondConcept.ConceptSteps[0].Value, Equals, "next step")281 c.Assert(thirdConcept.IsConcept, Equals, true)282 c.Assert(len(thirdConcept.ConceptSteps), Equals, 1)283 c.Assert(thirdConcept.ConceptSteps[0].Value, Equals, "next step {} and {}")284 c.Assert(len(thirdConcept.ConceptSteps[0].Args), Equals, 2)285 c.Assert(thirdConcept.ConceptSteps[0].Args[0].ArgType, Equals, gauge.Dynamic)286 c.Assert(thirdConcept.ConceptSteps[0].Args[1].ArgType, Equals, gauge.Static)287 // c.Assert(len(thirdConcept.Lookup.paramValue), Equals, 1)288 c.Assert(thirdConcept.Lookup.ContainsArg("param0"), Equals, true)289}290func (s *MySuite) TestParsingConceptStepWithInlineTable(c *C) {291 parser := new(ConceptParser)292 concepts, parseRes := parser.Parse("# my concept <foo> \n * first step with <foo> and inline table\n |id|name|\n|1|vishnu|\n|2|prateek|\n", "")293 c.Assert(len(parseRes.ParseErrors), Equals, 0)294 c.Assert(len(concepts), Equals, 1)295 concept := concepts[0]296 c.Assert(concept.IsConcept, Equals, true)297 c.Assert(len(concept.ConceptSteps), Equals, 1)298 c.Assert(concept.ConceptSteps[0].Value, Equals, "first step with {} and inline table {}")299 tableArgument := concept.ConceptSteps[0].Args[1]300 c.Assert(tableArgument.ArgType, Equals, gauge.TableArg)301 inlineTable := tableArgument.Table302 c.Assert(inlineTable.IsInitialized(), Equals, true)303 idCells, _ := inlineTable.Get("id")304 nameCells, _ := inlineTable.Get("name")305 c.Assert(len(idCells), Equals, 2)306 c.Assert(len(nameCells), Equals, 2)307 c.Assert(idCells[0].Value, Equals, "1")308 c.Assert(idCells[0].CellType, Equals, gauge.Static)309 c.Assert(idCells[1].Value, Equals, "2")310 c.Assert(idCells[1].CellType, Equals, gauge.Static)311 c.Assert(nameCells[0].Value, Equals, "vishnu")312 c.Assert(nameCells[0].CellType, Equals, gauge.Static)313 c.Assert(nameCells[1].Value, Equals, "prateek")314 c.Assert(nameCells[1].CellType, Equals, gauge.Static)315}316func (s *MySuite) TestErrorParsingConceptWithInvalidInlineTable(c *C) {317 parser := new(ConceptParser)318 _, parseRes := parser.Parse("# my concept \n |id|name|\n|1|vishnu|\n|2|prateek|\n", "")319 c.Assert(len(parseRes.ParseErrors), Not(Equals), 0)320 c.Assert(parseRes.ParseErrors[0].Message, Equals, "Table doesn't belong to any step")321}322func (s *MySuite) TestNestedConceptLooksUpArgsFromParent(c *C) {323 parser := new(SpecParser)324 specText := newSpecBuilder().specHeading("A spec heading").325 scenarioHeading("First flow").326 step("create user \"foo\" \"doo\"").327 step("another step").String()328 dictionary := gauge.NewConceptDictionary()329 path, _ := filepath.Abs(filepath.Join("testdata", "param_nested_concept.cpt"))330 AddConcepts([]string{path}, dictionary)331 tokens, _ := parser.GenerateTokens(specText, "")332 spec, parseResult, _ := parser.CreateSpecification(tokens, dictionary, "")333 c.Assert(parseResult.Ok, Equals, true)334 firstStepInSpec := spec.Scenarios[0].Steps[0]335 nestedConcept := firstStepInSpec.ConceptSteps[0]336 nestedConceptArg1, _ := nestedConcept.GetArg("baz")337 c.Assert(nestedConceptArg1.Value, Equals, "foo")338 nestedConceptArg2, _ := nestedConcept.GetArg("boo")339 c.Assert(nestedConceptArg2.Value, Equals, "doo")340}341func (s *MySuite) TestNestedConceptLooksUpDataTableArgs(c *C) {342 parser := new(SpecParser)343 specText := newSpecBuilder().specHeading("A spec heading").344 tableHeader("id", "name", "phone").345 tableHeader("123", "prateek", "8800").346 tableHeader("456", "apoorva", "9800").347 tableHeader("789", "srikanth", "7900").348 scenarioHeading("First scenario").349 step("create user <id> <name>").350 step("another step").String()351 dictionary := gauge.NewConceptDictionary()352 path, _ := filepath.Abs(filepath.Join("testdata", "param_nested_concept.cpt"))353 AddConcepts([]string{path}, dictionary)354 tokens, _ := parser.GenerateTokens(specText, "")355 spec, parseResult, _ := parser.CreateSpecification(tokens, dictionary, "")356 c.Assert(parseResult.Ok, Equals, true)357 firstStepInSpec := spec.Scenarios[0].Steps[0]358 c.Assert(firstStepInSpec.IsConcept, Equals, true)359 barArg, _ := firstStepInSpec.GetArg("bar")360 farArg, _ := firstStepInSpec.GetArg("far")361 c.Assert(barArg.ArgType, Equals, gauge.Dynamic)362 c.Assert(farArg.ArgType, Equals, gauge.Dynamic)363 c.Assert(barArg.Value, Equals, "id")364 c.Assert(farArg.Value, Equals, "name")365 nestedConcept := firstStepInSpec.ConceptSteps[0]366 bazArg, _ := nestedConcept.GetArg("baz")367 booArg, _ := nestedConcept.GetArg("boo")368 c.Assert(bazArg.ArgType, Equals, gauge.Dynamic)369 c.Assert(booArg.ArgType, Equals, gauge.Dynamic)370 c.Assert(bazArg.Value, Equals, "id")371 c.Assert(booArg.Value, Equals, "name")372}373func (s *MySuite) TestNestedConceptLooksUpWhenParameterPlaceholdersAreSame(c *C) {374 parser := new(SpecParser)375 specText := newSpecBuilder().specHeading("A spec heading").376 tableHeader("id", "name", "phone").377 tableHeader("123", "prateek", "8800").378 tableHeader("456", "apoorva", "9800").379 tableHeader("789", "srikanth", "7900").380 scenarioHeading("First scenario").381 step("create user <id> <name> and <phone>").382 step("another step").String()383 dictionary := gauge.NewConceptDictionary()384 path, _ := filepath.Abs(filepath.Join("testdata", "param_nested_concept2.cpt"))385 AddConcepts([]string{path}, dictionary)386 tokens, _ := parser.GenerateTokens(specText, "")387 spec, parseResult, _ := parser.CreateSpecification(tokens, dictionary, "")388 c.Assert(parseResult.Ok, Equals, true)389 firstStepInSpec := spec.Scenarios[0].Steps[0]390 c.Assert(firstStepInSpec.IsConcept, Equals, true)391 useridArg, _ := firstStepInSpec.GetArg("user-id")392 usernameArg, _ := firstStepInSpec.GetArg("user-name")393 userphoneArg, _ := firstStepInSpec.GetArg("user-phone")394 c.Assert(useridArg.ArgType, Equals, gauge.Dynamic)395 c.Assert(usernameArg.ArgType, Equals, gauge.Dynamic)396 c.Assert(userphoneArg.ArgType, Equals, gauge.Dynamic)397 c.Assert(useridArg.Value, Equals, "id")398 c.Assert(usernameArg.Value, Equals, "name")399 c.Assert(userphoneArg.Value, Equals, "phone")400 nestedConcept := firstStepInSpec.ConceptSteps[0]401 useridArg2, _ := nestedConcept.GetArg("user-id")402 usernameArg2, _ := nestedConcept.GetArg("user-name")403 c.Assert(useridArg2.ArgType, Equals, gauge.Dynamic)404 c.Assert(usernameArg2.ArgType, Equals, gauge.Dynamic)405 c.Assert(useridArg2.Value, Equals, "id")406 c.Assert(usernameArg2.Value, Equals, "name")407}408func (s *MySuite) TestErrorOnCircularReferenceInConcept(c *C) {409 cd := gauge.NewConceptDictionary()410 cd.ConceptsMap["concept"] = &gauge.Concept{ConceptStep: &gauge.Step{LineText: "concept", Value: "concept", IsConcept: true, ConceptSteps: []*gauge.Step{&gauge.Step{LineText: "concept", Value: "concept", IsConcept: true}}}, FileName: "filename.cpt"}411 res := ValidateConcepts(cd)412 c.Assert(containsAny(res.ParseErrors, "Circular reference found"), Equals, true)413}414func (s *MySuite) TestValidateConceptShouldRemoveCircularConceptsConceptStepFromDictionary(c *C) {415 cd := gauge.NewConceptDictionary()416 cd.ConceptsMap["concept"] = &gauge.Concept{ConceptStep: &gauge.Step{LineText: "concept", Value: "concept", IsConcept: true, ConceptSteps: []*gauge.Step{&gauge.Step{LineText: "concept", Value: "concept", IsConcept: true}}}, FileName: "filename.cpt"}417 cd.ConceptsMap["concept2"] = &gauge.Concept{ConceptStep: &gauge.Step{LineText: "concept2", Value: "concept2", IsConcept: true, ConceptSteps: []*gauge.Step{&gauge.Step{LineText: "concept", Value: "concept", IsConcept: true}}}, FileName: "filename.cpt"}418 res := ValidateConcepts(cd)419 c.Assert(cd.ConceptsMap["concept"], Equals, (*gauge.Concept)(nil))420 c.Assert(len(cd.ConceptsMap["concept2"].ConceptStep.ConceptSteps), Equals, 0)421 c.Assert(len(res.ParseErrors), Equals, 2)422 c.Assert(strings.Contains(res.ParseErrors[0].Message, "Circular reference found"), Equals, true)423 c.Assert(strings.Contains(res.ParseErrors[1].Message, "Circular reference found"), Equals, true)424}425func (s *MySuite) TestValidateConceptShouldRemoveCircularConceptsFromDictionary(c *C) {426 cd := gauge.NewConceptDictionary()427 c1 := &gauge.Step{LineText: "concept", Value: "concept", IsConcept: true, ConceptSteps: []*gauge.Step{&gauge.Step{LineText: "concept2", Value: "concept2", IsConcept: true}}}428 c2 := &gauge.Step{LineText: "concept2", Value: "concept2", IsConcept: true, ConceptSteps: []*gauge.Step{&gauge.Step{LineText: "concept", Value: "concept", IsConcept: true}}}429 AddConcept([]*gauge.Step{c1, c2}, "filename.cpt", cd)430 res := ValidateConcepts(cd)431 c.Assert(cd.ConceptsMap["concept"], Equals, (*gauge.Concept)(nil))432 c.Assert(cd.ConceptsMap["concept2"], Equals, (*gauge.Concept)(nil))433 c.Assert(len(res.ParseErrors), Equals, 2)434 c.Assert(strings.Contains(res.ParseErrors[0].Message, "Circular reference found"), Equals, true)435 c.Assert(strings.Contains(res.ParseErrors[1].Message, "Circular reference found"), Equals, true)436}437func (s *MySuite) TestRemoveAllReferences(c *C) {438 cd := gauge.NewConceptDictionary()439 cpt1 := &gauge.Concept{ConceptStep: &gauge.Step{LineText: "concept", Value: "concept", IsConcept: true, ConceptSteps: []*gauge.Step{&gauge.Step{LineText: "concept", Value: "concept", IsConcept: true}}}, FileName: "filename.cpt"}440 cd.ConceptsMap["concept"] = cpt1441 cd.ConceptsMap["concept2"] = &gauge.Concept{ConceptStep: &gauge.Step{LineText: "concept2", Value: "concept2", IsConcept: true, ConceptSteps: []*gauge.Step{&gauge.Step{LineText: "concept", Value: "concept", IsConcept: true}}}, FileName: "filename.cpt"}442 c.Assert(len(cd.ConceptsMap["concept2"].ConceptStep.ConceptSteps), Equals, 1)443 removeAllReferences(cd, cpt1)444 c.Assert(len(cd.ConceptsMap["concept2"].ConceptStep.ConceptSteps), Equals, 0)445}446func (s *MySuite) TestReplaceNestedConceptsWithCircularReference(c *C) {447 lookup := gauge.ArgLookup{}448 lookup.AddArgName("a")449 lookup.AddArgValue("a", &gauge.StepArg{Name: "", Value: "a", ArgType: gauge.Static})450 lookup.ParamIndexMap = make(map[string]int)451 lookup.ParamIndexMap["a"] = 0452 cd := gauge.NewConceptDictionary()453 path, _ := filepath.Abs(filepath.Join("testdata", "err", "cpt", "circular_concept.cpt"))454 AddConcepts([]string{path}, cd)455 concept := cd.Search("concept1 {}")456 c.Assert(concept.ConceptStep.ConceptSteps[0].Lookup, DeepEquals, lookup)457}458func (s *MySuite) TestErrorParsingConceptWithRecursiveCallToConcept(c *C) {459 cd := gauge.NewConceptDictionary()460 cd.ConceptsMap["concept"] = &gauge.Concept{ConceptStep: &gauge.Step{LineText: "concept", Value: "concept", IsConcept: true, ConceptSteps: []*gauge.Step{&gauge.Step{LineText: "concept", Value: "concept", IsConcept: false}}}, FileName: "filename.cpt"}461 res := ValidateConcepts(cd)462 c.Assert(len(res.ParseErrors), Not(Equals), 0)463 c.Assert(containsAny(res.ParseErrors, "Circular reference found"), Equals, true)464}465func (s *MySuite) TestConceptHavingDynamicParameters(c *C) {466 conceptText := newSpecBuilder().467 specHeading("create user <user:id> <user:name> and <file>").468 step("a step <user:id>").String()469 step, _ := new(ConceptParser).Parse(conceptText, "")470 c.Assert(step[0].LineText, Equals, "create user <user:id> <user:name> and <file>")471 c.Assert(step[0].Args[0].ArgType, Equals, gauge.Dynamic)472 c.Assert(step[0].Args[1].ArgType, Equals, gauge.Dynamic)473 c.Assert(step[0].Args[2].ArgType, Equals, gauge.Dynamic)474}475func (s *MySuite) TestConceptHavingInvalidSpecialParameters(c *C) {476 conceptText := newSpecBuilder().477 specHeading("create user <user:id> <table:name> and <file>").478 step("a step <user:id>").String()479 _, parseRes := new(ConceptParser).Parse(conceptText, "")480 c.Assert(parseRes.ParseErrors[0].Message, Equals, "Dynamic parameter <table:name> could not be resolved")481}482func (s *MySuite) TestConceptHavingStaticParameters(c *C) {483 conceptText := newSpecBuilder().484 specHeading("create user <user:id> \"abc\" and <file>").485 step("a step <user:id>").String()486 _, parseRes := new(ConceptParser).Parse(conceptText, "")487 c.Assert(parseRes.ParseErrors[0].Message, Equals, "Concept heading can have only Dynamic Parameters")488}489func (s *MySuite) TestConceptFileHavingScenarioHeadingGivesParseError(c *C) {490 conceptText := newSpecBuilder().491 specHeading("create user").492 step("a step").493 scenarioHeading("Scenario Heading").494 step("a step1").495 String()496 scenarioHeading := newSpecBuilder().497 scenarioHeading("Scenario Heading").498 String()499 _, res := new(ConceptParser).Parse(conceptText, "")500 c.Assert(len(res.ParseErrors), Not(Equals), 0)501 c.Assert(res.ParseErrors[0].Message, Equals, "Scenario Heading is not allowed in concept file")502 c.Assert(res.ParseErrors[0].LineText, Equals, strings.TrimSpace(scenarioHeading))503}504func (s *MySuite) TestConceptFileHavingStaticParamsInHeadingShouldGiveParseError(c *C) {505 conceptText := newSpecBuilder().506 specHeading("Concept Heading37a").507 step("a step").508 specHeading("testinghjk \"sdf\"").509 step("a step1").510 String()511 _, res := new(ConceptParser).Parse(conceptText, "")512 c.Assert(len(res.ParseErrors), Not(Equals), 0)513 c.Assert(res.ParseErrors[0].Message, Equals, "Concept heading can have only Dynamic Parameters")514 c.Assert(res.ParseErrors[0].LineText, Equals, "testinghjk \"sdf\"")515}516func (s *MySuite) TestConceptFileHavingTableAfterConceptHeadingShouldGiveParseError(c *C) {517 conceptText := newSpecBuilder().518 specHeading("Concept Heading37a").519 step("a step").520 specHeading("testinghjk ").521 text("|sdfsdf|").522 text("|----|").523 text("|wer|").524 step("a step1").525 String()526 _, res := new(ConceptParser).Parse(conceptText, "")527 c.Assert(len(res.ParseErrors), Not(Equals), 0)528 c.Assert(res.ParseErrors[0].Message, Equals, "Table doesn't belong to any step")529 c.Assert(res.ParseErrors[0].LineText, Equals, "|sdfsdf|")530}531func (s *MySuite) TestMultipleConceptsInAFileHavingErrorsShouldBeConsolidated(c *C) {532 conceptText := newSpecBuilder().533 specHeading("1<werwer>").534 step("self <werwe1r>").535 specHeading("2 <werwer> two").536 step("self <werwer>").537 String()538 _, res := new(ConceptParser).Parse(conceptText, "")539 c.Assert(len(res.ParseErrors), Not(Equals), 0)540 c.Assert(res.ParseErrors[0].Message, Equals, "Dynamic parameter <werwe1r> could not be resolved")541 c.Assert(res.ParseErrors[0].LineText, Equals, "self <werwe1r>")542}543func (s *MySuite) TestConceptFileHavingItemsWithDuplicateTableHeaders(c *C) {544 conceptDictionary := gauge.NewConceptDictionary()545 path, _ := filepath.Abs(filepath.Join("testdata", "tabular_concept1.cpt"))546 AddConcepts([]string{path}, conceptDictionary)547 concept := conceptDictionary.Search("my concept {}")548 concept1 := conceptDictionary.Search("my {}")549 c.Assert(concept, Not(Equals), nil)550 c.Assert(concept1, Not(Equals), nil)551}552func (s *MySuite) TestConceptParserShouldNotAddTableAsArgIfCommentsArePresentBetweenStepAndTable(c *C) {553 conceptText := newSpecBuilder().554 specHeading("create user").555 step("a step").556 text("").557 text("adasdasd\n\n").558 text("|sdfsdf|").559 text("|----|").560 text("|wer|")....

Full Screen

Full Screen

resolver_test.go

Source:resolver_test.go Github

copy

Full Screen

...73 step("create user <id> <name> and <phone>").74 String()75 conceptDictionary := gauge.NewConceptDictionary()76 path, _ := filepath.Abs(filepath.Join("testdata", "dynamic_param_concept.cpt"))77 AddConcepts([]string{path}, conceptDictionary)78 spec, _, _ := parser.Parse(specText, conceptDictionary, "")79 concept := spec.Scenarios[0].Steps[0]80 dataTableLookup := new(gauge.ArgLookup)81 dataTableLookup.ReadDataTableRow(&spec.DataTable.Table, 0)82 err := PopulateConceptDynamicParams(concept, dataTableLookup)83 c.Assert(err, IsNil)84 useridArg, _ := concept.GetArg("user-id")85 c.Assert(useridArg.Value, Equals, "123")86 usernameArg, _ := concept.GetArg("user-name")87 c.Assert(usernameArg.Value, Equals, "foo")88 userphoneArg, _ := concept.GetArg("user-phone")89 c.Assert(userphoneArg.Value, Equals, "888")90}91func (s *MySuite) TestPopulatingNestedConceptLookup(c *C) {92 parser := new(SpecParser)93 specText := newSpecBuilder().specHeading("A spec heading").94 tableHeader("id", "name", "phone").95 tableHeader("123", "prateek", "8800").96 scenarioHeading("First scenario").97 step("create user <id> <name> and <phone>").98 step("create user \"456\" \"foo\" and \"9900\"").99 String()100 conceptDictionary := gauge.NewConceptDictionary()101 path, _ := filepath.Abs(filepath.Join("testdata", "dynamic_param_concept.cpt"))102 AddConcepts([]string{path}, conceptDictionary)103 spec, _, _ := parser.Parse(specText, conceptDictionary, "")104 concept1 := spec.Scenarios[0].Steps[0]105 dataTableLookup := new(gauge.ArgLookup)106 dataTableLookup.ReadDataTableRow(&spec.DataTable.Table, 0)107 err := PopulateConceptDynamicParams(concept1, dataTableLookup)108 c.Assert(err, IsNil)109 useridArg1, _ := concept1.GetArg("user-id")110 c.Assert(useridArg1.Value, Equals, "123")111 usernameArg1, _ := concept1.GetArg("user-name")112 c.Assert(usernameArg1.Value, Equals, "prateek")113 userphoneArg1, _ := concept1.GetArg("user-phone")114 c.Assert(userphoneArg1.Value, Equals, "8800")115 nestedConcept := concept1.ConceptSteps[0]116 useridArgN1, _ := nestedConcept.GetArg("userid")117 c.Assert(useridArgN1.Value, Equals, "123")118 usernameArgN1, _ := nestedConcept.GetArg("username")119 c.Assert(usernameArgN1.Value, Equals, "prateek")120 concept2 := spec.Scenarios[0].Steps[1]121 useridArg2, _ := concept2.GetArg("user-id")122 c.Assert(useridArg2.Value, Equals, "456")123 usernameArg2, _ := concept2.GetArg("user-name")124 c.Assert(usernameArg2.Value, Equals, "foo")125 userphoneArg2, _ := concept2.GetArg("user-phone")126 c.Assert(userphoneArg2.Value, Equals, "9900")127 nestedConcept2 := concept2.ConceptSteps[0]128 useridArgN2, _ := nestedConcept2.GetArg("userid")129 c.Assert(useridArgN2.Value, Equals, "456")130 usernameArgN2, _ := nestedConcept2.GetArg("username")131 c.Assert(usernameArgN2.Value, Equals, "foo")132}133func (s *MySuite) TestPopulatingNestedConceptsWithStaticParametersLookup(c *C) {134 parser := new(SpecParser)135 specText := newSpecBuilder().specHeading("A spec heading").136 scenarioHeading("First scenario").137 step("create user \"456\" \"foo\" and \"123456\"").138 String()139 conceptDictionary := gauge.NewConceptDictionary()140 path, _ := filepath.Abs(filepath.Join("testdata", "static_param_concept.cpt"))141 AddConcepts([]string{path}, conceptDictionary)142 spec, _, _ := parser.Parse(specText, conceptDictionary, "")143 concept1 := spec.Scenarios[0].Steps[0]144 dataTableLookup := new(gauge.ArgLookup)145 dataTableLookup.ReadDataTableRow(&spec.DataTable.Table, 0)146 err := PopulateConceptDynamicParams(concept1, dataTableLookup)147 c.Assert(err, IsNil)148 useridArg1, _ := concept1.GetArg("user-id")149 c.Assert(useridArg1.Value, Equals, "456")150 usernameArg1, _ := concept1.GetArg("user-name")151 c.Assert(usernameArg1.Value, Equals, "foo")152 userphoneArg1, _ := concept1.GetArg("user-phone")153 c.Assert(userphoneArg1.Value, Equals, "123456")154 nestedConcept := concept1.ConceptSteps[0]155 useridArgN, _ := nestedConcept.GetArg("userid")156 c.Assert(useridArgN.Value, Equals, "456")157 usernameArgN, _ := nestedConcept.GetArg("username")158 c.Assert(usernameArgN.Value, Equals, "static-value")159}160func (s *MySuite) TestPopulatingConceptsWithDynamicParametersInTable(c *C) {161 parser := new(SpecParser)162 specText := newSpecBuilder().specHeading("A spec heading").163 tableHeader("property").164 tableRow("something").165 scenarioHeading("First scenario").166 step("create user \"someone\" with ").167 tableHeader("name").168 tableRow("<property>").169 String()170 conceptDictionary := gauge.NewConceptDictionary()171 path, _ := filepath.Abs(filepath.Join("testdata", "table_param_concept.cpt"))172 AddConcepts([]string{path}, conceptDictionary)173 spec, _, _ := parser.Parse(specText, conceptDictionary, "")174 concept1 := spec.Scenarios[0].Steps[0]175 dataTableLookup := new(gauge.ArgLookup)176 dataTableLookup.ReadDataTableRow(&spec.DataTable.Table, 0)177 err := PopulateConceptDynamicParams(concept1, dataTableLookup)178 c.Assert(err, IsNil)179 tableArg,err := concept1.Lookup.GetArg("addresses")180 c.Assert(err, IsNil)181 v, err := tableArg.Table.Get("name")182 c.Assert(err, IsNil)183 c.Assert(v[0].CellType, Equals, gauge.Static)184 c.Assert(v[0].Value, Equals, "something")185}186func (s *MySuite) TestEachConceptUsageIsUpdatedWithRespectiveParams(c *C) {187 parser := new(SpecParser)188 specText := newSpecBuilder().specHeading("A spec heading").189 scenarioHeading("First scenario").190 step("create user \"sdf\" \"name\" and \"1234\"").191 String()192 conceptDictionary := gauge.NewConceptDictionary()193 path, _ := filepath.Abs(filepath.Join("testdata", "static_param_concept.cpt"))194 AddConcepts([]string{path}, conceptDictionary)195 spec, _, _ := parser.Parse(specText, conceptDictionary, "")196 concept1 := spec.Scenarios[0].Steps[0]197 nestedConcept := concept1.ConceptSteps[0]198 nestedConcept1 := concept1.ConceptSteps[1]199 usernameArg, _ := nestedConcept.GetArg("username")200 c.Assert(usernameArg.Value, Equals, "static-value")201 usernameArg1, _ := nestedConcept1.GetArg("username")202 c.Assert(usernameArg1.Value, Equals, "static-value1")203 useridArg, _ := nestedConcept.GetArg("userid")204 c.Assert(useridArg.Value, Equals, "sdf")205 useridArg1, _ := nestedConcept1.GetArg("userid")206 c.Assert(useridArg1.Value, Equals, "sdf")207}208func (s *MySuite) TestGetResolveParameterFromTable(c *C) {...

Full Screen

Full Screen

AddConcepts

Using AI Code Generation

copy

Full Screen

1import "fmt"2import "github.com/rahulravindran/parse"3func main() {4 fmt.Println("Hello World")5 parser.AddConcepts("Go", "Golang", "GoLang", "GOLANG")6 fmt.Println(parser.Parse("Go is a programming language"))7}8import "fmt"9import "github.com/rahulravindran/parse"10func main() {11 fmt.Println("Hello World")12 parser.AddConcepts("Go", "Golang", "GoLang", "GOLANG")13 fmt.Println(parser.Parse("Golang is a programming language"))14}15import "fmt"16import "github.com/rahulravindran/parse"17func main() {18 fmt.Println("Hello World")19 parser.AddConcepts("Go", "Golang", "GoLang", "GOLANG")20 fmt.Println(parser.Parse("GOLANG is a programming language"))21}22import "fmt"23import "github.com/rahulravindran/parse"24func main() {25 fmt.Println("Hello World")26 parser.AddConcepts("Go", "Golang", "GoLang", "GOLANG")27 fmt.Println(parser.Parse("GoLang is a programming language"))28}29import "fmt"30import "github.com/rahulravindran/parse"31func main() {32 fmt.Println("Hello World")33 parser.AddConcepts("Go", "Golang", "GoLang", "GOLANG")34 fmt.Println(parser.Parse("GoLang is a programming language"))35}36import "fmt"37import "github.com/rahulravindran/parse"38func main() {39 fmt.Println("Hello World")

Full Screen

Full Screen

Automation Testing Tutorials

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.

LambdaTest Learning Hubs:

YouTube

You could also refer to video tutorials over LambdaTest YouTube channel to get step by step demonstration from industry experts.

Run Gauge automation tests on LambdaTest cloud grid

Perform automation testing on 3000+ real desktop and mobile devices online.

Most used method in

Try LambdaTest Now !!

Get 100 minutes of automation test minutes FREE!!

Next-Gen App & Browser Testing Cloud

Was this article helpful?

Helpful

NotHelpful