How to use Kind method of gauge Package

Best Gauge code snippet using gauge.Kind

specparser_test.go

Source:specparser_test.go Github

copy

Full Screen

...17type MySuite struct{}18var _ = Suite(&MySuite{})19func (s *MySuite) TestToCheckTagsInSpecLevel(c *C) {20 tokens := []*Token{21 {Kind: gauge.SpecKind, Value: "Spec Heading", LineNo: 1},22 {Kind: gauge.TagKind, Args: []string{"tag1", "tag2"}, LineNo: 2},23 {Kind: gauge.ScenarioKind, Value: "Scenario Heading", LineNo: 3},24 {Kind: gauge.StepKind, Value: "my step"},25 }26 spec, result, err := new(SpecParser).CreateSpecification(tokens, gauge.NewConceptDictionary(), "")27 c.Assert(err, IsNil)28 c.Assert(result.Ok, Equals, true)29 c.Assert(len(spec.Tags.Values()), Equals, 2)30 c.Assert(spec.Tags.Values()[0], Equals, "tag1")31 c.Assert(spec.Tags.Values()[1], Equals, "tag2")32}33func (s *MySuite) TestToCheckTagsInScenarioLevel(c *C) {34 tokens := []*Token{35 {Kind: gauge.SpecKind, Value: "Spec Heading", LineNo: 1},36 {Kind: gauge.ScenarioKind, Value: "Scenario Heading", LineNo: 2},37 {Kind: gauge.TagKind, Args: []string{"tag1", "tag2"}, LineNo: 3},38 {Kind: gauge.StepKind, Value: "my step"},39 }40 spec, result, err := new(SpecParser).CreateSpecification(tokens, gauge.NewConceptDictionary(), "")41 c.Assert(err, IsNil)42 c.Assert(result.Ok, Equals, true)43 c.Assert(len(spec.Scenarios[0].Tags.Values()), Equals, 2)44 c.Assert(spec.Scenarios[0].Tags.Values()[0], Equals, "tag1")45 c.Assert(spec.Scenarios[0].Tags.Values()[1], Equals, "tag2")46}47func (s *MySuite) TestParsingConceptInSpec(c *C) {48 parser := new(SpecParser)49 specText := newSpecBuilder().specHeading("A spec heading").50 scenarioHeading("First flow").51 step("test concept step 1").52 step("another step").String()53 conceptDictionary := gauge.NewConceptDictionary()54 path, _ := filepath.Abs(filepath.Join("testdata", "concept.cpt"))55 _, _, err := AddConcepts([]string{path}, conceptDictionary)56 c.Assert(err, IsNil)57 tokens, errs := parser.GenerateTokens(specText, "")58 c.Assert(errs, IsNil)59 spec, parseResult, e := parser.CreateSpecification(tokens, conceptDictionary, "")60 c.Assert(e, IsNil)61 c.Assert(parseResult.Ok, Equals, true)62 firstStepInSpec := spec.Scenarios[0].Steps[0]63 secondStepInSpec := spec.Scenarios[0].Steps[1]64 c.Assert(firstStepInSpec.ConceptSteps[0].Parent, Equals, firstStepInSpec)65 c.Assert(firstStepInSpec.Parent, IsNil)66 c.Assert(secondStepInSpec.Parent, IsNil)67}68func (s *MySuite) TestTableInputFromInvalidFileAndDataTableNotInitialized(c *C) {69 parser := new(SpecParser)70 specText := newSpecBuilder().specHeading("Spec heading").text("table: inputinvalid.csv").text("comment").scenarioHeading("Sce heading").step("my step").String()71 _, parseRes, err := parser.Parse(specText, gauge.NewConceptDictionary(), "")72 c.Assert(err, IsNil)73 c.Assert(parseRes.ParseErrors[0].Message, Equals, "Could not resolve table. File inputinvalid.csv doesn't exist.")74 c.Assert(parseRes.Ok, Equals, false)75}76func (s *MySuite) TestTableInputFromFile(c *C) {77 parser := new(SpecParser)78 specText := newSpecBuilder().specHeading("Spec heading").text("Table: inputinvalid.csv").text("comment").scenarioHeading("Sce heading").step("my step").String()79 _, parseRes, err := parser.Parse(specText, gauge.NewConceptDictionary(), "")80 c.Assert(err, IsNil)81 c.Assert(parseRes.ParseErrors[0].Message, Equals, "Could not resolve table. File inputinvalid.csv doesn't exist.")82 c.Assert(parseRes.Ok, Equals, false)83}84func (s *MySuite) TestTableInputFromFileIfPathNotSpecified(c *C) {85 parser := new(SpecParser)86 specText := newSpecBuilder().specHeading("Spec heading").text("Table: ").scenarioHeading("Sce heading").step("my step").String()87 _, parseRes, err := parser.Parse(specText, gauge.NewConceptDictionary(), "")88 c.Assert(err, IsNil)89 c.Assert(parseRes.ParseErrors[0].Message, Equals, "Table location not specified")90 c.Assert(parseRes.Ok, Equals, false)91}92func (s *MySuite) TestToSplitTagNames(c *C) {93 allTags := splitAndTrimTags("tag1 , tag2, tag3")94 c.Assert(allTags[0], Equals, "tag1")95 c.Assert(allTags[1], Equals, "tag2")96 c.Assert(allTags[2], Equals, "tag3")97}98func (s *MySuite) TestThrowsErrorForMultipleSpecHeading(c *C) {99 tokens := []*Token{100 {Kind: gauge.SpecKind, Value: "Spec Heading", LineNo: 1},101 {Kind: gauge.ScenarioKind, Value: "Scenario Heading", LineNo: 2},102 {Kind: gauge.StepKind, Value: "Example step", LineNo: 3},103 {Kind: gauge.SpecKind, Value: "Another Heading", LineNo: 4},104 }105 _, result, err := new(SpecParser).CreateSpecification(tokens, gauge.NewConceptDictionary(), "")106 c.Assert(err, IsNil)107 c.Assert(result.Ok, Equals, false)108 c.Assert(result.ParseErrors[0].Message, Equals, "Multiple spec headings found in same file")109 c.Assert(result.ParseErrors[0].LineNo, Equals, 4)110}111func (s *MySuite) TestThrowsErrorForScenarioWithoutSpecHeading(c *C) {112 tokens := []*Token{113 {Kind: gauge.ScenarioKind, Value: "Scenario Heading", LineNo: 1},114 {Kind: gauge.StepKind, Value: "Example step", LineNo: 2},115 {Kind: gauge.CommentKind, Value: "Comment", LineNo: 3},116 }117 _, result, err := new(SpecParser).CreateSpecification(tokens, gauge.NewConceptDictionary(), "")118 c.Assert(err, IsNil)119 c.Assert(result.Ok, Equals, false)120 c.Assert(len(result.ParseErrors), Equals, 2)121 c.Assert(result.ParseErrors[0].Message, Equals, "Spec heading not found")122 c.Assert(result.ParseErrors[0].LineNo, Equals, 1)123 c.Assert(result.ParseErrors[1].Message, Equals, "Scenario should be defined after the spec heading")124 c.Assert(result.ParseErrors[1].LineNo, Equals, 1)125}126func (s *MySuite) TestThrowsErrorForDuplicateScenariosWithinTheSameSpec(c *C) {127 tokens := []*Token{128 {Kind: gauge.SpecKind, Value: "Spec Heading", LineNo: 1},129 {Kind: gauge.ScenarioKind, Value: "Scenario Heading", LineNo: 2},130 {Kind: gauge.StepKind, Value: "Example step", LineNo: 3},131 {Kind: gauge.ScenarioKind, Value: "Scenario Heading", LineNo: 4},132 }133 _, result, err := new(SpecParser).CreateSpecification(tokens, gauge.NewConceptDictionary(), "")134 c.Assert(err, IsNil)135 c.Assert(result.Ok, Equals, false)136 c.Assert(result.ParseErrors[0].Message, Equals, "Duplicate scenario definition 'Scenario Heading' found in the same specification")137 c.Assert(result.ParseErrors[0].LineNo, Equals, 4)138}139func (s *MySuite) TestSpecWithHeadingAndSimpleSteps(c *C) {140 tokens := []*Token{141 {Kind: gauge.SpecKind, Value: "Spec Heading", LineNo: 1},142 {Kind: gauge.ScenarioKind, Value: "Scenario Heading", LineNo: 2},143 {Kind: gauge.StepKind, Value: "Example step", LineNo: 3},144 }145 spec, result, err := new(SpecParser).CreateSpecification(tokens, gauge.NewConceptDictionary(), "")146 c.Assert(err, IsNil)147 c.Assert(len(spec.Items), Equals, 1)148 c.Assert(spec.Items[0], Equals, spec.Scenarios[0])149 scenarioItems := (spec.Items[0]).(*gauge.Scenario).Items150 c.Assert(scenarioItems[0], Equals, spec.Scenarios[0].Steps[0])151 c.Assert(result.Ok, Equals, true)152 c.Assert(spec.Heading.LineNo, Equals, 1)153 c.Assert(spec.Heading.Value, Equals, "Spec Heading")154 c.Assert(len(spec.Scenarios), Equals, 1)155 c.Assert(spec.Scenarios[0].Heading.LineNo, Equals, 2)156 c.Assert(spec.Scenarios[0].Heading.Value, Equals, "Scenario Heading")157 c.Assert(len(spec.Scenarios[0].Steps), Equals, 1)158 c.Assert(spec.Scenarios[0].Steps[0].Value, Equals, "Example step")159}160func (s *MySuite) TestStepsAndComments(c *C) {161 tokens := []*Token{162 {Kind: gauge.SpecKind, Value: "Spec Heading", LineNo: 1},163 {Kind: gauge.CommentKind, Value: "A comment with some text and **bold** characters", LineNo: 2},164 {Kind: gauge.ScenarioKind, Value: "Scenario Heading", LineNo: 3},165 {Kind: gauge.CommentKind, Value: "Another comment", LineNo: 4},166 {Kind: gauge.StepKind, Value: "Example step", LineNo: 5},167 {Kind: gauge.CommentKind, Value: "Third comment", LineNo: 6},168 }169 spec, result, err := new(SpecParser).CreateSpecification(tokens, gauge.NewConceptDictionary(), "")170 c.Assert(err, IsNil)171 c.Assert(len(spec.Items), Equals, 2)172 c.Assert(spec.Items[0], Equals, spec.Comments[0])173 c.Assert(spec.Items[1], Equals, spec.Scenarios[0])174 scenarioItems := (spec.Items[1]).(*gauge.Scenario).Items175 c.Assert(3, Equals, len(scenarioItems))176 c.Assert(scenarioItems[0], Equals, spec.Scenarios[0].Comments[0])177 c.Assert(scenarioItems[1], Equals, spec.Scenarios[0].Steps[0])178 c.Assert(scenarioItems[2], Equals, spec.Scenarios[0].Comments[1])179 c.Assert(result.Ok, Equals, true)180 c.Assert(spec.Heading.Value, Equals, "Spec Heading")181 c.Assert(len(spec.Comments), Equals, 1)182 c.Assert(spec.Comments[0].LineNo, Equals, 2)183 c.Assert(spec.Comments[0].Value, Equals, "A comment with some text and **bold** characters")184 c.Assert(len(spec.Scenarios), Equals, 1)185 scenario := spec.Scenarios[0]186 c.Assert(2, Equals, len(scenario.Comments))187 c.Assert(scenario.Comments[0].LineNo, Equals, 4)188 c.Assert(scenario.Comments[0].Value, Equals, "Another comment")189 c.Assert(scenario.Comments[1].LineNo, Equals, 6)190 c.Assert(scenario.Comments[1].Value, Equals, "Third comment")191 c.Assert(scenario.Heading.Value, Equals, "Scenario Heading")192 c.Assert(len(scenario.Steps), Equals, 1)193}194func (s *MySuite) TestTableFromInvalidFile(c *C) {195 parser := new(SpecParser)196 specText := newSpecBuilder().specHeading("Spec heading").text("table: inputinvalid.csv").text("comment").scenarioHeading("Sce heading").step("my step").String()197 tokens, _ := parser.GenerateTokens(specText, "")198 _, res, err := parser.CreateSpecification(tokens, gauge.NewConceptDictionary(), "")199 c.Assert(err, IsNil)200 c.Assert(len(res.ParseErrors) > 0, Equals, true)201 c.Assert(res.ParseErrors[0].Message, Equals, "Could not resolve table. File inputinvalid.csv doesn't exist.")202}203func (s *MySuite) TestStepsWithParam(c *C) {204 tokens := []*Token{205 {Kind: gauge.SpecKind, Value: "Spec Heading", LineNo: 1},206 {Kind: gauge.TableHeader, Args: []string{"id"}, LineNo: 2},207 {Kind: gauge.TableRow, Args: []string{"1"}, LineNo: 3},208 {Kind: gauge.ScenarioKind, Value: "Scenario Heading", LineNo: 4},209 {Kind: gauge.StepKind, Value: "enter {static} with {dynamic}", LineNo: 5, Args: []string{"user \\n foo", "id"}},210 {Kind: gauge.StepKind, Value: "sample \\{static\\}", LineNo: 6},211 }212 spec, result, err := new(SpecParser).CreateSpecification(tokens, gauge.NewConceptDictionary(), "")213 c.Assert(err, IsNil)214 c.Assert(result.Ok, Equals, true)215 step := spec.Scenarios[0].Steps[0]216 c.Assert(step.Value, Equals, "enter {} with {}")217 c.Assert(step.LineNo, Equals, 5)218 c.Assert(len(step.Args), Equals, 2)219 c.Assert(step.Args[0].Value, Equals, "user \\n foo")220 c.Assert(step.Args[0].ArgType, Equals, gauge.Static)221 c.Assert(step.Args[1].Value, Equals, "id")222 c.Assert(step.Args[1].ArgType, Equals, gauge.Dynamic)223 c.Assert(step.Args[1].Name, Equals, "id")224 escapedStep := spec.Scenarios[0].Steps[1]225 c.Assert(escapedStep.Value, Equals, "sample \\{static\\}")226 c.Assert(len(escapedStep.Args), Equals, 0)227}228func (s *MySuite) TestStepsWithKeywords(c *C) {229 tokens := []*Token{230 {Kind: gauge.SpecKind, Value: "Spec Heading", LineNo: 1},231 {Kind: gauge.ScenarioKind, Value: "Scenario Heading", LineNo: 2},232 {Kind: gauge.StepKind, Value: "sample {static} and {dynamic}", LineNo: 3, Args: []string{"name"}},233 }234 _, result, err := new(SpecParser).CreateSpecification(tokens, gauge.NewConceptDictionary(), "")235 c.Assert(err, IsNil)236 c.Assert(result, NotNil)237 c.Assert(result.Ok, Equals, false)238 c.Assert(result.ParseErrors[0].Message, Equals, "Scenario should have atleast one step")239 c.Assert(result.ParseErrors[0].LineNo, Equals, 2)240 c.Assert(result.ParseErrors[1].Message, Equals, "Step text should not have '{static}' or '{dynamic}' or '{special}'")241 c.Assert(result.ParseErrors[1].LineNo, Equals, 3)242}243func (s *MySuite) TestContextWithKeywords(c *C) {244 tokens := []*Token{245 {Kind: gauge.SpecKind, Value: "Spec Heading", LineNo: 1},246 {Kind: gauge.StepKind, Value: "sample {static} and {dynamic}", LineNo: 3, Args: []string{"name"}},247 {Kind: gauge.ScenarioKind, Value: "Scenario Heading", LineNo: 2},248 {Kind: gauge.StepKind, Value: "Step"},249 }250 _, result, err := new(SpecParser).CreateSpecification(tokens, gauge.NewConceptDictionary(), "")251 c.Assert(err, IsNil)252 c.Assert(result, NotNil)253 c.Assert(result.Ok, Equals, false)254 c.Assert(result.ParseErrors[0].Message, Equals, "Step text should not have '{static}' or '{dynamic}' or '{special}'")255 c.Assert(result.ParseErrors[0].LineNo, Equals, 3)256}257func (s *MySuite) TestSpecWithDataTable(c *C) {258 tokens := []*Token{259 {Kind: gauge.SpecKind, Value: "Spec Heading"},260 {Kind: gauge.CommentKind, Value: "Comment before data table"},261 {Kind: gauge.TableHeader, Args: []string{"id", "name"}},262 {Kind: gauge.TableRow, Args: []string{"1", "foo"}},263 {Kind: gauge.TableRow, Args: []string{"2", "bar"}},264 {Kind: gauge.CommentKind, Value: "Comment before data table"},265 {Kind: gauge.ScenarioKind, Value: "Scenario heading"},266 {Kind: gauge.StepKind, Value: "my step"},267 }268 spec, result, err := new(SpecParser).CreateSpecification(tokens, gauge.NewConceptDictionary(), "")269 c.Assert(err, IsNil)270 c.Assert(len(spec.Items), Equals, 4)271 c.Assert(spec.Items[0], Equals, spec.Comments[0])272 c.Assert(spec.Items[1], DeepEquals, &spec.DataTable)273 c.Assert(spec.Items[2], Equals, spec.Comments[1])274 c.Assert(result.Ok, Equals, true)275 c.Assert(spec.DataTable, NotNil)276 idCells, _ := spec.DataTable.Table.Get("id")277 nameCells, _ := spec.DataTable.Table.Get("name")278 c.Assert(len(idCells), Equals, 2)279 c.Assert(len(nameCells), Equals, 2)280 c.Assert(idCells[0].Value, Equals, "1")281 c.Assert(idCells[0].CellType, Equals, gauge.Static)282 c.Assert(idCells[1].Value, Equals, "2")283 c.Assert(idCells[1].CellType, Equals, gauge.Static)284 c.Assert(nameCells[0].Value, Equals, "foo")285 c.Assert(nameCells[0].CellType, Equals, gauge.Static)286 c.Assert(nameCells[1].Value, Equals, "bar")287 c.Assert(nameCells[1].CellType, Equals, gauge.Static)288}289func TestScenarioWithDataTable(t *testing.T) {290 var subject = func() *gauge.Scenario {291 tokens := []*Token{292 {Kind: gauge.SpecKind, Value: "Spec Heading"},293 {Kind: gauge.CommentKind, Value: "Comment before data table"},294 {Kind: gauge.ScenarioKind, Value: "Scenario heading"},295 {Kind: gauge.CommentKind, Value: "Comment before data table"},296 {Kind: gauge.TableHeader, Args: []string{"id", "name"}},297 {Kind: gauge.TableRow, Args: []string{"1", "foo"}},298 {Kind: gauge.TableRow, Args: []string{"2", "bar"}},299 {Kind: gauge.StepKind, Value: "my step"},300 }301 spec, result, err := new(SpecParser).CreateSpecification(tokens, gauge.NewConceptDictionary(), "")302 if err != nil {303 t.Error(err)304 }305 v := len(spec.Items)306 if v != 2 {307 t.Errorf("expected spec to have 2 items. got %d", v)308 }309 if !result.Ok {310 t.Errorf("parse failed, err %s", strings.Join(result.Errors(), ","))311 }312 return spec.Scenarios[0]313 }314 t.Run("Scenario with datatable when AllowScenarioDatatable=True", func(t *testing.T) {315 env.AllowScenarioDatatable = func() bool { return true }316 s := subject()317 if s.DataTable.Table == nil {318 t.Error("expected scenario datatable to be not nil")319 }320 v := len(s.Items)321 if v != 3 {322 t.Errorf("expected scenario to have 3 items, got %d", v)323 }324 idCells, _ := s.DataTable.Table.Get("id")325 nameCells, _ := s.DataTable.Table.Get("name")326 var assertEqual = func(e, a interface{}) {327 if e != a {328 t.Errorf("expected %v got %v", e, a)329 }330 }331 assertEqual(len(idCells), 2)332 assertEqual(len(nameCells), 2)333 assertEqual(idCells[0].Value, "1")334 assertEqual(idCells[0].CellType, gauge.Static)335 assertEqual(idCells[1].Value, "2")336 assertEqual(idCells[1].CellType, gauge.Static)337 assertEqual(nameCells[0].Value, "foo")338 assertEqual(nameCells[0].CellType, gauge.Static)339 assertEqual(nameCells[1].Value, "bar")340 assertEqual(nameCells[1].CellType, gauge.Static)341 })342 t.Run("Parse Scenario with datatable when AllowScenarioDatatable=False", func(t *testing.T) {343 env.AllowScenarioDatatable = func() bool { return false }344 s := subject()345 if s.DataTable.Table.IsInitialized() {346 t.Error("expected scenario to have no datatable, got one")347 }348 })349}350func (s *MySuite) TestSpecWithDataTableHavingEmptyRowAndNoSeparator(c *C) {351 tokens := []*Token{352 {Kind: gauge.SpecKind, Value: "Spec Heading"},353 {Kind: gauge.CommentKind, Value: "Comment before data table"},354 {Kind: gauge.TableHeader, Args: []string{"id", "name"}},355 {Kind: gauge.TableRow, Args: []string{"1", "foo"}},356 {Kind: gauge.TableRow, Args: []string{"", ""}},357 {Kind: gauge.TableRow, Args: []string{"2", "bar"}},358 {Kind: gauge.CommentKind, Value: "Comment before data table"},359 {Kind: gauge.ScenarioKind, Value: "Scenario heading"},360 {Kind: gauge.StepKind, Value: "my step"},361 }362 spec, result, err := new(SpecParser).CreateSpecification(tokens, gauge.NewConceptDictionary(), "")363 c.Assert(err, IsNil)364 c.Assert(len(spec.Items), Equals, 4)365 c.Assert(spec.Items[0], Equals, spec.Comments[0])366 c.Assert(spec.Items[1], DeepEquals, &spec.DataTable)367 c.Assert(spec.Items[2], Equals, spec.Comments[1])368 c.Assert(result.Ok, Equals, true)369 c.Assert(spec.DataTable, NotNil)370 c.Assert(spec.DataTable.Table.GetRowCount(), Equals, 3)371 idCells, _ := spec.DataTable.Table.Get("id")372 nameCells, _ := spec.DataTable.Table.Get("name")373 c.Assert(len(idCells), Equals, 3)374 c.Assert(len(nameCells), Equals, 3)375 c.Assert(idCells[0].Value, Equals, "1")376 c.Assert(idCells[0].CellType, Equals, gauge.Static)377 c.Assert(idCells[1].Value, Equals, "")378 c.Assert(idCells[1].CellType, Equals, gauge.Static)379 c.Assert(idCells[2].Value, Equals, "2")380 c.Assert(idCells[2].CellType, Equals, gauge.Static)381 c.Assert(nameCells[0].Value, Equals, "foo")382 c.Assert(nameCells[0].CellType, Equals, gauge.Static)383 c.Assert(nameCells[1].Value, Equals, "")384 c.Assert(nameCells[1].CellType, Equals, gauge.Static)385 c.Assert(nameCells[2].Value, Equals, "bar")386 c.Assert(nameCells[2].CellType, Equals, gauge.Static)387}388func (s *MySuite) TestSpecWithStepUsingInlineTableWhichUsagesDynamicParamFromScenarioDataTable(c *C) {389 env.AllowScenarioDatatable = func() bool { return true }390 specText := `# Specification heading391## Scenario Heading392 |name |393 |-------|394 |someone|395* step with396 |id |397 |------|398 |<name>|399`400 _, _, err := new(SpecParser).Parse(specText, gauge.NewConceptDictionary(), "foo.spec")401 c.Assert(err, IsNil)402}403func (s *MySuite) TestStepWithInlineTable(c *C) {404 tokens := []*Token{405 {Kind: gauge.SpecKind, Value: "Spec Heading", LineNo: 1},406 {Kind: gauge.ScenarioKind, Value: "Scenario Heading", LineNo: 2},407 {Kind: gauge.StepKind, Value: "Step with inline table", LineNo: 3},408 {Kind: gauge.TableHeader, Args: []string{"id", "name"}},409 {Kind: gauge.TableRow, Args: []string{"1", "foo"}},410 {Kind: gauge.TableRow, Args: []string{"2", "bar"}},411 }412 spec, result, err := new(SpecParser).CreateSpecification(tokens, gauge.NewConceptDictionary(), "")413 c.Assert(err, IsNil)414 c.Assert(result.Ok, Equals, true)415 step := spec.Scenarios[0].Steps[0]416 c.Assert(step.Args[0].ArgType, Equals, gauge.TableArg)417 inlineTable := step.Args[0].Table418 c.Assert(inlineTable, NotNil)419 c.Assert(step.Value, Equals, "Step with inline table {}")420 c.Assert(step.HasInlineTable, Equals, true)421 idCells, _ := inlineTable.Get("id")422 nameCells, _ := inlineTable.Get("name")423 c.Assert(len(idCells), Equals, 2)424 c.Assert(len(nameCells), Equals, 2)425 c.Assert(idCells[0].Value, Equals, "1")426 c.Assert(idCells[0].CellType, Equals, gauge.Static)427 c.Assert(idCells[1].Value, Equals, "2")428 c.Assert(idCells[1].CellType, Equals, gauge.Static)429 c.Assert(nameCells[0].Value, Equals, "foo")430 c.Assert(nameCells[0].CellType, Equals, gauge.Static)431 c.Assert(nameCells[1].Value, Equals, "bar")432 c.Assert(nameCells[1].CellType, Equals, gauge.Static)433}434func (s *MySuite) TestStepWithInlineTableWithDynamicParam(c *C) {435 tokens := []*Token{436 {Kind: gauge.SpecKind, Value: "Spec Heading", LineNo: 1},437 {Kind: gauge.TableHeader, Args: []string{"type1", "type2"}},438 {Kind: gauge.TableRow, Args: []string{"1", "2"}},439 {Kind: gauge.ScenarioKind, Value: "Scenario Heading", LineNo: 2},440 {Kind: gauge.StepKind, Value: "Step with inline table", LineNo: 3},441 {Kind: gauge.TableHeader, Args: []string{"id", "name"}},442 {Kind: gauge.TableRow, Args: []string{"1", "<type1>"}},443 {Kind: gauge.TableRow, Args: []string{"2", "<type2>"}},444 {Kind: gauge.TableRow, Args: []string{"<2>", "<type3>"}},445 }446 spec, result, err := new(SpecParser).CreateSpecification(tokens, gauge.NewConceptDictionary(), "")447 c.Assert(err, IsNil)448 c.Assert(result.Ok, Equals, true)449 step := spec.Scenarios[0].Steps[0]450 c.Assert(step.Args[0].ArgType, Equals, gauge.TableArg)451 inlineTable := step.Args[0].Table452 c.Assert(inlineTable, NotNil)453 c.Assert(step.Value, Equals, "Step with inline table {}")454 idCells, _ := inlineTable.Get("id")455 nameCells, _ := inlineTable.Get("name")456 c.Assert(len(idCells), Equals, 3)457 c.Assert(len(nameCells), Equals, 3)458 c.Assert(idCells[0].Value, Equals, "1")459 c.Assert(idCells[0].CellType, Equals, gauge.Static)460 c.Assert(idCells[1].Value, Equals, "2")461 c.Assert(idCells[1].CellType, Equals, gauge.Static)462 c.Assert(idCells[2].Value, Equals, "<2>")463 c.Assert(idCells[2].CellType, Equals, gauge.Static)464 c.Assert(nameCells[0].Value, Equals, "type1")465 c.Assert(nameCells[0].CellType, Equals, gauge.Dynamic)466 c.Assert(nameCells[1].Value, Equals, "type2")467 c.Assert(nameCells[1].CellType, Equals, gauge.Dynamic)468 c.Assert(nameCells[2].Value, Equals, "<type3>")469 c.Assert(nameCells[2].CellType, Equals, gauge.Static)470}471func (s *MySuite) TestStepWithInlineTableWithUnResolvableDynamicParam(c *C) {472 tokens := []*Token{473 {Kind: gauge.SpecKind, Value: "Spec Heading", LineNo: 1},474 {Kind: gauge.TableHeader, Args: []string{"type1", "type2"}},475 {Kind: gauge.TableRow, Args: []string{"1", "2"}},476 {Kind: gauge.ScenarioKind, Value: "Scenario Heading", LineNo: 2},477 {Kind: gauge.StepKind, Value: "Step with inline table", LineNo: 3},478 {Kind: gauge.TableHeader, Args: []string{"id", "name"}},479 {Kind: gauge.TableRow, Args: []string{"1", "<invalid>"}},480 {Kind: gauge.TableRow, Args: []string{"2", "<type2>"}},481 }482 spec, result, err := new(SpecParser).CreateSpecification(tokens, gauge.NewConceptDictionary(), "")483 c.Assert(err, IsNil)484 c.Assert(result.Ok, Equals, true)485 idCells, _ := spec.Scenarios[0].Steps[0].Args[0].Table.Get("id")486 c.Assert(idCells[0].Value, Equals, "1")487 nameCells, _ := spec.Scenarios[0].Steps[0].Args[0].Table.Get("name")488 c.Assert(nameCells[0].Value, Equals, "<invalid>")489 c.Assert(result.Warnings[0].Message, Equals, "Dynamic param <invalid> could not be resolved, Treating it as static param")490}491func (s *MySuite) TestContextWithInlineTable(c *C) {492 tokens := []*Token{493 {Kind: gauge.SpecKind, Value: "Spec Heading"},494 {Kind: gauge.StepKind, Value: "Context with inline table"},495 {Kind: gauge.TableHeader, Args: []string{"id", "name"}},496 {Kind: gauge.TableRow, Args: []string{"1", "foo"}},497 {Kind: gauge.TableRow, Args: []string{"2", "bar"}},498 {Kind: gauge.TableRow, Args: []string{"3", "not a <dynamic>"}},499 {Kind: gauge.ScenarioKind, Value: "Scenario Heading"},500 {Kind: gauge.StepKind, Value: "Step"},501 }502 spec, result, err := new(SpecParser).CreateSpecification(tokens, gauge.NewConceptDictionary(), "")503 c.Assert(err, IsNil)504 c.Assert(len(spec.Items), Equals, 2)505 c.Assert(spec.Items[0], DeepEquals, spec.Contexts[0])506 c.Assert(spec.Items[1], Equals, spec.Scenarios[0])507 c.Assert(result.Ok, Equals, true)508 context := spec.Contexts[0]509 c.Assert(context.Args[0].ArgType, Equals, gauge.TableArg)510 inlineTable := context.Args[0].Table511 c.Assert(inlineTable, NotNil)512 c.Assert(context.Value, Equals, "Context with inline table {}")513 idCells, _ := inlineTable.Get("id")514 nameCells, _ := inlineTable.Get("name")515 c.Assert(len(idCells), Equals, 3)516 c.Assert(len(nameCells), Equals, 3)517 c.Assert(idCells[0].Value, Equals, "1")518 c.Assert(idCells[0].CellType, Equals, gauge.Static)519 c.Assert(idCells[1].Value, Equals, "2")520 c.Assert(idCells[1].CellType, Equals, gauge.Static)521 c.Assert(idCells[2].Value, Equals, "3")522 c.Assert(idCells[2].CellType, Equals, gauge.Static)523 c.Assert(nameCells[0].Value, Equals, "foo")524 c.Assert(nameCells[0].CellType, Equals, gauge.Static)525 c.Assert(nameCells[1].Value, Equals, "bar")526 c.Assert(nameCells[1].CellType, Equals, gauge.Static)527 c.Assert(nameCells[2].Value, Equals, "not a <dynamic>")528 c.Assert(nameCells[2].CellType, Equals, gauge.Static)529}530func (s *MySuite) TestErrorWhenDataTableHasOnlyHeader(c *C) {531 tokens := []*Token{532 {Kind: gauge.SpecKind, Value: "Spec Heading"},533 {Kind: gauge.TableHeader, Args: []string{"id", "name"}, LineNo: 3},534 {Kind: gauge.ScenarioKind, Value: "Scenario Heading"},535 }536 _, result, err := new(SpecParser).CreateSpecification(tokens, gauge.NewConceptDictionary(), "")537 c.Assert(err, IsNil)538 c.Assert(result.Ok, Equals, false)539 c.Assert(result.ParseErrors[0].Message, Equals, "Data table should have at least 1 data row")540 c.Assert(result.ParseErrors[0].LineNo, Equals, 3)541}542func (s *MySuite) TestWarningWhenParsingMultipleDataTable(c *C) {543 tokens := []*Token{544 {Kind: gauge.SpecKind, Value: "Spec Heading"},545 {Kind: gauge.CommentKind, Value: "Comment before data table"},546 {Kind: gauge.TableHeader, Args: []string{"id", "name"}},547 {Kind: gauge.TableRow, Args: []string{"1", "foo"}},548 {Kind: gauge.TableRow, Args: []string{"2", "bar"}},549 {Kind: gauge.CommentKind, Value: "Comment before data table"},550 {Kind: gauge.TableHeader, Args: []string{"phone"}, LineNo: 7},551 {Kind: gauge.TableRow, Args: []string{"1"}},552 {Kind: gauge.TableRow, Args: []string{"2"}},553 {Kind: gauge.ScenarioKind, Value: "Scenario heading"},554 {Kind: gauge.StepKind, Value: "my step"},555 }556 _, result, err := new(SpecParser).CreateSpecification(tokens, gauge.NewConceptDictionary(), "foo.spec")557 c.Assert(err, IsNil)558 c.Assert(result.Ok, Equals, true)559 c.Assert(len(result.Warnings), Equals, 1)560 c.Assert(result.Warnings[0].String(), Equals, "foo.spec:7 Multiple data table present, ignoring table")561}562func (s *MySuite) TestParseErrorWhenCouldNotResolveExternalDataTable(c *C) {563 tokens := []*Token{564 {Kind: gauge.SpecKind, Value: "Spec Heading", LineNo: 1},565 {Kind: gauge.CommentKind, Value: "Comment before data table", LineNo: 2},566 {Kind: gauge.DataTableKind, Value: "table: foo", LineNo: 3, Lines: []string{"table: foo"}},567 {Kind: gauge.ScenarioKind, Value: "Scenario Heading", LineNo: 4},568 {Kind: gauge.StepKind, Value: "Step", LineNo: 5},569 }570 _, result, err := new(SpecParser).CreateSpecification(tokens, gauge.NewConceptDictionary(), "foo.spec")571 c.Assert(err, IsNil)572 c.Assert(result.Ok, Equals, false)573 c.Assert(len(result.Warnings), Equals, 0)574 c.Assert(result.Errors()[0], Equals, "[ParseError] foo.spec:3 Could not resolve table. File foo doesn't exist. => 'table: foo'")575}576func (s *MySuite) TestAddSpecTags(c *C) {577 tokens := []*Token{578 {Kind: gauge.SpecKind, Value: "Spec Heading", LineNo: 1},579 {Kind: gauge.TagKind, Args: []string{"tag1", "tag2"}, LineNo: 2},580 {Kind: gauge.ScenarioKind, Value: "Scenario Heading", LineNo: 3},581 {Kind: gauge.StepKind, Value: "Step"},582 }583 spec, result, err := new(SpecParser).CreateSpecification(tokens, gauge.NewConceptDictionary(), "")584 c.Assert(err, IsNil)585 c.Assert(result.Ok, Equals, true)586 c.Assert(len(spec.Tags.Values()), Equals, 2)587 c.Assert(spec.Tags.Values()[0], Equals, "tag1")588 c.Assert(spec.Tags.Values()[1], Equals, "tag2")589}590func (s *MySuite) TestAddSpecTagsAndScenarioTags(c *C) {591 tokens := []*Token{592 {Kind: gauge.SpecKind, Value: "Spec Heading", LineNo: 1},593 {Kind: gauge.TagKind, Args: []string{"tag1", "tag2"}, LineNo: 2},594 {Kind: gauge.ScenarioKind, Value: "Scenario Heading", LineNo: 3},595 {Kind: gauge.TagKind, Args: []string{"tag3", "tag4"}, LineNo: 2},596 {Kind: gauge.StepKind, Value: "Step"},597 }598 spec, result, err := new(SpecParser).CreateSpecification(tokens, gauge.NewConceptDictionary(), "")599 c.Assert(err, IsNil)600 c.Assert(result.Ok, Equals, true)601 c.Assert(len(spec.Tags.Values()), Equals, 2)602 c.Assert(spec.Tags.Values()[0], Equals, "tag1")603 c.Assert(spec.Tags.Values()[1], Equals, "tag2")604 tags := spec.Scenarios[0].Tags605 c.Assert(len(tags.Values()), Equals, 2)606 c.Assert(tags.Values()[0], Equals, "tag3")607 c.Assert(tags.Values()[1], Equals, "tag4")608}609func (s *MySuite) TestErrorOnAddingDynamicParamterWithoutADataTable(c *C) {610 tokens := []*Token{611 {Kind: gauge.SpecKind, Value: "Spec Heading", LineNo: 1},612 {Kind: gauge.ScenarioKind, Value: "Scenario Heading", LineNo: 2},613 {Kind: gauge.StepKind, Value: "Step with a {dynamic}", Args: []string{"foo"}, LineNo: 3, Lines: []string{"*Step with a <foo>"}},614 {Kind: gauge.StepKind, Value: "Step"},615 }616 _, result, err := new(SpecParser).CreateSpecification(tokens, gauge.NewConceptDictionary(), "")617 c.Assert(err, IsNil)618 c.Assert(result.Ok, Equals, false)619 c.Assert(result.ParseErrors[0].Message, Equals, "Dynamic parameter <foo> could not be resolved")620 c.Assert(result.ParseErrors[0].LineNo, Equals, 3)621}622func (s *MySuite) TestErrorOnAddingDynamicParamterWithoutDataTableHeaderValue(c *C) {623 tokens := []*Token{624 {Kind: gauge.SpecKind, Value: "Spec Heading", LineNo: 1},625 {Kind: gauge.TableHeader, Args: []string{"id, name"}, LineNo: 2},626 {Kind: gauge.TableRow, Args: []string{"123, hello"}, LineNo: 3},627 {Kind: gauge.ScenarioKind, Value: "Scenario Heading", LineNo: 4},628 {Kind: gauge.StepKind, Value: "Step with a {dynamic}", Args: []string{"foo"}, LineNo: 5, Lines: []string{"*Step with a <foo>"}},629 {Kind: gauge.StepKind, Value: "Step"},630 }631 _, result, err := new(SpecParser).CreateSpecification(tokens, gauge.NewConceptDictionary(), "")632 c.Assert(err, IsNil)633 c.Assert(result.Ok, Equals, false)634 c.Assert(result.ParseErrors[0].Message, Equals, "Dynamic parameter <foo> could not be resolved")635 c.Assert(result.ParseErrors[0].LineNo, Equals, 5)636}637func (s *MySuite) TestResolveScenarioDataTableAsDynamicParams(c *C) {638 env.AllowScenarioDatatable = func() bool { return true }639 tokens := []*Token{640 {Kind: gauge.SpecKind, Value: "Spec Heading", LineNo: 1},641 {Kind: gauge.ScenarioKind, Value: "Scenario Heading", LineNo: 4},642 {Kind: gauge.TableHeader, Args: []string{"id", "name"}, LineNo: 2},643 {Kind: gauge.TableRow, Args: []string{"123", "hello"}, LineNo: 3},644 {Kind: gauge.StepKind, Value: "Step with a {dynamic}", Args: []string{"id"}, LineNo: 5, Lines: []string{"*Step with a <id>"}},645 {Kind: gauge.StepKind, Value: "Step"},646 }647 _, result, err := new(SpecParser).CreateSpecification(tokens, gauge.NewConceptDictionary(), "")648 c.Assert(err, IsNil)649 c.Assert(result.Ok, Equals, true)650}651func (s *MySuite) TestCreateStepFromSimpleConcept(c *C) {652 tokens := []*Token{653 {Kind: gauge.SpecKind, Value: "Spec Heading", LineNo: 1},654 {Kind: gauge.ScenarioKind, Value: "Scenario Heading", LineNo: 2},655 {Kind: gauge.StepKind, Value: "test concept step 1", LineNo: 3},656 }657 conceptDictionary := gauge.NewConceptDictionary()658 path, _ := filepath.Abs(filepath.Join("testdata", "concept.cpt"))659 _, _, err := AddConcepts([]string{path}, conceptDictionary)660 c.Assert(err, IsNil)661 spec, result, err := new(SpecParser).CreateSpecification(tokens, conceptDictionary, "")662 c.Assert(err, IsNil)663 c.Assert(result.Ok, Equals, true)664 c.Assert(len(spec.Scenarios[0].Steps), Equals, 1)665 specConceptStep := spec.Scenarios[0].Steps[0]666 c.Assert(specConceptStep.IsConcept, Equals, true)667 assertStepEqual(c, &gauge.Step{LineNo: 2, Value: "step 1", LineText: "step 1"}, specConceptStep.ConceptSteps[0])668}669func (s *MySuite) TestCreateStepFromConceptWithParameters(c *C) {670 tokens := []*Token{671 {Kind: gauge.SpecKind, Value: "Spec Heading", LineNo: 1},672 {Kind: gauge.ScenarioKind, Value: "Scenario Heading", LineNo: 2},673 {Kind: gauge.StepKind, Value: "assign id {static} and name {static}", Args: []string{"foo", "foo1"}, LineNo: 3},674 {Kind: gauge.StepKind, Value: "assign id {static} and name {static}", Args: []string{"bar", "bar1"}, LineNo: 4},675 }676 conceptDictionary := gauge.NewConceptDictionary()677 path, _ := filepath.Abs(filepath.Join("testdata", "dynamic_param_concept.cpt"))678 _, _, err := AddConcepts([]string{path}, conceptDictionary)679 c.Assert(err, IsNil)680 spec, result, err := new(SpecParser).CreateSpecification(tokens, conceptDictionary, "")681 c.Assert(err, IsNil)682 c.Assert(result.Ok, Equals, true)683 c.Assert(len(spec.Scenarios[0].Steps), Equals, 2)684 firstConceptStep := spec.Scenarios[0].Steps[0]685 c.Assert(firstConceptStep.IsConcept, Equals, true)686 c.Assert(firstConceptStep.ConceptSteps[0].Value, Equals, "add id {}")687 c.Assert(firstConceptStep.ConceptSteps[0].Args[0].Value, Equals, "userid")688 c.Assert(firstConceptStep.ConceptSteps[1].Value, Equals, "add name {}")689 c.Assert(firstConceptStep.ConceptSteps[1].Args[0].Value, Equals, "username")690 usernameArg, _ := firstConceptStep.GetArg("username")691 c.Assert(usernameArg.Value, Equals, "foo1")692 useridArg, _ := firstConceptStep.GetArg("userid")693 c.Assert(useridArg.Value, Equals, "foo")694 secondConceptStep := spec.Scenarios[0].Steps[1]695 c.Assert(secondConceptStep.IsConcept, Equals, true)696 c.Assert(secondConceptStep.ConceptSteps[0].Value, Equals, "add id {}")697 c.Assert(secondConceptStep.ConceptSteps[0].Args[0].Value, Equals, "userid")698 c.Assert(secondConceptStep.ConceptSteps[1].Value, Equals, "add name {}")699 c.Assert(secondConceptStep.ConceptSteps[1].Args[0].Value, Equals, "username")700 usernameArg2, _ := secondConceptStep.GetArg("username")701 c.Assert(usernameArg2.Value, Equals, "bar1")702 useridArg2, _ := secondConceptStep.GetArg("userid")703 c.Assert(useridArg2.Value, Equals, "bar")704}705func (s *MySuite) TestCreateStepFromConceptWithDynamicParameters(c *C) {706 tokens := []*Token{707 {Kind: gauge.SpecKind, Value: "Spec Heading", LineNo: 1},708 {Kind: gauge.TableHeader, Args: []string{"id", "description"}, LineNo: 2},709 {Kind: gauge.TableRow, Args: []string{"123", "Admin fellow"}, LineNo: 3},710 {Kind: gauge.ScenarioKind, Value: "Scenario Heading", LineNo: 4},711 {Kind: gauge.StepKind, Value: "assign id {dynamic} and name {dynamic}", Args: []string{"id", "description"}, LineNo: 5},712 }713 conceptDictionary := gauge.NewConceptDictionary()714 path, _ := filepath.Abs(filepath.Join("testdata", "dynamic_param_concept.cpt"))715 _, _, err := AddConcepts([]string{path}, conceptDictionary)716 c.Assert(err, IsNil)717 spec, result, err := new(SpecParser).CreateSpecification(tokens, conceptDictionary, "")718 c.Assert(err, IsNil)719 c.Assert(result.Ok, Equals, true)720 c.Assert(len(spec.Items), Equals, 2)721 c.Assert(spec.Items[0], DeepEquals, &spec.DataTable)722 c.Assert(spec.Items[1], Equals, spec.Scenarios[0])723 scenarioItems := (spec.Items[1]).(*gauge.Scenario).Items724 c.Assert(scenarioItems[0], Equals, spec.Scenarios[0].Steps[0])725 c.Assert(len(spec.Scenarios[0].Steps), Equals, 1)726 firstConcept := spec.Scenarios[0].Steps[0]727 c.Assert(firstConcept.IsConcept, Equals, true)728 c.Assert(firstConcept.ConceptSteps[0].Value, Equals, "add id {}")729 c.Assert(firstConcept.ConceptSteps[0].Args[0].ArgType, Equals, gauge.Dynamic)730 c.Assert(firstConcept.ConceptSteps[0].Args[0].Value, Equals, "userid")731 c.Assert(firstConcept.ConceptSteps[1].Value, Equals, "add name {}")732 c.Assert(firstConcept.ConceptSteps[1].Args[0].Value, Equals, "username")733 c.Assert(firstConcept.ConceptSteps[1].Args[0].ArgType, Equals, gauge.Dynamic)734 arg1, _ := firstConcept.Lookup.GetArg("userid")735 c.Assert(arg1.Value, Equals, "id")736 c.Assert(arg1.ArgType, Equals, gauge.Dynamic)737 arg2, _ := firstConcept.Lookup.GetArg("username")738 c.Assert(arg2.Value, Equals, "description")739 c.Assert(arg2.ArgType, Equals, gauge.Dynamic)740}741func (s *MySuite) TestCreateStepFromConceptWithInlineTable(c *C) {742 tokens := []*Token{743 {Kind: gauge.SpecKind, Value: "Spec Heading", LineNo: 1},744 {Kind: gauge.ScenarioKind, Value: "Scenario Heading", LineNo: 4},745 {Kind: gauge.StepKind, Value: "assign id {static} and name", Args: []string{"sdf"}, LineNo: 3},746 {Kind: gauge.TableHeader, Args: []string{"id", "description"}, LineNo: 4},747 {Kind: gauge.TableRow, Args: []string{"123", "Admin"}, LineNo: 5},748 {Kind: gauge.TableRow, Args: []string{"456", "normal fellow"}, LineNo: 6},749 }750 conceptDictionary := gauge.NewConceptDictionary()751 path, _ := filepath.Abs(filepath.Join("testdata", "dynamic_param_concept.cpt"))752 _, _, err := AddConcepts([]string{path}, conceptDictionary)753 c.Assert(err, IsNil)754 spec, result, err := new(SpecParser).CreateSpecification(tokens, conceptDictionary, "")755 c.Assert(err, IsNil)756 c.Assert(result.Ok, Equals, true)757 steps := spec.Scenarios[0].Steps758 c.Assert(len(steps), Equals, 1)759 c.Assert(steps[0].IsConcept, Equals, true)760 c.Assert(steps[0].Value, Equals, "assign id {} and name {}")761 c.Assert(len(steps[0].Args), Equals, 2)762 c.Assert(steps[0].Args[1].ArgType, Equals, gauge.TableArg)763 c.Assert(len(steps[0].ConceptSteps), Equals, 2)764}765func (s *MySuite) TestCreateStepFromConceptWithInlineTableHavingDynamicParam(c *C) {766 tokens := []*Token{767 {Kind: gauge.SpecKind, Value: "Spec Heading", LineNo: 1},768 {Kind: gauge.TableHeader, Args: []string{"id", "description"}, LineNo: 2},769 {Kind: gauge.TableRow, Args: []string{"123", "Admin"}, LineNo: 3},770 {Kind: gauge.TableRow, Args: []string{"456", "normal fellow"}, LineNo: 4},771 {Kind: gauge.ScenarioKind, Value: "Scenario Heading", LineNo: 5},772 {Kind: gauge.StepKind, Value: "assign id {static} and name", Args: []string{"sdf"}, LineNo: 6},773 {Kind: gauge.TableHeader, Args: []string{"user-id", "description", "name"}, LineNo: 7},774 {Kind: gauge.TableRow, Args: []string{"<id>", "<description>", "root"}, LineNo: 8},775 }776 conceptDictionary := gauge.NewConceptDictionary()777 path, _ := filepath.Abs(filepath.Join("testdata", "dynamic_param_concept.cpt"))778 _, _, err := AddConcepts([]string{path}, conceptDictionary)779 c.Assert(err, IsNil)780 spec, result, err := new(SpecParser).CreateSpecification(tokens, conceptDictionary, "")781 c.Assert(err, IsNil)782 c.Assert(result.Ok, Equals, true)783 steps := spec.Scenarios[0].Steps784 c.Assert(len(steps), Equals, 1)785 c.Assert(steps[0].IsConcept, Equals, true)786 c.Assert(steps[0].Value, Equals, "assign id {} and name {}")787 c.Assert(len(steps[0].Args), Equals, 2)788 c.Assert(steps[0].Args[1].ArgType, Equals, gauge.TableArg)789 table := steps[0].Args[1].Table790 userIDCells, _ := table.Get("user-id")791 descriptionCells, _ := table.Get("description")792 nameCells, _ := table.Get("name")793 c.Assert(userIDCells[0].Value, Equals, "id")794 c.Assert(userIDCells[0].CellType, Equals, gauge.Dynamic)795 c.Assert(descriptionCells[0].Value, Equals, "description")796 c.Assert(descriptionCells[0].CellType, Equals, gauge.Dynamic)797 c.Assert(nameCells[0].Value, Equals, "root")798 c.Assert(nameCells[0].CellType, Equals, gauge.Static)799 c.Assert(len(steps[0].ConceptSteps), Equals, 2)800}801func (s *MySuite) TestCreateInValidSpecialArgInStep(c *C) {802 tokens := []*Token{803 {Kind: gauge.SpecKind, Value: "Spec Heading", LineNo: 1},804 {Kind: gauge.TableHeader, Args: []string{"unknown:foo", "description"}, LineNo: 2},805 {Kind: gauge.TableRow, Args: []string{"123", "Admin"}, LineNo: 3},806 {Kind: gauge.ScenarioKind, Value: "Scenario Heading", LineNo: 2},807 {Kind: gauge.StepKind, Value: "Example {special} step", LineNo: 3, Args: []string{"unknown:foo"}},808 }809 spec, parseResults, err := new(SpecParser).CreateSpecification(tokens, gauge.NewConceptDictionary(), "")810 c.Assert(err, IsNil)811 c.Assert(spec.Scenarios[0].Steps[0].Args[0].ArgType, Equals, gauge.Dynamic)812 c.Assert(len(parseResults.Warnings), Equals, 1)813 c.Assert(parseResults.Warnings[0].Message, Equals, "Could not resolve special param type <unknown:foo>. Treating it as dynamic param.")814}815func (s *MySuite) TestTearDownSteps(c *C) {816 tokens := []*Token{817 {Kind: gauge.SpecKind, Value: "Spec Heading", LineNo: 1},818 {Kind: gauge.CommentKind, Value: "A comment with some text and **bold** characters", LineNo: 2},819 {Kind: gauge.ScenarioKind, Value: "Scenario Heading", LineNo: 3},820 {Kind: gauge.CommentKind, Value: "Another comment", LineNo: 4},821 {Kind: gauge.StepKind, Value: "Example step", LineNo: 5},822 {Kind: gauge.CommentKind, Value: "Third comment", LineNo: 6},823 {Kind: gauge.TearDownKind, Value: "____", LineNo: 7},824 {Kind: gauge.StepKind, Value: "Example step1", LineNo: 8},825 {Kind: gauge.CommentKind, Value: "Fourth comment", LineNo: 9},826 {Kind: gauge.StepKind, Value: "Example step2", LineNo: 10},827 }828 spec, _, err := new(SpecParser).CreateSpecification(tokens, gauge.NewConceptDictionary(), "")829 c.Assert(err, IsNil)830 c.Assert(len(spec.TearDownSteps), Equals, 2)831 c.Assert(spec.TearDownSteps[0].Value, Equals, "Example step1")832 c.Assert(spec.TearDownSteps[0].LineNo, Equals, 8)833 c.Assert(spec.TearDownSteps[1].Value, Equals, "Example step2")834 c.Assert(spec.TearDownSteps[1].LineNo, Equals, 10)835}836func (s *MySuite) TestParsingOfTableWithHyphens(c *C) {837 p := new(SpecParser)838 text := newSpecBuilder().specHeading("My Spec Heading").text("|id|").text("|--|").text("|1 |").text("|- |").String()839 tokens, _ := p.GenerateTokens(text, "")840 spec, _, err := p.CreateSpecification(tokens, gauge.NewConceptDictionary(), "")841 c.Assert(err, IsNil)842 idCells, _ := spec.DataTable.Table.Get("id")843 c.Assert((len(idCells)), Equals, 2)844 c.Assert(idCells[0].Value, Equals, "1")845 c.Assert(idCells[1].Value, Equals, "-")846}847func (s *MySuite) TestCreateStepWithNewlineBetweenTextAndTable(c *C) {848 tokens := []*Token{849 {Kind: gauge.SpecKind, Value: "Spec Heading", LineNo: 1},850 {Kind: gauge.ScenarioKind, Value: "Scenario Heading", LineNo: 2},851 {Kind: gauge.StepKind, Value: "some random step\n", LineNo: 3},852 {Kind: gauge.TableHeader, Args: []string{"id", "description"}, LineNo: 5},853 {Kind: gauge.TableRow, Args: []string{"123", "Admin"}, LineNo: 6},854 {Kind: gauge.TableRow, Args: []string{"456", "normal fellow"}, LineNo: 7},855 }856 conceptDictionary := gauge.NewConceptDictionary()857 spec, _, err := new(SpecParser).CreateSpecification(tokens, conceptDictionary, "")858 c.Assert(err, IsNil)859 c.Assert(spec.Scenarios[0].Steps[0].HasInlineTable, Equals, true)860}861func (s *MySuite) TestSpecParsingWhenSpecHeadingIsNotPresentAndDynamicParseError(c *C) {862 p := new(SpecParser)863 _, res, err := p.Parse(`#864Scenario Heading865----------------866* def <a>867`, gauge.NewConceptDictionary(), "foo.spec")868 c.Assert(err, IsNil)869 c.Assert(len(res.ParseErrors), Equals, 2)870 c.Assert(res.ParseErrors[0].Error(), Equals, "foo.spec:1 Spec heading should have at least one character => ''")871 c.Assert(res.ParseErrors[1].Error(), Equals, "foo.spec:4 Dynamic parameter <a> could not be resolved => 'def <a>'")872}873func (s *MySuite) TestSpecParsingWhenSpecHeadingIsNotPresent(c *C) {874 p := new(SpecParser)875 _, res, err := p.Parse(`#876Scenario Heading877----------------878* def "sad"879`, gauge.NewConceptDictionary(), "foo.spec")880 c.Assert(err, IsNil)881 c.Assert(len(res.ParseErrors), Equals, 1)882 c.Assert(res.ParseErrors[0].Error(), Equals, "foo.spec:1 Spec heading should have at least one character => ''")883}884func (s *MySuite) TestSpecParsingWhenUnderlinedSpecHeadingIsNotPresent(c *C) {885 p := new(SpecParser)886 _, res, err := p.Parse(`======887Scenario Heading888----------------889* def "sd"890`, gauge.NewConceptDictionary(), "foo.spec")891 c.Assert(err, IsNil)892 c.Assert(len(res.ParseErrors), Equals, 2)893 c.Assert(res.ParseErrors[0].Error(), Equals, "foo.spec:1 Spec heading not found => ''")894 c.Assert(res.ParseErrors[1].Error(), Equals, "foo.spec:2 Scenario should be defined after the spec heading => 'Scenario Heading'")895}896func (s *MySuite) TestProcessingTokensGivesErrorWhenSpecHeadingHasOnlySpaces(c *C) {897 p := new(SpecParser)898 _, res, err := p.Parse("#"+" "+`899Scenario Heading900----------------901* def "sd"902`, gauge.NewConceptDictionary(), "foo.spec")903 c.Assert(err, IsNil)904 c.Assert(len(res.ParseErrors), Equals, 1)905 c.Assert(res.ParseErrors[0].Error(), Equals, "foo.spec:1 Spec heading should have at least one character => ''")906}907func (s *MySuite) TestProcessingTokensGivesErrorWhenScenarioHeadingIsEmpty(c *C) {908 p := new(SpecParser)909 _, res, err := p.Parse(`# dfgdfg910##911* def "sd"912`, gauge.NewConceptDictionary(), "foo.spec")913 c.Assert(err, IsNil)914 c.Assert(len(res.ParseErrors), Equals, 1)915 c.Assert(res.ParseErrors[0].Error(), Equals, "foo.spec:2 Scenario heading should have at least one character => ''")916}917func (s *MySuite) TestProcessingTokensGivesErrorWhenScenarioHeadingHasOnlySpaces(c *C) {918 p := new(SpecParser)919 _, res, err := p.Parse(`# dfgs920##`+" "+`921* def "sd"922`, gauge.NewConceptDictionary(), "foo.spec")923 c.Assert(err, IsNil)924 c.Assert(len(res.ParseErrors), Equals, 1)925 c.Assert(res.ParseErrors[0].Error(), Equals, "foo.spec:2 Scenario heading should have at least one character => ''")926}927func (s *MySuite) TestScenarioProcessingToHaveScenarioSpan(c *C) {928 p := new(SpecParser)929 spec, _, err := p.Parse(`# Spec 1930## Scenario 1931* def "sd"932comment1933* def "sd"934## Scenario 2935* def "sd"936comment2937* def "sd"938## Scenario 3939* def "sd"940comment3941* def "sd"942`, gauge.NewConceptDictionary(), "")943 c.Assert(err, IsNil)944 c.Assert(len(spec.Scenarios), Equals, 3)945 c.Assert(spec.Scenarios[0].Span.Start, Equals, 2)946 c.Assert(spec.Scenarios[0].Span.End, Equals, 7)947 c.Assert(spec.Scenarios[1].Span.Start, Equals, 8)948 c.Assert(spec.Scenarios[1].Span.End, Equals, 13)949 c.Assert(spec.Scenarios[2].Span.Start, Equals, 14)950 c.Assert(spec.Scenarios[2].Span.End, Equals, 17)951}952func TestParseScenarioWithDataTable(t *testing.T) {953 p := new(SpecParser)954 var subject = func() *gauge.Scenario {955 spec, _, err := p.Parse(`Specification Heading956 =====================957 * Vowels in English language are "aeiou".958 959 Vowel counts in single word960 ---------------------------961 962 |Word |Vowel Count|963 |------|-----------|964 |Gauge |3 |965 |Mingle|2 |966 |Snap |1 |967 |GoCD |1 |968 |Rhythm|0 |969 970 * The word <Word> has <Vowel Count> vowels.971 972 `, gauge.NewConceptDictionary(), "")973 if err != nil {974 t.Error(err)975 }976 return spec.Scenarios[0]977 }978 t.Run("Parse Scenario with datatable when AllowScenarioDatatable=True", func(t *testing.T) {979 env.AllowScenarioDatatable = func() bool { return true }980 s := subject()981 v := len(s.DataTable.Table.Rows())982 if v != 5 {983 t.Errorf("expected scenario to have 5 rows, got %d", v)984 }985 v = len(s.DataTable.Table.Columns)986 if v != 2 {987 t.Errorf("expected scenario to have 2 columns, got %d", v)988 }989 })990 t.Run("Parse Scenario with datatable when AllowScenarioDatatable=False", func(t *testing.T) {991 env.AllowScenarioDatatable = func() bool { return false }992 s := subject()993 v := len(s.DataTable.Table.Rows())994 if v != 0 {995 t.Errorf("expected scenario to have no rows, got %d", v)996 }997 })998}999func TestParseScenarioWithExternalDataTable(t *testing.T) {1000 p := new(SpecParser)1001 var subject = func() *gauge.Scenario {1002 spec, _, err := p.Parse(`Specification Heading1003=====================1004* Vowels in English language are "aeiou".1005Vowel counts in single word1006---------------------------1007table:testdata/data.csv1008* The word <Word> has <Vowel Count> vowels.1009`, gauge.NewConceptDictionary(), "")1010 if err != nil {1011 t.Error(err)1012 }1013 return spec.Scenarios[0]1014 }1015 t.Run("Parse Scenario with external datatable when AllowScenarioDatatable=True", func(t *testing.T) {1016 env.AllowScenarioDatatable = func() bool { return true }1017 s := subject()1018 v := len(s.DataTable.Table.Rows())1019 if v != 5 {1020 t.Errorf("expected scenario to have 5 rows, got %d", v)1021 }1022 v = len(s.DataTable.Table.Columns)1023 if v != 2 {1024 t.Errorf("expected scenario to have 2 columns, got %d", v)1025 }1026 })1027 t.Run("Parse Scenario with datatable when AllowScenarioDatatable=False", func(t *testing.T) {1028 env.AllowScenarioDatatable = func() bool { return false }1029 s := subject()1030 v := len(s.DataTable.Table.Rows())1031 if v != 0 {1032 t.Errorf("expected scenario to have no rows, got %d", v)1033 }1034 })1035}1036func (s *MySuite) TestParsingWhenTearDownHAsOnlyTable(c *C) {1037 p := new(SpecParser)1038 spec, _, err := p.Parse(`Specification Heading1039=====================1040* Vowels in English language are "aeiou".1041Vowel counts in single word1042---------------------------1043* The word "gauge" has "3" vowels.1044___1045 |Word |Vowel Count|1046 |------|-----------|1047 |Gauge |3 |1048 |Mingle|2 |1049 |Snap |1 |1050 |GoCD |1 |1051 |Rhythm|0 |1052`, gauge.NewConceptDictionary(), "")1053 c.Assert(err, IsNil)1054 c.Assert(len(spec.TearDownSteps), Equals, 0)1055 c.Assert(len(spec.Comments), Equals, 7)1056}1057func (s *MySuite) TestSpecWithRepeatedTagDefinitions(c *C) {1058 p := new(SpecParser)1059 spec, parseRes, err := p.Parse(`Spec Heading1060==============1061tags: foo, bar1062* step1063tags: blah1064Scenario1065--------1066* step1067 `, gauge.NewConceptDictionary(), "")1068 c.Assert(err, IsNil)1069 c.Assert(len(parseRes.ParseErrors), Equals, 1)1070 c.Assert(parseRes.ParseErrors[0].Message, Equals, "Tags can be defined only once per specification")1071 c.Assert(len(spec.Tags.Values()), Equals, 2)1072 c.Assert(spec.Tags.Values()[0], Equals, "foo")1073 c.Assert(spec.Tags.Values()[1], Equals, "bar")1074}1075func (s *MySuite) TestScenarioWithRepeatedTagDefinitions(c *C) {1076 p := new(SpecParser)1077 spec, parseRes, err := p.Parse(`Spec Heading1078==============1079tags: tag11080* step1081Scenario1082--------1083tags: foo, bar1084* step1085tags: blah1086 `, gauge.NewConceptDictionary(), "")1087 c.Assert(err, IsNil)1088 c.Assert(len(parseRes.ParseErrors), Equals, 1)1089 c.Assert(parseRes.ParseErrors[0].Message, Equals, "Tags can be defined only once per scenario")1090 c.Assert(len(spec.Scenarios[0].Tags.Values()), Equals, 2)1091 c.Assert(spec.Scenarios[0].Tags.Values()[0], Equals, "foo")1092 c.Assert(spec.Scenarios[0].Tags.Values()[1], Equals, "bar")1093 c.Assert(len(spec.Tags.Values()), Equals, 1)1094 c.Assert(spec.Tags.Values()[0], Equals, "tag1")1095}1096func (s *MySuite) TestDatatTableWithEmptyHeaders(c *C) {1097 p := new(SpecParser)1098 _, parseRes, err := p.Parse(`Something1099=========1100 ||a|||a|1101 |-------|1102 |dsf|dsf|dsf|dsf|dsf|1103Scenario Heading1104----------------1105* Vowels in English language are "aeiou".1106`, gauge.NewConceptDictionary(), "")1107 c.Assert(err, IsNil)1108 c.Assert(len(parseRes.ParseErrors), Equals, 4)1109 c.Assert(parseRes.ParseErrors[0].Message, Equals, "Table header should not be blank")1110 c.Assert(parseRes.ParseErrors[1].Message, Equals, "Table header should not be blank")1111 c.Assert(parseRes.ParseErrors[2].Message, Equals, "Table header should not be blank")1112 c.Assert(parseRes.ParseErrors[3].Message, Equals, "Table header cannot have repeated column values")1113}1114func (s *MySuite) TestExtractStepArgsFromToken(c *C) {1115 token := &Token{Kind: gauge.StepKind, Lines: []string{`my step with "Static" and <Dynamic> params`}, Value: `my step with {static} and {dynamic} params`, Args: []string{"Static", "Dynamic"}}1116 args, err := ExtractStepArgsFromToken(token)1117 if err != nil {1118 c.Fatalf("Error while extracting step args : %s", err.Error())1119 }1120 c.Assert(len(args), Equals, 2)1121 c.Assert(args[0].Value, Equals, "Static")1122 c.Assert(args[0].ArgType, Equals, gauge.Static)1123 c.Assert(args[1].Value, Equals, "Dynamic")1124 c.Assert(args[1].ArgType, Equals, gauge.Dynamic)1125}1126func (s *MySuite) TestParsingTableParameterWithSpecialString(c *C) {1127 parser := new(SpecParser)1128 specText := newSpecBuilder().specHeading("Spec Heading").scenarioHeading("First scenario").step("my step").text("|name|id|").text("|---|---|").text("|john|123|").text("|james|<file:testdata/foo.txt>|").String()1129 spec, res := parser.ParseSpecText(specText, "")...

Full Screen

Full Screen

refactor_test.go

Source:refactor_test.go Github

copy

Full Screen

...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"...

Full Screen

Full Screen

formatter_test.go

Source:formatter_test.go Github

copy

Full Screen

...16type MySuite struct{}17var _ = Suite(&MySuite{})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>|...

Full Screen

Full Screen

Kind

Using AI Code Generation

copy

Full Screen

1import (2func main() {3 fmt.Println(g1.kind, g1.value, g1.unit)4}5import (6func main() {7 g1 := NewGauge("pressure", 14.7, "psi")8 fmt.Println(g1.kind, g1.value, g1.unit)9}10import (11func main() {12 g1 := NewGauge("pressure", 14.7, "psi")13 fmt.Println(g1)14}15import (16func main() {17 g1 := NewGauge("pressure", 14.7, "psi")18 fmt.Println(g1)19 g1.SetUnit("kPa")20 fmt.Println(g1)21}22import (23func main() {24 g1 := NewGauge("pressure", 14.7, "psi")25 fmt.Println(g1)26 g1.SetValue(100.5)27 fmt.Println(g1)28}29import (30func main() {31 g1 := NewGauge("pressure", 14.7, "psi")32 fmt.Println(g1)33 g1.SetKind("temperature")34 fmt.Println(g1)35}36import (37func main() {38 g1 := NewGauge("pressure", 14.7, "psi")39 fmt.Println(g1)40 g1.SetKind("temperature")41 fmt.Println(g1)42 g1.SetValue(100.5)43 fmt.Println(g1)44 g1.SetUnit("kPa")45 fmt.Println(g1)

Full Screen

Full Screen

Kind

Using AI Code Generation

copy

Full Screen

1import (2type Gauge struct {3}4func (g Gauge) Kind() string {5}6func main() {7 g := Gauge{kind: "pressure"}8 fmt.Println(g.Kind())9}10import (11type Gauge struct {12}13func (g Gauge) Kind() string {14}15func main() {16 g := Gauge{kind: "pressure"}17 fmt.Println(g.Kind())18}19import (20type Gauge struct {21}22func (g Gauge) Kind() string {23}24func main() {25 g := Gauge{kind: "pressure"}26 fmt.Println(g.Kind())27}28import (29type Gauge struct {30}31func (g Gauge) Kind() string {32}33func main() {34 g := Gauge{kind: "pressure"}35 fmt.Println(g.Kind())36}37import (38type Gauge struct {39}40func (g Gauge) Kind() string {41}42func main() {43 g := Gauge{kind: "pressure"}44 fmt.Println(g.Kind())45}46import (47type Gauge struct {48}49func (g Gauge) Kind() string {50}51func main() {52 g := Gauge{kind: "pressure"}53 fmt.Println(g.Kind())54}55import (56type Gauge struct {57}58func (g Gauge) Kind() string {59}60func main() {

Full Screen

Full Screen

Kind

Using AI Code Generation

copy

Full Screen

1import (2func main() {3 g := gauge.NewGauge()4 g.Kind(1)5 fmt.Println(g)6}7import (8func main() {9 g := gauge.NewGauge()10 g.Kind(2)11 fmt.Println(g)12}13import (14func main() {15 g := gauge.NewGauge()16 g.Kind(3)17 fmt.Println(g)18}19import (20func main() {21 g := gauge.NewGauge()22 g.Kind(4)23 fmt.Println(g)24}25import (26func main() {27 g := gauge.NewGauge()28 g.Kind(5)29 fmt.Println(g)30}31import (32func main() {33 g := gauge.NewGauge()34 g.Kind(6)35 fmt.Println(g)36}37import (38func main() {39 g := gauge.NewGauge()40 g.Kind(7)41 fmt.Println(g)42}43import (44func main() {45 g := gauge.NewGauge()46 g.Kind(8)47 fmt.Println(g)48}49import (50func main() {51 g := gauge.NewGauge()52 g.Kind(9)53 fmt.Println(g)54}55import (56func main() {57 g := gauge.NewGauge()58 g.Kind(10)59 fmt.Println(g)60}

Full Screen

Full Screen

Kind

Using AI Code Generation

copy

Full Screen

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

Full Screen

Full Screen

Kind

Using AI Code Generation

copy

Full Screen

1import "fmt"2func main() {3 var g1 = Gauge{4 }5 fmt.Println(g1.Kind())6}7import "fmt"8func main() {9 var g1 = Gauge{10 }11 fmt.Println(g1.Kind())12}13import "fmt"14func main() {15 var g1 = Gauge{16 }17 fmt.Println(g1.Kind())18}19import "fmt"20func main() {21 var g1 = Gauge{22 }23 fmt.Println(g1.Kind())24}25import "fmt"26func main() {27 var g1 = Gauge{28 }29 fmt.Println(g1.Kind())30}31import "fmt"32func main() {33 var g1 = Gauge{34 }35 fmt.Println(g1.Kind())36}37import "fmt"38func main() {39 var g1 = Gauge{40 }41 fmt.Println(g1.Kind())42}43import "fmt"44func main() {45 var g1 = Gauge{46 }47 fmt.Println(g1.Kind())48}49import "fmt"50func main() {51 var g1 = Gauge{52 }53 fmt.Println(g1.Kind())54}55import "fmt"56func main() {57 var g1 = Gauge{58 }59 fmt.Println(g1.Kind())60}61import "fmt"

Full Screen

Full Screen

Kind

Using AI Code Generation

copy

Full Screen

1import (2type Gauge struct {3}4func (g Gauge) String() string {5 return fmt.Sprintf("Kind: %s, Reading: %f", g.Kind, g.Reading)6}7func (g Gauge) Value() float64 {8}9func (g Gauge) Set(v float64) {10}11func (g Gauge) Min() float64 {12}13func (g Gauge) Max() float64 {14}15func main() {16 g := Gauge{Kind: "Pressure", Reading: 2.34}17 fmt.Println(g)18 fmt.Println(g.Value())19 g.Set(4.56)20 fmt.Println(g)21 fmt.Println(g.Min())22 fmt.Println(g.Max())23}24import (25type Gauge struct {26}27func (g Gauge) String() string {28 return fmt.Sprintf("Kind: %s, Reading: %f", g.Kind, g.Reading)29}30func (g Gauge) Value() float64 {31}32func (g Gauge) Set(v float64) {33}34func (g Gauge) Min() float64 {35}36func (g Gauge) Max() float64 {37}38func main() {39 g := Gauge{Kind: "Pressure", Reading: 2.34}40 fmt.Println(g)41 fmt.Println(g.Value())42 g.Set(4.56)43 fmt.Println(g)44 fmt.Println(g.Min())45 fmt.Println(g.Max())46}47import (48type Gauge struct {

Full Screen

Full Screen

Kind

Using AI Code Generation

copy

Full Screen

1import (2func main() {3 g := gauge.NewGauge(0, 100, 50)4 fmt.Println(g.Kind())5}6import (7func main() {8 g := gauge.NewGauge(0, 100, 50)9 fmt.Println(g.Kind())10}11import (12func main() {13 g := gauge.NewGauge(0, 100, 50)14 fmt.Println(g.Kind())15}16import (17func main() {18 g := gauge.NewGauge(0, 100, 50)19 fmt.Println(g.Kind())20}21import (22func main() {23 g := gauge.NewGauge(0, 100, 50)24 fmt.Println(g.Kind())25}26import (27func main() {28 g := gauge.NewGauge(0, 100, 50)29 fmt.Println(g.Kind())30}31import (32func main() {33 g := gauge.NewGauge(0, 100, 50)34 fmt.Println(g.Kind())35}36import (37func main() {38 g := gauge.NewGauge(0, 100, 50)39 fmt.Println(g.Kind())40}41import

Full Screen

Full Screen

Kind

Using AI Code Generation

copy

Full Screen

1import (2func main() {3 for _, arg := range os.Args[1:] {4 t, err := strconv.ParseFloat(arg, 64)5 if err != nil {6 fmt.Fprintf(os.Stderr, "cf: %v\n", err)7 os.Exit(1)8 }9 f := tempconv.Fahrenheit(t)10 c := tempconv.Celsius(t)11 ft := lengthconv.Feet(t)12 m := lengthconv.Meter(t)13 lb := weightconv.Pound(t)14 kg := weightconv.Kilogram(t)15 fmt.Printf("%s = %s, %s = %s, %s = %s, %s = %s, %s = %s, %s = %s\n",16 f, tempconv.FToC(f), c, tempconv.CToF(c),17 ft, lengthconv.FToM(ft), m, lengthconv.MToF(m),18 lb, weightconv.PToK(lb), kg, weightconv.KToP(kg))19 }20}21import (22func main() {23 for _, arg := range os.Args[1:] {24 t, err := strconv.ParseFloat(arg, 64)25 if err != nil {26 fmt.Fprintf(os.Stderr, "cf: %v\n", err)27 os.Exit(1)28 }29 f := tempconv.Fahrenheit(t)30 c := tempconv.Celsius(t)31 ft := lengthconv.Feet(t)32 m := lengthconv.Meter(t)

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