How to use getRefactorAgent method of refactor Package

Best Gauge code snippet using refactor.getRefactorAgent

refactor_test.go

Source:refactor_test.go Github

copy

Full Screen

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

Full Screen

Full Screen

getRefactorAgent

Using AI Code Generation

copy

Full Screen

1import (2func main() {3 fmt.Println("Hello, playground")4}5import (6func main() {7 fmt.Println("Hello, playground")8}9import (10func main() {11 fmt.Println("Hello, playground")12}13import (14func main() {15 fmt.Println("Hello, playground")16}17import (18func main() {19 fmt.Println("Hello, playground")20}21import (22func main() {23 fmt.Println("Hello, playground")24}25import (26func main() {27 fmt.Println("Hello, playground")28}29import (30func main() {31 fmt.Println("Hello, playground")32}33import (34func main() {35 fmt.Println("Hello, playground")36}37import (38func main() {39 fmt.Println("Hello, playground")40}41import (42func main() {43 fmt.Println("Hello, playground")44}45import (46func main() {47 fmt.Println("Hello, playground")48}49import (

Full Screen

Full Screen

getRefactorAgent

Using AI Code Generation

copy

Full Screen

1import (2func main() {3 agent := refactor.GetRefactorAgent()4 fmt.Println(agent)5}6import (7func main() {8 agent := refactor.GetRefactorAgent()9 fmt.Println(agent)10}

Full Screen

Full Screen

getRefactorAgent

Using AI Code Generation

copy

Full Screen

1import (2func main() {3 fmt.Println(refactor.GetRefactorAgent())4}5func GetRefactorAgent() string {6}

Full Screen

Full Screen

getRefactorAgent

Using AI Code Generation

copy

Full Screen

1import (2func main() {3 agent := refactor.getRefactorAgent()4 fmt.Println("Agent:", agent)5}6import (7func main() {8 agent := refactor.getRefactorAgent()9 fmt.Println("Agent:", agent)10}11import (12func main() {13 agent := refactor.getRefactorAgent()14 fmt.Println("Agent:", agent)15}16import (17func main() {18 agent := refactor.getRefactorAgent()19 fmt.Println("Agent:", agent)20}21import (22func main() {23 agent := refactor.getRefactorAgent()24 fmt.Println("Agent:", agent)25}26import (27func main() {28 agent := refactor.getRefactorAgent()29 fmt.Println("Agent:", agent)30}31import (32func main() {33 agent := refactor.getRefactorAgent()34 fmt.Println("Agent:", agent)35}36import (37func main() {38 agent := refactor.getRefactorAgent()39 fmt.Println("Agent:", agent)40}41import (42func main() {43 agent := refactor.getRefactorAgent()44 fmt.Println("Agent:", agent)45}

Full Screen

Full Screen

getRefactorAgent

Using AI Code Generation

copy

Full Screen

1import (2type Refactor struct {3}4func (r *Refactor) getRefactorAgent() string {5}6func main() {7 r := &Refactor{}8 fmt.Println("Type of Refactor struct:", reflect.TypeOf(r))9 fmt.Println("Type of getRefactorAgent method:", reflect.TypeOf(r.getRefactorAgent))10 fmt.Println("Method value of getRefactorAgent method:", reflect.ValueOf(r.getRefactorAgent))11 fmt.Println("Method value of getRefactorAgent method:", reflect.ValueOf(r.getRefactorAgent).Call(nil))12 fmt.Println("Method type of getRefactorAgent method:", reflect.TypeOf(r.getRefactorAgent).Call(nil))13 fmt.Println("Method type of getRefactorAgent method:", reflect.TypeOf(r.getRefactorAgent).Call(nil)[0])14 fmt.Println("Method type of getRefactorAgent method:", reflect.TypeOf(r.getRefactorAgent).Call(nil)[0].Type())15 fmt.Println("Method type of getRefactorAgent method:", reflect.TypeOf(r.getRefactorAgent).Call(nil)[0].Type().Kind())16 fmt.Println("Method type of getRefactorAgent method:", reflect.TypeOf(r.getRefactorAgent).Call(nil)[0].Type().Name())17 fmt.Println("Method type of getRefactorAgent method:", reflect.TypeOf(r.getRefactorAgent).Call(nil)[0].Type().String())18 fmt.Println("Method type of getRefactorAgent method:", reflect.TypeOf(r.getRefactorAgent).Call(nil)[0].Type().NumIn())19 fmt.Println("Method type of getRefactorAgent method:", reflect.TypeOf(r.getRefactorAgent).Call(nil)[0].Type().NumOut())20 fmt.Println("Method type of getRefactorAgent method:", reflect.TypeOf(r.getRefactorAgent).Call(nil)[0].Type().In(0))21 fmt.Println("Method type of getRefactorAgent method:", reflect.TypeOf(r.getRefactorAgent).Call(nil)[0].Type().Out(0))22 fmt.Println("Method type of getRefactorAgent method:", reflect.TypeOf(r.getRefactorAgent).Call(nil)[0].Type

Full Screen

Full Screen

getRefactorAgent

Using AI Code Generation

copy

Full Screen

1import (2func main() {3 ref = refactor.GetRefactorAgent()4 fmt.Println(ref)5}6import (7func main() {8 ref = refactor.GetRefactorAgent()9 fmt.Println(ref)10}11import (12func main() {13 ref = refactor.GetRefactorAgent()14 fmt.Println(ref)15}16import (17func main() {18 ref = refactor.GetRefactorAgent()19 fmt.Println(ref)20}21import (22func main() {23 ref = refactor.GetRefactorAgent()24 fmt.Println(ref)25}26import (27func main() {28 ref = refactor.GetRefactorAgent()29 fmt.Println(ref)30}31import (32func main() {33 ref = refactor.GetRefactorAgent()34 fmt.Println(ref)35}36import (

Full Screen

Full Screen

getRefactorAgent

Using AI Code Generation

copy

Full Screen

1import (2func main() {3 agent, err := refactor.GetRefactorAgent("golangci-lint")4 if err != nil {5 fmt.Println(err)6 }7}8import (9func main() {10 agent, err := refactor.GetRefactorAgent("golangci-lint")11 if err != nil {12 fmt.Println(err)13 }14}15import (16func main() {17 agent, err := refactor.GetRefactorAgent("golangci-lint")18 if err != nil {19 fmt.Println(err)20 }21}22import (23func main() {24 agent, err := refactor.GetRefactorAgent("golangci-lint")25 if err != nil {26 fmt.Println(err)27 }28}29import (30func main() {31 agent, err := refactor.GetRefactorAgent("golangci-lint")32 if err != nil {33 fmt.Println(err)34 }35}

Full Screen

Full Screen

getRefactorAgent

Using AI Code Generation

copy

Full Screen

1import (2type Agent struct {3}4type Refactor struct {5}6func (r Refactor) getRefactorAgent() Agent {7 agent := Agent{AgentId: 1, AgentName: "Agent 1", AgentCode: "1"}8}9func main() {10 refactor := Refactor{}11 agent := refactor.getRefactorAgent()12 fmt.Println(agent)13}14{1 Agent 1 1}15In the above example, we have created a method getRefactorAgent()

Full Screen

Full Screen

getRefactorAgent

Using AI Code Generation

copy

Full Screen

1import (2func main() {3 agent := refactor.GetRefactorAgent()4 fmt.Println(agent)5}6import (7func main() {8 agent := refactor.GetRefactorAgent()9 fmt.Println(agent)10}11import (12func main() {13 agent := refactor.GetRefactorAgent()14 fmt.Println(agent)15}16import (17func main() {18 agent := refactor.GetRefactorAgent()19 fmt.Println(agent)20}21import (22func main() {23 agent := refactor.GetRefactorAgent()24 fmt.Println(agent)25}26import (27func main() {28 agent := refactor.GetRefactorAgent()29 fmt.Println(agent)30}31import (32func main() {33 agent := refactor.GetRefactorAgent()34 fmt.Println(agent)35}36import (37func main() {38 agent := refactor.GetRefactorAgent()39 fmt.Println(agent

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