How to use rephraseInSpecsAndConcepts method of refactor Package

Best Gauge code snippet using refactor.rephraseInSpecsAndConcepts

refactor_test.go

Source:refactor_test.go Github

copy

Full Screen

...30 }31 spec, _, _ := new(parser.SpecParser).CreateSpecification(tokens, gauge.NewConceptDictionary(), "")32 agent, errs := getRefactorAgent(oldStep, newStep, nil)33 specs := append(make([]*gauge.Specification, 0), spec)34 agent.rephraseInSpecsAndConcepts(&specs, gauge.NewConceptDictionary())35 c.Assert(len(errs), Equals, 0)36 c.Assert(len(specs[0].Scenarios[0].Steps), Equals, 1)37 c.Assert(specs[0].Scenarios[0].Steps[0].Value, Equals, newStep)38}39func (s *MySuite) TestRefactoringOfStepsWithNoArgsAndWithMoreThanOneScenario(c *C) {40 oldStep := "first step"41 newStep := "second step"42 unchanged := "unchanged"43 tokens := []*parser.Token{44 &parser.Token{Kind: gauge.SpecKind, Value: "Spec Heading", LineNo: 1},45 &parser.Token{Kind: gauge.ScenarioKind, Value: "Scenario Heading", LineNo: 2},46 &parser.Token{Kind: gauge.StepKind, Value: oldStep, LineNo: 3},47 &parser.Token{Kind: gauge.StepKind, Value: oldStep, LineNo: 5},48 &parser.Token{Kind: gauge.ScenarioKind, Value: "Scenario Heading 1", LineNo: 20},49 &parser.Token{Kind: gauge.StepKind, Value: unchanged, LineNo: 30},50 &parser.Token{Kind: gauge.StepKind, Value: oldStep, LineNo: 50},51 }52 spec, _, _ := new(parser.SpecParser).CreateSpecification(tokens, gauge.NewConceptDictionary(), "")53 agent, errs := getRefactorAgent(oldStep, newStep, nil)54 specs := append(make([]*gauge.Specification, 0), spec)55 agent.rephraseInSpecsAndConcepts(&specs, gauge.NewConceptDictionary())56 c.Assert(len(errs), Equals, 0)57 c.Assert(len(specs[0].Scenarios), Equals, 2)58 c.Assert(len(specs[0].Scenarios[0].Steps), Equals, 2)59 c.Assert(specs[0].Scenarios[0].Steps[0].Value, Equals, newStep)60 c.Assert(specs[0].Scenarios[0].Steps[1].Value, Equals, newStep)61 c.Assert(len(specs[0].Scenarios[1].Steps), Equals, 2)62 c.Assert(specs[0].Scenarios[1].Steps[0].Value, Equals, unchanged)63 c.Assert(specs[0].Scenarios[1].Steps[1].Value, Equals, newStep)64}65func (s *MySuite) TestRefactoringOfStepsWithNoArgsAndWithMoreThanOneSpec(c *C) {66 oldStep := " first step"67 newStep := "second step"68 tokens := []*parser.Token{69 &parser.Token{Kind: gauge.SpecKind, Value: "Spec Heading", LineNo: 1},70 &parser.Token{Kind: gauge.ScenarioKind, Value: "Scenario Heading", LineNo: 2},71 &parser.Token{Kind: gauge.StepKind, Value: oldStep, LineNo: 3},72 }73 spec, _, _ := new(parser.SpecParser).CreateSpecification(tokens, gauge.NewConceptDictionary(), "")74 tokens = []*parser.Token{75 &parser.Token{Kind: gauge.SpecKind, Value: "Spec Heading", LineNo: 10},76 &parser.Token{Kind: gauge.ScenarioKind, Value: "Scenario Heading", LineNo: 20},77 &parser.Token{Kind: gauge.StepKind, Value: oldStep, LineNo: 30},78 }79 spec1, _, _ := new(parser.SpecParser).CreateSpecification(tokens, gauge.NewConceptDictionary(), "")80 specs := append(make([]*gauge.Specification, 0), spec)81 specs = append(specs, spec1)82 agent, errs := getRefactorAgent(oldStep, newStep, nil)83 specRefactored, _ := agent.rephraseInSpecsAndConcepts(&specs, gauge.NewConceptDictionary())84 for _, diffs := range specRefactored {85 c.Assert(1, Equals, len(diffs))86 }87 c.Assert(len(errs), Equals, 0)88 c.Assert(len(specs[0].Scenarios[0].Steps), Equals, 1)89 c.Assert(specs[0].Scenarios[0].Steps[0].Value, Equals, newStep)90 c.Assert(len(specs[1].Scenarios[0].Steps), Equals, 1)91 c.Assert(specs[1].Scenarios[0].Steps[0].Value, Equals, newStep)92}93func (s *MySuite) TestRefactoringOfStepsWithNoArgsInConceptFiles(c *C) {94 oldStep := "first step"95 newStep := "second step"96 unchanged := "unchanged"97 tokens := []*parser.Token{98 &parser.Token{Kind: gauge.SpecKind, Value: "Spec Heading", LineNo: 1},99 &parser.Token{Kind: gauge.ScenarioKind, Value: "Scenario Heading 1", LineNo: 20},100 }101 spec, _, _ := new(parser.SpecParser).CreateSpecification(tokens, gauge.NewConceptDictionary(), "")102 agent, _ := getRefactorAgent(oldStep, newStep, nil)103 specs := append(make([]*gauge.Specification, 0), spec)104 dictionary := gauge.NewConceptDictionary()105 step1 := &gauge.Step{Value: oldStep + "sdsf", IsConcept: true}106 step2 := &gauge.Step{Value: unchanged, IsConcept: true, Items: []gauge.Item{&gauge.Step{Value: oldStep, IsConcept: false}, &gauge.Step{Value: oldStep + "T", IsConcept: false}}}107 dictionary.ConceptsMap[step1.Value] = &gauge.Concept{ConceptStep: step1, FileName: "file.cpt"}108 dictionary.ConceptsMap[step2.Value] = &gauge.Concept{ConceptStep: step2, FileName: "file.cpt"}109 agent.rephraseInSpecsAndConcepts(&specs, dictionary)110 c.Assert(dictionary.ConceptsMap[unchanged].ConceptStep.Items[0].(*gauge.Step).Value, Equals, newStep)111 c.Assert(dictionary.ConceptsMap[unchanged].ConceptStep.Items[1].(*gauge.Step).Value, Equals, oldStep+"T")112}113func (s *MySuite) TestRefactoringGivesOnlySpecsThatAreRefactored(c *C) {114 oldStep := " first step"115 newStep := "second step"116 tokens := []*parser.Token{117 &parser.Token{Kind: gauge.SpecKind, Value: "Spec Heading", LineNo: 1},118 &parser.Token{Kind: gauge.ScenarioKind, Value: "Scenario Heading", LineNo: 2},119 &parser.Token{Kind: gauge.StepKind, Value: oldStep, LineNo: 3},120 }121 spec, _, _ := new(parser.SpecParser).CreateSpecification(tokens, gauge.NewConceptDictionary(), "")122 tokens = []*parser.Token{123 &parser.Token{Kind: gauge.SpecKind, Value: "Spec Heading", LineNo: 10},124 &parser.Token{Kind: gauge.ScenarioKind, Value: "Scenario Heading", LineNo: 20},125 &parser.Token{Kind: gauge.StepKind, Value: newStep, LineNo: 30},126 }127 spec1, _, _ := new(parser.SpecParser).CreateSpecification(tokens, gauge.NewConceptDictionary(), "")128 specs := append(make([]*gauge.Specification, 0), spec)129 specs = append(specs, spec1)130 agent, _ := getRefactorAgent(oldStep, newStep, nil)131 specRefactored, _ := agent.rephraseInSpecsAndConcepts(&specs, gauge.NewConceptDictionary())132 c.Assert(1, Equals, len(specRefactored[specs[0]]))133 c.Assert(0, Equals, len(specRefactored[specs[1]]))134 c.Assert(specRefactored[specs[0]][0].OldStep.Value, Equals, " first step")135 c.Assert(specRefactored[specs[0]][0].NewStep.Value, Equals, "second step")136}137func (s *MySuite) TestRefactoringGivesOnlyThoseConceptFilesWhichAreRefactored(c *C) {138 oldStep := "first step"139 newStep := "second step"140 unchanged := "unchanged"141 tokens := []*parser.Token{142 &parser.Token{Kind: gauge.SpecKind, Value: "Spec Heading", LineNo: 1},143 &parser.Token{Kind: gauge.ScenarioKind, Value: "Scenario Heading 1", LineNo: 20},144 }145 spec, _, _ := new(parser.SpecParser).CreateSpecification(tokens, gauge.NewConceptDictionary(), "")146 agent, _ := getRefactorAgent(oldStep, newStep, nil)147 specs := append(make([]*gauge.Specification, 0), spec)148 dictionary := gauge.NewConceptDictionary()149 step1 := &gauge.Step{Value: oldStep + "sdsf", IsConcept: true}150 step2 := &gauge.Step{Value: unchanged, IsConcept: true, Items: []gauge.Item{&gauge.Step{Value: newStep, IsConcept: false}, &gauge.Step{Value: oldStep + "T", IsConcept: false}}}151 step3 := &gauge.Step{Value: "Concept value", IsConcept: true, Items: []gauge.Item{&gauge.Step{Value: oldStep, IsConcept: false}, &gauge.Step{Value: oldStep + "T", IsConcept: false}}}152 fileName := "file.cpt"153 dictionary.ConceptsMap[step1.Value] = &gauge.Concept{ConceptStep: step1, FileName: fileName}154 dictionary.ConceptsMap[step2.Value] = &gauge.Concept{ConceptStep: step2, FileName: fileName}155 dictionary.ConceptsMap[step3.Value] = &gauge.Concept{ConceptStep: step3, FileName: "e" + fileName}156 _, filesRefactored := agent.rephraseInSpecsAndConcepts(&specs, dictionary)157 c.Assert(len(filesRefactored[fileName]), Equals, 0)158 c.Assert(len(filesRefactored["e"+fileName]), Equals, 1)159}160func (s *MySuite) TestRenamingWhenNumberOfArgumentsAreSame(c *C) {161 oldStep := "first step {static} and {static}"162 oldStep1 := "first step <a> and <b>"163 newStep := "second step <a> and <b>"164 tokens := []*parser.Token{165 &parser.Token{Kind: gauge.SpecKind, Value: "Spec Heading", LineNo: 1},166 &parser.Token{Kind: gauge.ScenarioKind, Value: "Scenario Heading 1", LineNo: 2},167 &parser.Token{Kind: gauge.StepKind, Value: oldStep, LineNo: 3, Args: []string{"name", "address"}},168 }169 spec, _, _ := new(parser.SpecParser).CreateSpecification(tokens, gauge.NewConceptDictionary(), "")170 agent, _ := getRefactorAgent(oldStep1, newStep, nil)171 specs := append(make([]*gauge.Specification, 0), spec)172 dictionary := gauge.NewConceptDictionary()173 agent.rephraseInSpecsAndConcepts(&specs, dictionary)174 c.Assert(specs[0].Scenarios[0].Steps[0].Value, Equals, "second step {} and {}")175 c.Assert(specs[0].Scenarios[0].Steps[0].Args[0].Value, Equals, "name")176 c.Assert(specs[0].Scenarios[0].Steps[0].Args[1].Value, Equals, "address")177}178func (s *MySuite) TestRenamingWhenArgumentsOrderIsChanged(c *C) {179 oldStep := "first step {static} and {static} and {static} and {static}"180 oldStep1 := "first step <a> and <b> and <c> and <d>"181 newStep := "second step <d> and <b> and <c> and <a>"182 tokens := []*parser.Token{183 &parser.Token{Kind: gauge.SpecKind, Value: "Spec Heading", LineNo: 1},184 &parser.Token{Kind: gauge.ScenarioKind, Value: "Scenario Heading 1", LineNo: 2},185 &parser.Token{Kind: gauge.StepKind, Value: oldStep, LineNo: 3, Args: []string{"name", "address", "number", "id"}},186 }187 spec, _, _ := new(parser.SpecParser).CreateSpecification(tokens, gauge.NewConceptDictionary(), "")188 agent, _ := getRefactorAgent(oldStep1, newStep, nil)189 specs := append(make([]*gauge.Specification, 0), spec)190 dictionary := gauge.NewConceptDictionary()191 agent.rephraseInSpecsAndConcepts(&specs, dictionary)192 c.Assert(specs[0].Scenarios[0].Steps[0].Value, Equals, "second step {} and {} and {} and {}")193 c.Assert(specs[0].Scenarios[0].Steps[0].Args[0].Value, Equals, "id")194 c.Assert(specs[0].Scenarios[0].Steps[0].Args[1].Value, Equals, "address")195 c.Assert(specs[0].Scenarios[0].Steps[0].Args[2].Value, Equals, "number")196 c.Assert(specs[0].Scenarios[0].Steps[0].Args[3].Value, Equals, "name")197}198func (s *MySuite) TestCreateOrderGivesMapOfOldArgsAndNewArgs(c *C) {199 step1 := &gauge.Step{Args: []*gauge.StepArg{&gauge.StepArg{Name: "a"}, &gauge.StepArg{Name: "b"}, &gauge.StepArg{Name: "c"}, &gauge.StepArg{Name: "d"}}}200 step2 := &gauge.Step{Args: []*gauge.StepArg{&gauge.StepArg{Name: "d"}, &gauge.StepArg{Name: "b"}, &gauge.StepArg{Name: "c"}, &gauge.StepArg{Name: "a"}}}201 agent := &rephraseRefactorer{step1, step2, false, nil}202 orderMap := agent.createOrderOfArgs()203 c.Assert(orderMap[0], Equals, 3)204 c.Assert(orderMap[1], Equals, 1)205 c.Assert(orderMap[2], Equals, 2)206}207func (s *MySuite) TestCreateOrderGivesMapOfOldArgsAndNewWhenArgsAreAdded(c *C) {208 step1 := &gauge.Step{Args: []*gauge.StepArg{&gauge.StepArg{Name: "a"}, &gauge.StepArg{Name: "b"}, &gauge.StepArg{Name: "c"}, &gauge.StepArg{Name: "d"}}}209 step2 := &gauge.Step{Args: []*gauge.StepArg{&gauge.StepArg{Name: "d"}, &gauge.StepArg{Name: "e"}, &gauge.StepArg{Name: "b"}, &gauge.StepArg{Name: "c"}, &gauge.StepArg{Name: "a"}}}210 agent := &rephraseRefactorer{step1, step2, false, nil}211 orderMap := agent.createOrderOfArgs()212 c.Assert(orderMap[0], Equals, 3)213 c.Assert(orderMap[1], Equals, -1)214 c.Assert(orderMap[2], Equals, 1)215 c.Assert(orderMap[3], Equals, 2)216 c.Assert(orderMap[4], Equals, 0)217}218func (s *MySuite) TestCreateOrderGivesMapOfOldArgsAndNewWhenArgsAreRemoved(c *C) {219 step1 := &gauge.Step{Args: []*gauge.StepArg{&gauge.StepArg{Name: "a"}, &gauge.StepArg{Name: "b"}, &gauge.StepArg{Name: "c"}, &gauge.StepArg{Name: "d"}}}220 step2 := &gauge.Step{Args: []*gauge.StepArg{&gauge.StepArg{Name: "d"}, &gauge.StepArg{Name: "b"}, &gauge.StepArg{Name: "c"}}}221 agent := &rephraseRefactorer{step1, step2, false, nil}222 orderMap := agent.createOrderOfArgs()223 c.Assert(orderMap[0], Equals, 3)224 c.Assert(orderMap[1], Equals, 1)225 c.Assert(orderMap[2], Equals, 2)226}227func (s *MySuite) TestCreationOfOrderMapForStep(c *C) {228 agent, _ := getRefactorAgent("Say <greeting> to <name>", "Say <greeting> to <name> \"DD\"", nil)229 orderMap := agent.createOrderOfArgs()230 c.Assert(orderMap[0], Equals, 0)231 c.Assert(orderMap[1], Equals, 1)232 c.Assert(orderMap[2], Equals, -1)233}234func (s *MySuite) TestRenamingWhenArgumentsIsAddedAtLast(c *C) {235 oldStep := "first step {static} and {static} and {static}"236 oldStep1 := "first step <a> and <b> and <c>"237 newStep := "second step <a> and <b> and <c> and <d>"238 tokens := []*parser.Token{239 &parser.Token{Kind: gauge.SpecKind, Value: "Spec Heading", LineNo: 1},240 &parser.Token{Kind: gauge.ScenarioKind, Value: "Scenario Heading 1", LineNo: 2},241 &parser.Token{Kind: gauge.StepKind, Value: oldStep, LineNo: 3, Args: []string{"name", "address", "number"}},242 }243 spec, _, _ := new(parser.SpecParser).CreateSpecification(tokens, gauge.NewConceptDictionary(), "")244 agent, _ := getRefactorAgent(oldStep1, newStep, nil)245 specs := append(make([]*gauge.Specification, 0), spec)246 dictionary := gauge.NewConceptDictionary()247 agent.rephraseInSpecsAndConcepts(&specs, dictionary)248 c.Assert(specs[0].Scenarios[0].Steps[0].Value, Equals, "second step {} and {} and {} and {}")249 c.Assert(specs[0].Scenarios[0].Steps[0].Args[0].Value, Equals, "name")250 c.Assert(specs[0].Scenarios[0].Steps[0].Args[1].Value, Equals, "address")251 c.Assert(specs[0].Scenarios[0].Steps[0].Args[2].Value, Equals, "number")252 c.Assert(specs[0].Scenarios[0].Steps[0].Args[3].Value, Equals, "d")253}254func (s *MySuite) TestRenamingWhenArgumentsIsAddedAtFirst(c *C) {255 oldStep := "first step {static} and {static} and {static}"256 oldStep1 := "first step <a> and <b> and <c>"257 newStep := "second step <d> and <a> and <b> and <c>"258 tokens := []*parser.Token{259 &parser.Token{Kind: gauge.SpecKind, Value: "Spec Heading", LineNo: 1},260 &parser.Token{Kind: gauge.ScenarioKind, Value: "Scenario Heading 1", LineNo: 2},261 &parser.Token{Kind: gauge.StepKind, Value: oldStep, LineNo: 3, Args: []string{"name", "address", "number"}},262 }263 spec, _, _ := new(parser.SpecParser).CreateSpecification(tokens, gauge.NewConceptDictionary(), "")264 agent, _ := getRefactorAgent(oldStep1, newStep, nil)265 specs := append(make([]*gauge.Specification, 0), spec)266 dictionary := gauge.NewConceptDictionary()267 agent.rephraseInSpecsAndConcepts(&specs, dictionary)268 c.Assert(specs[0].Scenarios[0].Steps[0].Value, Equals, "second step {} and {} and {} and {}")269 c.Assert(specs[0].Scenarios[0].Steps[0].Args[0].Value, Equals, "d")270 c.Assert(specs[0].Scenarios[0].Steps[0].Args[1].Value, Equals, "name")271 c.Assert(specs[0].Scenarios[0].Steps[0].Args[2].Value, Equals, "address")272 c.Assert(specs[0].Scenarios[0].Steps[0].Args[3].Value, Equals, "number")273}274func (s *MySuite) TestRenamingWhenArgumentsIsAddedInMiddle(c *C) {275 oldStep := "first step {static} and {static} and {static}"276 oldStep1 := "first step <a> and <b> and <c>"277 newStep := "second step <a> and <d> and <b> and <c>"278 tokens := []*parser.Token{279 &parser.Token{Kind: gauge.SpecKind, Value: "Spec Heading", LineNo: 1},280 &parser.Token{Kind: gauge.ScenarioKind, Value: "Scenario Heading 1", LineNo: 2},281 &parser.Token{Kind: gauge.StepKind, Value: oldStep, LineNo: 3, Args: []string{"name", "address", "number"}},282 }283 spec, _, _ := new(parser.SpecParser).CreateSpecification(tokens, gauge.NewConceptDictionary(), "")284 agent, _ := getRefactorAgent(oldStep1, newStep, nil)285 specs := append(make([]*gauge.Specification, 0), spec)286 dictionary := gauge.NewConceptDictionary()287 agent.rephraseInSpecsAndConcepts(&specs, dictionary)288 c.Assert(specs[0].Scenarios[0].Steps[0].Value, Equals, "second step {} and {} and {} and {}")289 c.Assert(specs[0].Scenarios[0].Steps[0].Args[0].Value, Equals, "name")290 c.Assert(specs[0].Scenarios[0].Steps[0].Args[1].Value, Equals, "d")291 c.Assert(specs[0].Scenarios[0].Steps[0].Args[2].Value, Equals, "address")292 c.Assert(specs[0].Scenarios[0].Steps[0].Args[3].Value, Equals, "number")293}294func (s *MySuite) TestRenamingWhenArgumentsIsRemovedFromLast(c *C) {295 oldStep := "first step {static} and {static} and {static} and {static}"296 oldStep1 := "first step <a> and <b> and <c> and <d>"297 newStep := "second step <a> and <b> and <c>"298 tokens := []*parser.Token{299 &parser.Token{Kind: gauge.SpecKind, Value: "Spec Heading", LineNo: 1},300 &parser.Token{Kind: gauge.ScenarioKind, Value: "Scenario Heading 1", LineNo: 2},301 &parser.Token{Kind: gauge.StepKind, Value: oldStep, LineNo: 3, Args: []string{"name", "address", "number", "id"}},302 }303 spec, _, _ := new(parser.SpecParser).CreateSpecification(tokens, gauge.NewConceptDictionary(), "")304 agent, _ := getRefactorAgent(oldStep1, newStep, nil)305 specs := append(make([]*gauge.Specification, 0), spec)306 dictionary := gauge.NewConceptDictionary()307 agent.rephraseInSpecsAndConcepts(&specs, dictionary)308 c.Assert(specs[0].Scenarios[0].Steps[0].Value, Equals, "second step {} and {} and {}")309 c.Assert(specs[0].Scenarios[0].Steps[0].Args[0].Value, Equals, "name")310 c.Assert(specs[0].Scenarios[0].Steps[0].Args[1].Value, Equals, "address")311 c.Assert(specs[0].Scenarios[0].Steps[0].Args[2].Value, Equals, "number")312}313func (s *MySuite) TestRenamingWhenArgumentsIsRemovedFromBegining(c *C) {314 oldStep := "first step {static} and {static} and {static} and {static}"315 oldStep1 := "first step <a> and <b> and <c> and <d>"316 newStep := "second step <b> and <c> and <d>"317 tokens := []*parser.Token{318 &parser.Token{Kind: gauge.SpecKind, Value: "Spec Heading", LineNo: 1},319 &parser.Token{Kind: gauge.ScenarioKind, Value: "Scenario Heading 1", LineNo: 2},320 &parser.Token{Kind: gauge.StepKind, Value: oldStep, LineNo: 3, Args: []string{"name", "address", "number", "id"}},321 }322 spec, _, _ := new(parser.SpecParser).CreateSpecification(tokens, gauge.NewConceptDictionary(), "")323 agent, _ := getRefactorAgent(oldStep1, newStep, nil)324 specs := append(make([]*gauge.Specification, 0), spec)325 dictionary := gauge.NewConceptDictionary()326 agent.rephraseInSpecsAndConcepts(&specs, dictionary)327 c.Assert(specs[0].Scenarios[0].Steps[0].Value, Equals, "second step {} and {} and {}")328 c.Assert(specs[0].Scenarios[0].Steps[0].Args[0].Value, Equals, "address")329 c.Assert(specs[0].Scenarios[0].Steps[0].Args[1].Value, Equals, "number")330 c.Assert(specs[0].Scenarios[0].Steps[0].Args[2].Value, Equals, "id")331}332func (s *MySuite) TestRenamingWhenArgumentsIsRemovedFromMiddle(c *C) {333 oldStep := "first step {static} and {static} and {static} and {static}"334 oldStep1 := "first step <a> and <b> and <c> and <d>"335 newStep := "second step <a> and <b> and <d>"336 tokens := []*parser.Token{337 &parser.Token{Kind: gauge.SpecKind, Value: "Spec Heading", LineNo: 1},338 &parser.Token{Kind: gauge.ScenarioKind, Value: "Scenario Heading 1", LineNo: 2},339 &parser.Token{Kind: gauge.StepKind, Value: oldStep, LineNo: 3, Args: []string{"name", "address", "number", "id"}},340 }341 spec, _, _ := new(parser.SpecParser).CreateSpecification(tokens, gauge.NewConceptDictionary(), "")342 agent, _ := getRefactorAgent(oldStep1, newStep, nil)343 specs := append(make([]*gauge.Specification, 0), spec)344 dictionary := gauge.NewConceptDictionary()345 agent.rephraseInSpecsAndConcepts(&specs, dictionary)346 c.Assert(specs[0].Scenarios[0].Steps[0].Value, Equals, "second step {} and {} and {}")347 c.Assert(specs[0].Scenarios[0].Steps[0].Args[0].Value, Equals, "name")348 c.Assert(specs[0].Scenarios[0].Steps[0].Args[1].Value, Equals, "address")349 c.Assert(specs[0].Scenarios[0].Steps[0].Args[2].Value, Equals, "id")350}351func (s *MySuite) TestGenerateNewStepNameGivesLineTextWithActualParamNames(c *C) {352 args := []string{"name", "address", "id"}353 newStep := "second step <a> and <b> and <d>"354 orderMap := make(map[int]int)355 orderMap[0] = 1356 orderMap[1] = 2357 orderMap[2] = 0358 agent, _ := getRefactorAgent(newStep, newStep, nil)359 linetext := agent.generateNewStepName(args, orderMap)360 c.Assert(linetext, Equals, "second step <address> and <id> and <name>")361}362func (s *MySuite) TestGenerateNewStepNameWhenParametersAreAdded(c *C) {363 args := []string{"name", "address"}364 newStep := "changed step <a> and <b> and \"id\""365 orderMap := make(map[int]int)366 orderMap[0] = 1367 orderMap[1] = 0368 orderMap[2] = -1369 agent, _ := getRefactorAgent(newStep, newStep, nil)370 linetext := agent.generateNewStepName(args, orderMap)371 c.Assert(linetext, Equals, "changed step <address> and <name> and \"id\"")372}373func (s *MySuite) TestGenerateNewStepNameWhenParametersAreRemoved(c *C) {374 args := []string{"name", "address", "desc"}375 newStep := "changed step <b> and \"id\""376 orderMap := make(map[int]int)377 orderMap[0] = 1378 orderMap[1] = -1379 orderMap[2] = -1380 agent, _ := getRefactorAgent(newStep, newStep, nil)381 linetext := agent.generateNewStepName(args, orderMap)382 c.Assert(linetext, Equals, "changed step <address> and \"id\"")383}384func (s *MySuite) TestGenerateNewStepNameWhenParametersAreUnchanged(c *C) {385 args := []string{"a"}386 newStep := "make comment <a>"387 agent, _ := getRefactorAgent("Comment <a>", newStep, nil)388 linetext := agent.generateNewStepName(args, agent.createOrderOfArgs())389 c.Assert(linetext, Equals, "make comment <a>")390}391func (s *MySuite) TestRefactoringInContextStep(c *C) {392 oldStep := "first step {static} and {static} and {static} and {static}"393 oldStep1 := "first step <a> and <b> and <c> and <d>"394 newStep := "second step <d> and <b> and <c> and <a>"395 tokens := []*parser.Token{396 &parser.Token{Kind: gauge.SpecKind, Value: "Spec Heading", LineNo: 1},397 &parser.Token{Kind: gauge.StepKind, Value: oldStep, LineNo: 3, Args: []string{"name", "address", "number", "id"}},398 &parser.Token{Kind: gauge.ScenarioKind, Value: "Scenario Heading 1", LineNo: 2},399 &parser.Token{Kind: gauge.StepKind, Value: oldStep + " sdf", LineNo: 3, Args: []string{"name", "address", "number", "id"}},400 }401 spec, _, _ := new(parser.SpecParser).CreateSpecification(tokens, gauge.NewConceptDictionary(), "")402 agent, _ := getRefactorAgent(oldStep1, newStep, nil)403 specs := append(make([]*gauge.Specification, 0), spec)404 dictionary := gauge.NewConceptDictionary()405 agent.rephraseInSpecsAndConcepts(&specs, dictionary)406 c.Assert(specs[0].Contexts[0].Value, Equals, "second step {} and {} and {} and {}")407 c.Assert(specs[0].Contexts[0].Args[0].Value, Equals, "id")408 c.Assert(specs[0].Contexts[0].Args[1].Value, Equals, "address")409 c.Assert(specs[0].Contexts[0].Args[2].Value, Equals, "number")410 c.Assert(specs[0].Contexts[0].Args[3].Value, Equals, "name")411}412func (s *MySuite) TestRefactoringInTearDownStep(c *C) {413 oldStep := "first step {static} and {static} and {static} and {static}"414 oldStep1 := "first step <a> and <b> and <c> and <d>"415 newStep := "second step <d> and <b> and <c> and <a>"416 tokens := []*parser.Token{417 &parser.Token{Kind: gauge.SpecKind, Value: "Spec Heading", LineNo: 1},418 &parser.Token{Kind: gauge.StepKind, Value: oldStep + "sdf", LineNo: 3, Args: []string{"name", "address", "number", "id"}},419 &parser.Token{Kind: gauge.ScenarioKind, Value: "Scenario Heading 1", LineNo: 2},420 &parser.Token{Kind: gauge.StepKind, Value: oldStep + " sdf", LineNo: 3, Args: []string{"name", "address", "number", "id"}},421 &parser.Token{Kind: gauge.TearDownKind, Value: "____", LineNo: 3},422 &parser.Token{Kind: gauge.StepKind, Value: oldStep, LineNo: 3, Args: []string{"name", "address", "number", "id"}},423 }424 spec, _, _ := new(parser.SpecParser).CreateSpecification(tokens, gauge.NewConceptDictionary(), "")425 agent, _ := getRefactorAgent(oldStep1, newStep, nil)426 specs := append(make([]*gauge.Specification, 0), spec)427 dictionary := gauge.NewConceptDictionary()428 agent.rephraseInSpecsAndConcepts(&specs, dictionary)429 c.Assert(specs[0].TearDownSteps[0].Value, Equals, "second step {} and {} and {} and {}")430 c.Assert(specs[0].TearDownSteps[0].Args[0].Value, Equals, "id")431 c.Assert(specs[0].TearDownSteps[0].Args[1].Value, Equals, "address")432 c.Assert(specs[0].TearDownSteps[0].Args[2].Value, Equals, "number")433 c.Assert(specs[0].TearDownSteps[0].Args[3].Value, Equals, "name")434}...

Full Screen

Full Screen

rephraseInSpecsAndConcepts

Using AI Code Generation

copy

Full Screen

1import (2func main() {3 wd, _ := os.Getwd()4 specFiles, _ := util.GetSpecFiles(filepath.Join(wd, "specs"))5 spec, _ := parser.ParseSpecFile(specFiles[0])6 refactoredSpec, _ := refactor.RephraseInSpecsAndConcepts(spec, "A user", "A person")7 fmt.Println(refactoredSpec)8}

Full Screen

Full Screen

rephraseInSpecsAndConcepts

Using AI Code Generation

copy

Full Screen

1import (2func main() {3 wd, _ := os.Getwd()4 specFiles, _ := util.GetSpecFiles(filepath.Join(wd, "specs"))5 spec, _ := parser.ParseSpecFile(specFiles[0])6 refactoredSpec, _ := refactor.RephraseInSpecsAndConcepts(spec, "A user", "A person")7 fmt.Println(refactoredSpec)8}

Full Screen

Full Screen

rephraseInSpecsAndConcepts

Using AI Code Generation

copy

Full Screen

1func main() {2 refactor := new(refactor.Refactor)3 refactor.RephraseInSpecsAndConcepts("test.txt", "test1.txt", "test2.txt")4}5func (r *Refactor) RephraseInSpecsAndConcepts(specsPath, conceptsPath, outputPath string) {6 r.RephraseInSpecs(specsPath, outputPath)7 r.RephraseInConcepts(conceptsPath, outputPath)8}9func (r *Refactor) RephraseInSpecs(specsPath, outputPath string) {10 specs, err := r.parseSpecs(specsPath)11 if err != nil {12 fmt.Println(err)13 }14 for _, spec := range specs {15 r.rephraseInSpec(spec)16 }17 r.writeSpecs(specs, outputPath)18}19func (r *Refactor) RephraseInConcepts(conceptsPath, outputPath string) {20 concepts, err := r.parseConcepts(conceptsPath)21 if err != nil {22 fmt.Println(err)23 }24 for _, concept := range concepts {25 r.rephraseInConcept(concept)26 }27 r.writeConcepts(concepts, outputPath)28}29func (r *Refactor) rephraseInSpec(spec *gauge.Specification) {30 for _, item := range spec.Items {31 if step, ok := item.(*gauge.Step); ok {32 step.Value = r.rephrase(step.Value)33 }34 if concept, ok := item.(*gauge.Concept); ok {35 r.rephraseInConcept(concept)36 }37 }38}39func (r *Refactor) rephraseInConcept(concept *gauge.Concept) {40 for _, item := range concept.ConceptStep.ConceptStepItems {41 if step, ok := item.(*gauge.Step); ok {42 step.Value = r.rephrase(step.Value)43 }

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