Best Gauge code snippet using parser.step
clickhouseparser_base_listener.go
Source:clickhouseparser_base_listener.go
...27// EnterSelect_query_main is called when production select_query_main is entered.28func (s *BaseClickHouseParserListener) EnterSelect_query_main(ctx *Select_query_mainContext) {}29// ExitSelect_query_main is called when production select_query_main is exited.30func (s *BaseClickHouseParserListener) ExitSelect_query_main(ctx *Select_query_mainContext) {}31// EnterSelect_with_step is called when production select_with_step is entered.32func (s *BaseClickHouseParserListener) EnterSelect_with_step(ctx *Select_with_stepContext) {}33// ExitSelect_with_step is called when production select_with_step is exited.34func (s *BaseClickHouseParserListener) ExitSelect_with_step(ctx *Select_with_stepContext) {}35// EnterSelect_select_step is called when production select_select_step is entered.36func (s *BaseClickHouseParserListener) EnterSelect_select_step(ctx *Select_select_stepContext) {}37// ExitSelect_select_step is called when production select_select_step is exited.38func (s *BaseClickHouseParserListener) ExitSelect_select_step(ctx *Select_select_stepContext) {}39// EnterSelect_from_step is called when production select_from_step is entered.40func (s *BaseClickHouseParserListener) EnterSelect_from_step(ctx *Select_from_stepContext) {}41// ExitSelect_from_step is called when production select_from_step is exited.42func (s *BaseClickHouseParserListener) ExitSelect_from_step(ctx *Select_from_stepContext) {}43// EnterSelect_array_join_step is called when production select_array_join_step is entered.44func (s *BaseClickHouseParserListener) EnterSelect_array_join_step(ctx *Select_array_join_stepContext) {45}46// ExitSelect_array_join_step is called when production select_array_join_step is exited.47func (s *BaseClickHouseParserListener) ExitSelect_array_join_step(ctx *Select_array_join_stepContext) {48}49// EnterSelect_sample_step is called when production select_sample_step is entered.50func (s *BaseClickHouseParserListener) EnterSelect_sample_step(ctx *Select_sample_stepContext) {}51// ExitSelect_sample_step is called when production select_sample_step is exited.52func (s *BaseClickHouseParserListener) ExitSelect_sample_step(ctx *Select_sample_stepContext) {}53// EnterSample_ratio is called when production sample_ratio is entered.54func (s *BaseClickHouseParserListener) EnterSample_ratio(ctx *Sample_ratioContext) {}55// ExitSample_ratio is called when production sample_ratio is exited.56func (s *BaseClickHouseParserListener) ExitSample_ratio(ctx *Sample_ratioContext) {}57// EnterSelect_join_step is called when production select_join_step is entered.58func (s *BaseClickHouseParserListener) EnterSelect_join_step(ctx *Select_join_stepContext) {}59// ExitSelect_join_step is called when production select_join_step is exited.60func (s *BaseClickHouseParserListener) ExitSelect_join_step(ctx *Select_join_stepContext) {}61// EnterSelect_join_right_part is called when production select_join_right_part is entered.62func (s *BaseClickHouseParserListener) EnterSelect_join_right_part(ctx *Select_join_right_partContext) {63}64// ExitSelect_join_right_part is called when production select_join_right_part is exited.65func (s *BaseClickHouseParserListener) ExitSelect_join_right_part(ctx *Select_join_right_partContext) {66}67// EnterSelect_prewhere_step is called when production select_prewhere_step is entered.68func (s *BaseClickHouseParserListener) EnterSelect_prewhere_step(ctx *Select_prewhere_stepContext) {}69// ExitSelect_prewhere_step is called when production select_prewhere_step is exited.70func (s *BaseClickHouseParserListener) ExitSelect_prewhere_step(ctx *Select_prewhere_stepContext) {}71// EnterSelect_where_step is called when production select_where_step is entered.72func (s *BaseClickHouseParserListener) EnterSelect_where_step(ctx *Select_where_stepContext) {}73// ExitSelect_where_step is called when production select_where_step is exited.74func (s *BaseClickHouseParserListener) ExitSelect_where_step(ctx *Select_where_stepContext) {}75// EnterSelect_groupby_step is called when production select_groupby_step is entered.76func (s *BaseClickHouseParserListener) EnterSelect_groupby_step(ctx *Select_groupby_stepContext) {}77// ExitSelect_groupby_step is called when production select_groupby_step is exited.78func (s *BaseClickHouseParserListener) ExitSelect_groupby_step(ctx *Select_groupby_stepContext) {}79// EnterSelect_having_step is called when production select_having_step is entered.80func (s *BaseClickHouseParserListener) EnterSelect_having_step(ctx *Select_having_stepContext) {}81// ExitSelect_having_step is called when production select_having_step is exited.82func (s *BaseClickHouseParserListener) ExitSelect_having_step(ctx *Select_having_stepContext) {}83// EnterSelect_orderby_step is called when production select_orderby_step is entered.84func (s *BaseClickHouseParserListener) EnterSelect_orderby_step(ctx *Select_orderby_stepContext) {}85// ExitSelect_orderby_step is called when production select_orderby_step is exited.86func (s *BaseClickHouseParserListener) ExitSelect_orderby_step(ctx *Select_orderby_stepContext) {}87// EnterSelect_limit_step is called when production select_limit_step is entered.88func (s *BaseClickHouseParserListener) EnterSelect_limit_step(ctx *Select_limit_stepContext) {}89// ExitSelect_limit_step is called when production select_limit_step is exited.90func (s *BaseClickHouseParserListener) ExitSelect_limit_step(ctx *Select_limit_stepContext) {}91// EnterSelect_limitby_step is called when production select_limitby_step is entered.92func (s *BaseClickHouseParserListener) EnterSelect_limitby_step(ctx *Select_limitby_stepContext) {}93// ExitSelect_limitby_step is called when production select_limitby_step is exited.94func (s *BaseClickHouseParserListener) ExitSelect_limitby_step(ctx *Select_limitby_stepContext) {}95// EnterSettings_step is called when production settings_step is entered.96func (s *BaseClickHouseParserListener) EnterSettings_step(ctx *Settings_stepContext) {}97// ExitSettings_step is called when production settings_step is exited.98func (s *BaseClickHouseParserListener) ExitSettings_step(ctx *Settings_stepContext) {}99// EnterSelect_format_step is called when production select_format_step is entered.100func (s *BaseClickHouseParserListener) EnterSelect_format_step(ctx *Select_format_stepContext) {}101// ExitSelect_format_step is called when production select_format_step is exited.102func (s *BaseClickHouseParserListener) ExitSelect_format_step(ctx *Select_format_stepContext) {}103// EnterInsert_query is called when production insert_query is entered.104func (s *BaseClickHouseParserListener) EnterInsert_query(ctx *Insert_queryContext) {}105// ExitInsert_query is called when production insert_query is exited.106func (s *BaseClickHouseParserListener) ExitInsert_query(ctx *Insert_queryContext) {}107// EnterCreate_query is called when production create_query is entered.108func (s *BaseClickHouseParserListener) EnterCreate_query(ctx *Create_queryContext) {}109// ExitCreate_query is called when production create_query is exited.110func (s *BaseClickHouseParserListener) ExitCreate_query(ctx *Create_queryContext) {}111// EnterRename_query is called when production rename_query is entered.112func (s *BaseClickHouseParserListener) EnterRename_query(ctx *Rename_queryContext) {}113// ExitRename_query is called when production rename_query is exited.114func (s *BaseClickHouseParserListener) ExitRename_query(ctx *Rename_queryContext) {}115// EnterDrop_query is called when production drop_query is entered.116func (s *BaseClickHouseParserListener) EnterDrop_query(ctx *Drop_queryContext) {}117// ExitDrop_query is called when production drop_query is exited.118func (s *BaseClickHouseParserListener) ExitDrop_query(ctx *Drop_queryContext) {}119// EnterAlter_query is called when production alter_query is entered.120func (s *BaseClickHouseParserListener) EnterAlter_query(ctx *Alter_queryContext) {}121// ExitAlter_query is called when production alter_query is exited.122func (s *BaseClickHouseParserListener) ExitAlter_query(ctx *Alter_queryContext) {}123// EnterAlter_query_element is called when production alter_query_element is entered.124func (s *BaseClickHouseParserListener) EnterAlter_query_element(ctx *Alter_query_elementContext) {}125// ExitAlter_query_element is called when production alter_query_element is exited.126func (s *BaseClickHouseParserListener) ExitAlter_query_element(ctx *Alter_query_elementContext) {}127// EnterClickhouse_type is called when production clickhouse_type is entered.128func (s *BaseClickHouseParserListener) EnterClickhouse_type(ctx *Clickhouse_typeContext) {}129// ExitClickhouse_type is called when production clickhouse_type is exited.130func (s *BaseClickHouseParserListener) ExitClickhouse_type(ctx *Clickhouse_typeContext) {}131// EnterSimple_type is called when production simple_type is entered.132func (s *BaseClickHouseParserListener) EnterSimple_type(ctx *Simple_typeContext) {}133// ExitSimple_type is called when production simple_type is exited.134func (s *BaseClickHouseParserListener) ExitSimple_type(ctx *Simple_typeContext) {}135// EnterEnum_entry is called when production enum_entry is entered.136func (s *BaseClickHouseParserListener) EnterEnum_entry(ctx *Enum_entryContext) {}137// ExitEnum_entry is called when production enum_entry is exited.138func (s *BaseClickHouseParserListener) ExitEnum_entry(ctx *Enum_entryContext) {}139// EnterUse_query is called when production use_query is entered.140func (s *BaseClickHouseParserListener) EnterUse_query(ctx *Use_queryContext) {}141// ExitUse_query is called when production use_query is exited.142func (s *BaseClickHouseParserListener) ExitUse_query(ctx *Use_queryContext) {}143// EnterSet_query is called when production set_query is entered.144func (s *BaseClickHouseParserListener) EnterSet_query(ctx *Set_queryContext) {}145// ExitSet_query is called when production set_query is exited.146func (s *BaseClickHouseParserListener) ExitSet_query(ctx *Set_queryContext) {}147// EnterAssignment_list is called when production assignment_list is entered.148func (s *BaseClickHouseParserListener) EnterAssignment_list(ctx *Assignment_listContext) {}149// ExitAssignment_list is called when production assignment_list is exited.150func (s *BaseClickHouseParserListener) ExitAssignment_list(ctx *Assignment_listContext) {}151// EnterAssignment is called when production assignment is entered.152func (s *BaseClickHouseParserListener) EnterAssignment(ctx *AssignmentContext) {}153// ExitAssignment is called when production assignment is exited.154func (s *BaseClickHouseParserListener) ExitAssignment(ctx *AssignmentContext) {}155// EnterKill_query_query is called when production kill_query_query is entered.156func (s *BaseClickHouseParserListener) EnterKill_query_query(ctx *Kill_query_queryContext) {}157// ExitKill_query_query is called when production kill_query_query is exited.158func (s *BaseClickHouseParserListener) ExitKill_query_query(ctx *Kill_query_queryContext) {}159// EnterOptimize_query is called when production optimize_query is entered.160func (s *BaseClickHouseParserListener) EnterOptimize_query(ctx *Optimize_queryContext) {}161// ExitOptimize_query is called when production optimize_query is exited.162func (s *BaseClickHouseParserListener) ExitOptimize_query(ctx *Optimize_queryContext) {}163// EnterTable_properties_query is called when production table_properties_query is entered.164func (s *BaseClickHouseParserListener) EnterTable_properties_query(ctx *Table_properties_queryContext) {165}166// ExitTable_properties_query is called when production table_properties_query is exited.167func (s *BaseClickHouseParserListener) ExitTable_properties_query(ctx *Table_properties_queryContext) {168}169// EnterShow_tables_query is called when production show_tables_query is entered.170func (s *BaseClickHouseParserListener) EnterShow_tables_query(ctx *Show_tables_queryContext) {}171// ExitShow_tables_query is called when production show_tables_query is exited.172func (s *BaseClickHouseParserListener) ExitShow_tables_query(ctx *Show_tables_queryContext) {}173// EnterShow_processlist_query is called when production show_processlist_query is entered.174func (s *BaseClickHouseParserListener) EnterShow_processlist_query(ctx *Show_processlist_queryContext) {175}176// ExitShow_processlist_query is called when production show_processlist_query is exited.177func (s *BaseClickHouseParserListener) ExitShow_processlist_query(ctx *Show_processlist_queryContext) {178}179// EnterCheck_query is called when production check_query is entered.180func (s *BaseClickHouseParserListener) EnterCheck_query(ctx *Check_queryContext) {}181// ExitCheck_query is called when production check_query is exited.182func (s *BaseClickHouseParserListener) ExitCheck_query(ctx *Check_queryContext) {}183// EnterFull_table_name is called when production full_table_name is entered.184func (s *BaseClickHouseParserListener) EnterFull_table_name(ctx *Full_table_nameContext) {}185// ExitFull_table_name is called when production full_table_name is exited.186func (s *BaseClickHouseParserListener) ExitFull_table_name(ctx *Full_table_nameContext) {}187// EnterPartition_name is called when production partition_name is entered.188func (s *BaseClickHouseParserListener) EnterPartition_name(ctx *Partition_nameContext) {}189// ExitPartition_name is called when production partition_name is exited.190func (s *BaseClickHouseParserListener) ExitPartition_name(ctx *Partition_nameContext) {}191// EnterCluster_name is called when production cluster_name is entered.192func (s *BaseClickHouseParserListener) EnterCluster_name(ctx *Cluster_nameContext) {}193// ExitCluster_name is called when production cluster_name is exited.194func (s *BaseClickHouseParserListener) ExitCluster_name(ctx *Cluster_nameContext) {}195// EnterDatabase_name is called when production database_name is entered.196func (s *BaseClickHouseParserListener) EnterDatabase_name(ctx *Database_nameContext) {}197// ExitDatabase_name is called when production database_name is exited.198func (s *BaseClickHouseParserListener) ExitDatabase_name(ctx *Database_nameContext) {}199// EnterTable_name is called when production table_name is entered.200func (s *BaseClickHouseParserListener) EnterTable_name(ctx *Table_nameContext) {}201// ExitTable_name is called when production table_name is exited.202func (s *BaseClickHouseParserListener) ExitTable_name(ctx *Table_nameContext) {}203// EnterFormat_name is called when production format_name is entered.204func (s *BaseClickHouseParserListener) EnterFormat_name(ctx *Format_nameContext) {}205// ExitFormat_name is called when production format_name is exited.206func (s *BaseClickHouseParserListener) ExitFormat_name(ctx *Format_nameContext) {}207// EnterQuery_outfile_step is called when production query_outfile_step is entered.208func (s *BaseClickHouseParserListener) EnterQuery_outfile_step(ctx *Query_outfile_stepContext) {}209// ExitQuery_outfile_step is called when production query_outfile_step is exited.210func (s *BaseClickHouseParserListener) ExitQuery_outfile_step(ctx *Query_outfile_stepContext) {}211// EnterEngine is called when production engine is entered.212func (s *BaseClickHouseParserListener) EnterEngine(ctx *EngineContext) {}213// ExitEngine is called when production engine is exited.214func (s *BaseClickHouseParserListener) ExitEngine(ctx *EngineContext) {}215// EnterIdentifier_with_optional_parameters is called when production identifier_with_optional_parameters is entered.216func (s *BaseClickHouseParserListener) EnterIdentifier_with_optional_parameters(ctx *Identifier_with_optional_parametersContext) {217}218// ExitIdentifier_with_optional_parameters is called when production identifier_with_optional_parameters is exited.219func (s *BaseClickHouseParserListener) ExitIdentifier_with_optional_parameters(ctx *Identifier_with_optional_parametersContext) {220}221// EnterIdentifier_with_parameters is called when production identifier_with_parameters is entered.222func (s *BaseClickHouseParserListener) EnterIdentifier_with_parameters(ctx *Identifier_with_parametersContext) {223}224// ExitIdentifier_with_parameters is called when production identifier_with_parameters is exited....
refactor_test.go
Source:refactor_test.go
...14func Test(t *testing.T) { TestingT(t) }15type MySuite struct{}16var _ = Suite(&MySuite{})17func (s *MySuite) TestRefactoringOfStepsWithNoArgs(c *C) {18 oldStep := "first step"19 newStep := "second step"20 tokens := []*parser.Token{21 &parser.Token{Kind: gauge.SpecKind, Value: "Spec Heading", LineNo: 1},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, "")447}...
formatter_test.go
Source:formatter_test.go
...18func (s *MySuite) TestFormatSpecification(c *C) {19 tokens := []*parser.Token{20 &parser.Token{Kind: gauge.SpecKind, Value: "Spec Heading", LineNo: 1},21 &parser.Token{Kind: gauge.ScenarioKind, Value: "Scenario Heading", LineNo: 2},22 &parser.Token{Kind: gauge.StepKind, Value: "Example step", LineNo: 3, Lines: []string{"Example step"}},23 &parser.Token{Kind: gauge.StepKind, Value: "Step with inline table", LineNo: 3, Lines: []string{"Step with inline table "}},24 &parser.Token{Kind: gauge.TableHeader, Args: []string{"id", "name"}},25 &parser.Token{Kind: gauge.TableRow, Args: []string{"<1>", "foo"}},26 &parser.Token{Kind: gauge.TableRow, Args: []string{"2", "bar"}},27 }28 spec, _, _ := new(parser.SpecParser).CreateSpecification(tokens, gauge.NewConceptDictionary(), "")29 formatted := FormatSpecification(spec)30 c.Assert(formatted, Equals,31 `# Spec Heading32## Scenario Heading33* Example step34* Step with inline table35 |id |name|36 |---|----|37 |<1>|foo |38 |2 |bar |39`)40}41func (s *MySuite) TestFormatTable(c *C) {42 cell1 := gauge.TableCell{Value: "john", CellType: gauge.Static}43 cell2 := gauge.TableCell{Value: "doe", CellType: gauge.Static}44 headers := []string{"name1", "name2"}45 cols := [][]gauge.TableCell{{cell1}, {cell2}}46 table := gauge.NewTable(headers, cols, 10)47 got := FormatTable(table)48 want := `49 |name1|name2|50 |-----|-----|51 |john |doe |52`53 c.Assert(got, Equals, want)54}55func (s *MySuite) TestFormatTableWithUmlautChars(c *C) {56 // umlaut characters are unicode and can take up twice the space of regular chars57 cell1 := gauge.TableCell{Value: "Büsingen", CellType: gauge.Static}58 cell2 := gauge.TableCell{Value: "HauptstraÃe", CellType: gauge.Static}59 headers := []string{"col1", "col2"}60 cols := [][]gauge.TableCell{{cell1}, {cell2}}61 table := gauge.NewTable(headers, cols, 10)62 got := FormatTable(table)63 want := `64 |col1 |col2 |65 |--------|-----------|66 |Büsingen|HauptstraÃe|67`68 c.Assert(got, Equals, want)69}70func (s *MySuite) TestFormatConcepts(c *C) {71 dictionary := gauge.NewConceptDictionary()72 step1 := &gauge.Step{Value: "sdsf", LineText: "sdsf", IsConcept: true, LineNo: 1, PreComments: []*gauge.Comment{&gauge.Comment{Value: "COMMENT", LineNo: 1}}}73 step2 := &gauge.Step{Value: "dsfdsfdsf", LineText: "dsfdsfdsf", IsConcept: true, LineNo: 2, Items: []gauge.Item{&gauge.Step{Value: "sfd", LineText: "sfd", IsConcept: false}, &gauge.Step{Value: "sdfsdf" + "T", LineText: "sdfsdf" + "T", IsConcept: false}}}74 dictionary.ConceptsMap[step1.Value] = &gauge.Concept{ConceptStep: step1, FileName: "file.cpt"}75 dictionary.ConceptsMap[step2.Value] = &gauge.Concept{ConceptStep: step2, FileName: "file.cpt"}76 formatted := FormatConcepts(dictionary)77 c.Assert(formatted["file.cpt"], Equals, `COMMENT78# sdsf79# dsfdsfdsf80* sdfsdfT81`)82}83func (s *MySuite) TestFormatSpecificationWithTags(c *C) {84 tokens := []*parser.Token{85 &parser.Token{Kind: gauge.SpecKind, Value: "My Spec Heading", LineNo: 1},86 &parser.Token{Kind: gauge.TagKind, Args: []string{"tag1", "tag2"}, LineNo: 2},87 &parser.Token{Kind: gauge.ScenarioKind, Value: "Scenario Heading", LineNo: 3},88 &parser.Token{Kind: gauge.TagKind, Args: []string{"tag3", "tag4"}, LineNo: 4},89 &parser.Token{Kind: gauge.StepKind, Value: "Example step", LineNo: 5, Lines: []string{"Example step"}},90 &parser.Token{Kind: gauge.ScenarioKind, Value: "Scenario Heading1", LineNo: 6},91 &parser.Token{Kind: gauge.TagKind, Args: []string{"tag3", "tag4"}, LineNo: 7},92 &parser.Token{Kind: gauge.StepKind, Value: "Example step", LineNo: 8, Lines: []string{"Example step"}},93 }94 spec, _, _ := new(parser.SpecParser).CreateSpecification(tokens, gauge.NewConceptDictionary(), "")95 formatted := FormatSpecification(spec)96 c.Assert(formatted, Equals,97 `# My Spec Heading98tags: tag1, tag299## Scenario Heading100tags: tag3, tag4101* Example step102## Scenario Heading1103tags: tag3, tag4104* Example step105`)106}107func (s *MySuite) TestFormatSpecificationWithTagsInMutipleLines(c *C) {108 tokens := []*parser.Token{109 &parser.Token{Kind: gauge.SpecKind, Value: "My Spec Heading", LineNo: 1},110 &parser.Token{Kind: gauge.TagKind, Args: []string{"tag1", "tag2"}, LineNo: 2},111 &parser.Token{Kind: gauge.TagKind, Args: []string{"tag3", "tag4"}, LineNo: 3},112 &parser.Token{Kind: gauge.TagKind, Args: []string{"tag5"}, LineNo: 4},113 &parser.Token{Kind: gauge.ScenarioKind, Value: "Scenario Heading", LineNo: 5},114 &parser.Token{Kind: gauge.TagKind, Args: []string{"tag3", "tag4"}, LineNo: 6},115 &parser.Token{Kind: gauge.StepKind, Value: "Example step", LineNo: 7, Lines: []string{"Example step"}},116 &parser.Token{Kind: gauge.ScenarioKind, Value: "Scenario Heading1", LineNo: 8},117 &parser.Token{Kind: gauge.TagKind, Args: []string{"tag3", "tag4"}, LineNo: 9},118 &parser.Token{Kind: gauge.StepKind, Value: "Example step", LineNo: 10, Lines: []string{"Example step"}},119 }120 spec, _, _ := new(parser.SpecParser).CreateSpecification(tokens, gauge.NewConceptDictionary(), "")121 formatted := FormatSpecification(spec)122 c.Assert(formatted, Equals,123 `# My Spec Heading124tags: tag1, tag2,`+string(" \n ")+`tag3, tag4,`+string(" \n ")+`tag5125## Scenario Heading126tags: tag3, tag4127* Example step128## Scenario Heading1129tags: tag3, tag4130* Example step131`)132}133func (s *MySuite) TestFormatSpecificationWithTeardownSteps(c *C) {134 tokens := []*parser.Token{135 &parser.Token{Kind: gauge.SpecKind, Value: "My Spec Heading", LineNo: 1},136 &parser.Token{Kind: gauge.TagKind, Args: []string{"tag1", "tag2"}, LineNo: 2},137 &parser.Token{Kind: gauge.ScenarioKind, Value: "Scenario Heading", LineNo: 3},138 &parser.Token{Kind: gauge.TagKind, Args: []string{"tag3", "tag4"}, LineNo: 4},139 &parser.Token{Kind: gauge.StepKind, Value: "Example step", LineNo: 5, Lines: []string{"Example step"}},140 &parser.Token{Kind: gauge.ScenarioKind, Value: "Scenario Heading1", LineNo: 6},141 &parser.Token{Kind: gauge.TagKind, Args: []string{"tag3", "tag4"}, LineNo: 7},142 &parser.Token{Kind: gauge.StepKind, Value: "Example step", LineNo: 8, Lines: []string{"Example step"}},143 &parser.Token{Kind: gauge.TearDownKind, Value: "____", LineNo: 9},144 &parser.Token{Kind: gauge.StepKind, Value: "Example step1", LineNo: 10, Lines: []string{"Example step1"}},145 &parser.Token{Kind: gauge.StepKind, Value: "Example step2", LineNo: 11, Lines: []string{"Example step2"}},146 }147 spec, _, _ := new(parser.SpecParser).CreateSpecification(tokens, gauge.NewConceptDictionary(), "")148 formatted := FormatSpecification(spec)149 c.Assert(formatted, Equals,150 `# My Spec Heading151tags: tag1, tag2152## Scenario Heading153tags: tag3, tag4154* Example step155## Scenario Heading1156tags: tag3, tag4157* Example step158____159* Example step1160* Example step2161`)162}163func (s *MySuite) TestFormatStep(c *C) {164 step := &gauge.Step{Value: "my step with {}, {}, {} and {}", Args: []*gauge.StepArg{&gauge.StepArg{Value: "static \"foo\"", ArgType: gauge.Static},165 &gauge.StepArg{Name: "dynamic", Value: "\"foo\"", ArgType: gauge.Dynamic},166 &gauge.StepArg{Name: "file:user\".txt", ArgType: gauge.SpecialString},167 &gauge.StepArg{Name: "table :hell\".csv", ArgType: gauge.SpecialTable}}}168 formatted := FormatStep(step)169 c.Assert(formatted, Equals, `* my step with "static \"foo\"", <dynamic>, <file:user\".txt> and <table :hell\".csv>170`)171}172func (s *MySuite) TestFormatStepsWithResolveArgs(c *C) {173 step := &gauge.Step{Value: "my step with {}, {}", Args: []*gauge.StepArg{&gauge.StepArg{Value: "static \"foo\"", ArgType: gauge.Static},174 &gauge.StepArg{Name: "dynamic", Value: "\"foo\"", ArgType: gauge.Dynamic}},175 Fragments: []*gauge_messages.Fragment{176 &gauge_messages.Fragment{Text: "my step with "},177 &gauge_messages.Fragment{FragmentType: gauge_messages.Fragment_Parameter, Parameter: &gauge_messages.Parameter{Value: "static \"foo\"", ParameterType: gauge_messages.Parameter_Static}},178 &gauge_messages.Fragment{Text: ", "},179 &gauge_messages.Fragment{FragmentType: gauge_messages.Fragment_Parameter, Parameter: &gauge_messages.Parameter{Value: "\"foo\"", ParameterType: gauge_messages.Parameter_Dynamic}}}}180 formatted := FormatStepWithResolvedArgs(step)181 c.Assert(formatted, Equals, `* my step with "static "foo"", ""foo""182`)183}184func (s *MySuite) TestFormatStepsWithResolveArgsWithConcept(c *C) {185 step := &gauge.Step{Value: "my step with {}, {}", Args: []*gauge.StepArg{&gauge.StepArg{Value: "static \"foo\"", ArgType: gauge.Dynamic},186 &gauge.StepArg{Name: "dynamic", Value: "\"foo\"", ArgType: gauge.Static}},187 Fragments: []*gauge_messages.Fragment{188 &gauge_messages.Fragment{Text: "my step with "},189 &gauge_messages.Fragment{FragmentType: gauge_messages.Fragment_Parameter, Parameter: &gauge_messages.Parameter{Value: "static \"foo\"", ParameterType: gauge_messages.Parameter_Dynamic}},190 &gauge_messages.Fragment{Text: ", "},191 &gauge_messages.Fragment{FragmentType: gauge_messages.Fragment_Parameter, Parameter: &gauge_messages.Parameter{Value: "\"foo\"", ParameterType: gauge_messages.Parameter_Static}}}}192 formatted := FormatStepWithResolvedArgs(step)193 c.Assert(formatted, Equals, `* my step with "static "foo"", ""foo""194`)195}196func (s *MySuite) TestFormatStepsWithResolveArgsWithSpecialArguments(c *C) {197 step := &gauge.Step{Value: "my step with {}, {}", Args: []*gauge.StepArg{&gauge.StepArg{Value: "static \"foo\"", ArgType: gauge.SpecialString},198 &gauge.StepArg{Name: "dynamic", Value: "\"foo\"", ArgType: gauge.SpecialTable}},199 Fragments: []*gauge_messages.Fragment{200 &gauge_messages.Fragment{Text: "my step with "},201 &gauge_messages.Fragment{FragmentType: gauge_messages.Fragment_Parameter, Parameter: &gauge_messages.Parameter{Value: "static \"foo\"", ParameterType: gauge_messages.Parameter_Special_String}},202 &gauge_messages.Fragment{Text: ", "},203 &gauge_messages.Fragment{FragmentType: gauge_messages.Fragment_Parameter, Parameter: &gauge_messages.Parameter{Value: "\"foo\"", ParameterType: gauge_messages.Parameter_Special_Table}}}}204 formatted := FormatStepWithResolvedArgs(step)205 c.Assert(formatted, Equals, `* my step with "static "foo"", ""foo""206`)207}208func (s *MySuite) TestFormattingWithTableAsAComment(c *C) {209 tokens := []*parser.Token{210 &parser.Token{Kind: gauge.SpecKind, Value: "My Spec Heading", LineNo: 1},211 &parser.Token{Kind: gauge.CommentKind, Value: "\n", LineNo: 2},212 &parser.Token{Kind: gauge.ScenarioKind, Value: "Scenario Heading", LineNo: 3},213 &parser.Token{Kind: gauge.TableHeader, Args: []string{"id", "name"}, Lines: []string{" |id|name|"}},214 &parser.Token{Kind: gauge.TableRow, Args: []string{"1", "foo"}, Lines: []string{" |1|foo|"}},215 &parser.Token{Kind: gauge.TableRow, Args: []string{"2", "bar"}, Lines: []string{"|2|bar|"}},216 &parser.Token{Kind: gauge.CommentKind, Value: "\n", LineNo: 7},217 &parser.Token{Kind: gauge.TableHeader, Args: []string{"id", "name"}, Lines: []string{" |id|name1|"}},218 &parser.Token{Kind: gauge.TableRow, Args: []string{"1", "foo"}, Lines: []string{" |1|foo|"}},219 &parser.Token{Kind: gauge.TableRow, Args: []string{"2", "bar"}, Lines: []string{"|2|bar|"}},220 &parser.Token{Kind: gauge.StepKind, Value: "Example step", LineNo: 11, Lines: []string{"Example step"}},221 }222 spec, _, _ := new(parser.SpecParser).CreateSpecification(tokens, gauge.NewConceptDictionary(), "")223 formatted := FormatSpecification(spec)224 c.Assert(formatted, Equals,225 `# My Spec Heading226## Scenario Heading227 |id|name|228 |--|----|229 |1 |foo |230 |2 |bar |231 |id|name1|232 |1|foo|233|2|bar|234* Example step235`)236}237func (s *MySuite) TestFormatSpecificationWithTableContainingDynamicParameters(c *C) {238 tokens := []*parser.Token{239 &parser.Token{Kind: gauge.SpecKind, Value: "Spec Heading", LineNo: 1},240 &parser.Token{Kind: gauge.TableHeader, Args: []string{"id", "foo"}},241 &parser.Token{Kind: gauge.TableRow, Args: []string{"1", "f"}},242 &parser.Token{Kind: gauge.ScenarioKind, Value: "Scenario Heading", LineNo: 2},243 &parser.Token{Kind: gauge.StepKind, Value: "Example step", LineNo: 3, Lines: []string{"Example step"}},244 &parser.Token{Kind: gauge.StepKind, Value: "Step with inline table", LineNo: 3, Lines: []string{"Step with inline table "}},245 &parser.Token{Kind: gauge.TableHeader, Args: []string{"id", "name"}},246 &parser.Token{Kind: gauge.TableRow, Args: []string{"1", "<foo>"}},247 &parser.Token{Kind: gauge.TableRow, Args: []string{"2", "bar"}},248 }249 spec, _, _ := new(parser.SpecParser).CreateSpecification(tokens, gauge.NewConceptDictionary(), "")250 formatted := FormatSpecification(spec)251 c.Assert(formatted, Equals,252 `# Spec Heading253 |id|foo|254 |--|---|255 |1 |f |256## Scenario Heading257* Example step258* Step with inline table259 |id|name |260 |--|-----|261 |1 |<foo>|262 |2 |bar |263`)264}265func (s *MySuite) TestFormatShouldRetainNewlines(c *C) {266 tokens := []*parser.Token{267 &parser.Token{Kind: gauge.SpecKind, Value: "My Spec Heading", LineNo: 1},268 &parser.Token{Kind: gauge.CommentKind, Value: "\n", LineNo: 2},269 &parser.Token{Kind: gauge.CommentKind, Value: "\n", LineNo: 3},270 &parser.Token{Kind: gauge.ScenarioKind, Value: "Scenario Heading", LineNo: 4},271 &parser.Token{Kind: gauge.TableHeader, Args: []string{"id", "name"}, Lines: []string{" |id|name|"}},272 &parser.Token{Kind: gauge.TableRow, Args: []string{"1", "foo"}, Lines: []string{" |1|foo|"}},273 &parser.Token{Kind: gauge.TableRow, Args: []string{"2", "bar"}, Lines: []string{"|2|bar|"}},274 &parser.Token{Kind: gauge.StepKind, Value: "Example step", LineNo: 8, Lines: []string{"Example step"}},275 &parser.Token{Kind: gauge.TableHeader, Args: []string{"id", "name"}},276 &parser.Token{Kind: gauge.TableRow, Args: []string{"1", "<foo>"}},277 &parser.Token{Kind: gauge.TableRow, Args: []string{"2", "bar"}},278 }279 env.AllowScenarioDatatable = func() bool { return true }280 spec, _, _ := new(parser.SpecParser).CreateSpecification(tokens, gauge.NewConceptDictionary(), "")281 formatted := FormatSpecification(spec)282 c.Assert(formatted, Equals,283 `# My Spec Heading284## Scenario Heading285 |id|name|286 |--|----|287 |1 |foo |288 |2 |bar |289* Example step290 |id|name |291 |--|-----|292 |1 |<foo>|293 |2 |bar |294`)295}296func (s *MySuite) TestFormatShouldRetainNewlinesBetweenSteps(c *C) {297 tokens := []*parser.Token{298 &parser.Token{Kind: gauge.SpecKind, Value: "My Spec Heading", LineNo: 1},299 &parser.Token{Kind: gauge.ScenarioKind, Value: "Scenario Heading", LineNo: 4},300 &parser.Token{Kind: gauge.StepKind, Value: "Example step", LineNo: 6, Lines: []string{"Example step"}, Suffix: "\n\n"},301 &parser.Token{Kind: gauge.StepKind, Value: "Example step", LineNo: 9, Lines: []string{"Example step"}, Suffix: "\n\n"},302 }303 spec, _, _ := new(parser.SpecParser).CreateSpecification(tokens, gauge.NewConceptDictionary(), "")304 formatted := FormatSpecification(spec)305 c.Assert(formatted, Equals,306 `# My Spec Heading307## Scenario Heading308* Example step309* Example step310`)311}312func (s *MySuite) TestFormatShouldStripDuplicateNewlinesBeforeInlineTable(c *C) {313 tokens := []*parser.Token{314 &parser.Token{Kind: gauge.SpecKind, Value: "My Spec Heading", LineNo: 1},315 &parser.Token{Kind: gauge.CommentKind, Value: "\n", LineNo: 2},316 &parser.Token{Kind: gauge.CommentKind, Value: "\n", LineNo: 3},317 &parser.Token{Kind: gauge.ScenarioKind, Value: "Scenario Heading", LineNo: 4},318 &parser.Token{Kind: gauge.TableHeader, Args: []string{"id", "name"}, Lines: []string{" |id|name|"}},319 &parser.Token{Kind: gauge.TableRow, Args: []string{"1", "foo"}, Lines: []string{" |1|foo|"}},320 &parser.Token{Kind: gauge.TableRow, Args: []string{"2", "bar"}, Lines: []string{"|2|bar|"}},321 &parser.Token{Kind: gauge.StepKind, Value: "Example step", LineNo: 8, Lines: []string{"Example step\n\n"}},322 &parser.Token{Kind: gauge.TableHeader, Args: []string{"id", "name"}},323 &parser.Token{Kind: gauge.TableRow, Args: []string{"1", "<foo>"}},324 &parser.Token{Kind: gauge.TableRow, Args: []string{"2", "bar"}},325 }326 spec, _, _ := new(parser.SpecParser).CreateSpecification(tokens, gauge.NewConceptDictionary(), "")327 formatted := FormatSpecification(spec)328 c.Assert(formatted, Equals,329 `# My Spec Heading330## Scenario Heading331 |id|name|332 |--|----|333 |1 |foo |334 |2 |bar |335* Example step336 |id|name |337 |--|-----|338 |1 |<foo>|339 |2 |bar |340`)341}342func (s *MySuite) TestFormatShouldStripDuplicateNewlinesBeforeInlineTableInTeardown(c *C) {343 tokens := []*parser.Token{344 &parser.Token{Kind: gauge.SpecKind, Value: "My Spec Heading", LineNo: 1},345 &parser.Token{Kind: gauge.CommentKind, Value: "\n", LineNo: 2},346 &parser.Token{Kind: gauge.CommentKind, Value: "\n", LineNo: 3},347 &parser.Token{Kind: gauge.ScenarioKind, Value: "Scenario Heading", LineNo: 4},348 &parser.Token{Kind: gauge.TableHeader, Args: []string{"id", "name"}, Lines: []string{" |id|name|"}},349 &parser.Token{Kind: gauge.TableRow, Args: []string{"1", "foo"}, Lines: []string{" |1|foo|"}},350 &parser.Token{Kind: gauge.TableRow, Args: []string{"2", "bar"}, Lines: []string{"|2|bar|"}},351 &parser.Token{Kind: gauge.StepKind, Value: "Example step", LineNo: 8, Lines: []string{"Example step\n\n"}},352 &parser.Token{Kind: gauge.TableHeader, Args: []string{"id", "name"}},353 &parser.Token{Kind: gauge.TableRow, Args: []string{"1", "<foo>"}},354 &parser.Token{Kind: gauge.TableRow, Args: []string{"2", "bar"}},355 &parser.Token{Kind: gauge.CommentKind, Value: "\n", LineNo: 10},356 &parser.Token{Kind: gauge.TearDownKind, Value: "____", LineNo: 9},357 &parser.Token{Kind: gauge.CommentKind, Value: "\n", LineNo: 10},358 &parser.Token{Kind: gauge.StepKind, Value: "Example step", LineNo: 8, Lines: []string{"Example step\n\n\n"}},359 &parser.Token{Kind: gauge.TableHeader, Args: []string{"id", "name"}},360 &parser.Token{Kind: gauge.TableRow, Args: []string{"1", "<foo>"}},361 &parser.Token{Kind: gauge.TableRow, Args: []string{"2", "bar"}},362 }363 spec, _, _ := new(parser.SpecParser).CreateSpecification(tokens, gauge.NewConceptDictionary(), "")364 formatted := FormatSpecification(spec)365 c.Assert(formatted, Equals,366 `# My Spec Heading367## Scenario Heading368 |id|name|369 |--|----|370 |1 |foo |371 |2 |bar |372* Example step373 |id|name |374 |--|-----|375 |1 |<foo>|376 |2 |bar |377____378* Example step379 |id|name |380 |--|-----|381 |1 |<foo>|382 |2 |bar |383`)384}385func (s *MySuite) TestFormatShouldNotAddExtraNewLinesBeforeDataTable(c *C) {386 spec, _, _ := new(parser.SpecParser).Parse(`# Specification Heading387 |Word |Vowel Count|388 |------|-----------|389 |Gauge |3 |390 |Mingle|2 |391 |Snap |1 |392 |GoCD |1 |...
step
Using AI Code Generation
1import (2func main() {3 fset := token.NewFileSet()4 node, err := parser.ParseFile(fset, "1.go", nil, parser.ParseComments)5 if err != nil {6 log.Fatal(err)7 }8 ast.Inspect(node, func(n ast.Node) bool {9 if n == nil {10 }11 switch x := n.(type) {12 fmt.Println(x.Name.Name)13 fmt.Println(x.Name)14 }15 })16}
step
Using AI Code Generation
1import (2func main() {3 f, err := parser.ParseFile(fset, "1.go", nil, 0)4 if err != nil {5 log.Fatal(err)6 }7 fmt.Println("AST:")8 ast.Print(fset, f)9 p.Init(fset, f, nil, 0)10 for {11 _, tok, lit := p.Scan()12 if tok == token.EOF {13 }14 fmt.Printf("%s\t%s\n", tok, lit)15 }16}
step
Using AI Code Generation
1import (2func main() {3 input, err := io.ReadAll(os.Stdin)4 if err != nil {5 fmt.Println(err)6 }7 p := css.NewParser(input)8 for {9 tt, data := p.Next()10 switch tt {11 fmt.Println("error:", p.Err())12 }13 fmt.Printf("%s: %q\n", css.TokenType(tt), data)14 }15}
step
Using AI Code Generation
1import (2func main() {3 parser := otto.New()4 parser.Set("x", 1)5 parser.Set("y", 2)6 parser.Set("z", 3)
step
Using AI Code Generation
1import (2func main() {3import "fmt"4func main() {5 fmt.Println("Hello, 世界")6}`7 f, err := parser.ParseFile(fset, "", src, 0)8 if err != nil {9 fmt.Println(err)10 }11 fmt.Printf("%#v", f)12}13&ast.File{14 Name: &ast.Ident{15 },16 Decls: []ast.Decl{17 &ast.GenDecl{18 Tok: "import",19 Specs: []ast.Spec{20 &ast.ImportSpec{21 Path: &ast.BasicLit{22 },23 },24 },25 },26 &ast.FuncDecl{27 Name: &ast.Ident{28 Obj: &ast.Object{29 Decl: *(obj @ 43),30 },31 },32 Type: &ast.FuncType{33 Params: &ast.FieldList{34 },35 },36 Body: &ast.BlockStmt{37 List: []ast.Stmt{38 &ast.ExprStmt{39 X: &ast.CallExpr{40 Fun: &ast.SelectorExpr{41 X: &ast.Ident{42 Obj: &ast.Object{
Learn to execute automation testing from scratch with LambdaTest Learning Hub. Right from setting up the prerequisites to run your first automation test, to following best practices and diving deeper into advanced test scenarios. LambdaTest Learning Hubs compile a list of step-by-step guides to help you be proficient with different test automation frameworks i.e. Selenium, Cypress, TestNG etc.
You could also refer to video tutorials over LambdaTest YouTube channel to get step by step demonstration from industry experts.
Get 100 minutes of automation test minutes FREE!!