diff --git a/execution/specExecutor_test.go b/execution/specExecutor_test.go index 2e7a8f778..914c6ecfa 100644 --- a/execution/specExecutor_test.go +++ b/execution/specExecutor_test.go @@ -19,6 +19,8 @@ package execution import ( "fmt" + "path/filepath" + "github.com/getgauge/gauge/gauge_messages" "github.com/getgauge/gauge/parser" . "gopkg.in/check.v1" @@ -93,20 +95,15 @@ func (specBuilder *specBuilder) text(comment string) *specBuilder { } func (s *MySuite) TestResolveConceptToProtoConceptItem(c *C) { - conceptDictionary := new(parser.ConceptDictionary) + conceptDictionary := parser.NewConceptDictionary() specText := SpecBuilder().specHeading("A spec heading"). scenarioHeading("First scenario"). step("create user \"456\" \"foo\" and \"9900\""). String() + path, _ := filepath.Abs(filepath.Join("testdata", "concept.cpt")) + parser.AddConcepts(path, conceptDictionary) - conceptText := SpecBuilder(). - specHeading("create user and "). - step("assign id and name "). - step("assign phone ").String() - - concepts, _ := new(parser.ConceptParser).Parse(conceptText) - conceptDictionary.Add(concepts, "file.cpt") spec, _ := new(parser.SpecParser).Parse(specText, conceptDictionary) specExecutor := newSpecExecutor(spec, nil, nil, indexRange{start: 0, end: 0}, nil, nil) @@ -114,13 +111,19 @@ func (s *MySuite) TestResolveConceptToProtoConceptItem(c *C) { protoConcept := specExecutor.resolveToProtoConceptItem(*spec.Scenarios[0].Steps[0]).GetConcept() checkConceptParameterValuesInOrder(c, protoConcept, "456", "foo", "9900") - - firstStep := protoConcept.GetSteps()[0].GetStep() - params := getParameters(firstStep.GetFragments()) - c.Assert(2, Equals, len(params)) + fmt.Println(protoConcept) + firstNestedStep := protoConcept.GetSteps()[0].GetConcept().GetSteps()[0].GetStep() + params := getParameters(firstNestedStep.GetFragments()) + c.Assert(1, Equals, len(params)) c.Assert(params[0].GetParameterType(), Equals, gauge_messages.Parameter_Dynamic) c.Assert(params[0].GetValue(), Equals, "456") + secondNestedStep := protoConcept.GetSteps()[0].GetConcept().GetSteps()[1].GetStep() + params = getParameters(secondNestedStep.GetFragments()) + c.Assert(1, Equals, len(params)) + c.Assert(params[0].GetParameterType(), Equals, gauge_messages.Parameter_Dynamic) + c.Assert(params[0].GetValue(), Equals, "foo") + secondStep := protoConcept.GetSteps()[1].GetStep() params = getParameters(secondStep.GetFragments()) c.Assert(1, Equals, len(params)) @@ -130,23 +133,15 @@ func (s *MySuite) TestResolveConceptToProtoConceptItem(c *C) { } func (s *MySuite) TestResolveNestedConceptToProtoConceptItem(c *C) { - conceptDictionary := new(parser.ConceptDictionary) + conceptDictionary := parser.NewConceptDictionary() specText := SpecBuilder().specHeading("A spec heading"). scenarioHeading("First scenario"). step("create user \"456\" \"foo\" and \"9900\""). String() - conceptText := SpecBuilder(). - specHeading("create user and "). - step("assign id and name "). - step("assign phone "). - specHeading("assign id and name "). - step("add id "). - step("add name ").String() - - concepts, _ := new(parser.ConceptParser).Parse(conceptText) - conceptDictionary.Add(concepts, "file.cpt") + path, _ := filepath.Abs(filepath.Join("testdata", "concept.cpt")) + parser.AddConcepts(path, conceptDictionary) specParser := new(parser.SpecParser) spec, _ := specParser.Parse(specText, conceptDictionary) @@ -182,7 +177,7 @@ func (s *MySuite) TestResolveNestedConceptToProtoConceptItem(c *C) { } func (s *MySuite) TestResolveToProtoConceptItemWithDataTable(c *C) { - conceptDictionary := new(parser.ConceptDictionary) + conceptDictionary := parser.NewConceptDictionary() specText := SpecBuilder().specHeading("A spec heading"). tableHeader("id", "name", "phone"). @@ -192,16 +187,8 @@ func (s *MySuite) TestResolveToProtoConceptItemWithDataTable(c *C) { step("create user and "). String() - conceptText := SpecBuilder(). - specHeading("create user and "). - step("assign id and name "). - step("assign phone "). - specHeading("assign id and name "). - step("add id "). - step("add name ").String() - - concepts, _ := new(parser.ConceptParser).Parse(conceptText) - conceptDictionary.Add(concepts, "file.cpt") + path, _ := filepath.Abs(filepath.Join("testdata", "concept.cpt")) + parser.AddConcepts(path, conceptDictionary) specParser := new(parser.SpecParser) spec, _ := specParser.Parse(specText, conceptDictionary) diff --git a/execution/testdata/concept.cpt b/execution/testdata/concept.cpt new file mode 100644 index 000000000..c1da4e158 --- /dev/null +++ b/execution/testdata/concept.cpt @@ -0,0 +1,7 @@ +# create user and +* assign id and name +* assign phone + +# assign id and name +* add id +* add name diff --git a/formatter/formatter_test.go b/formatter/formatter_test.go index f89693607..d9f99bbbb 100644 --- a/formatter/formatter_test.go +++ b/formatter/formatter_test.go @@ -18,9 +18,10 @@ package formatter import ( + "testing" + "github.com/getgauge/gauge/parser" . "gopkg.in/check.v1" - "testing" ) func Test(t *testing.T) { TestingT(t) } @@ -50,7 +51,7 @@ func (s *MySuite) TestFormatSpecification(c *C) { Scenario Heading ---------------- * Example step -* Step with inline table +* Step with inline table`+" "+` |id |name| |---|----| |<1>|foo | @@ -59,10 +60,12 @@ Scenario Heading } func (s *MySuite) TestFormatConcepts(c *C) { - dictionary := new(parser.ConceptDictionary) + dictionary := parser.NewConceptDictionary() step1 := &parser.Step{Value: "sdsf", LineText: "sdsf", IsConcept: true, LineNo: 1, PreComments: []*parser.Comment{&parser.Comment{Value: "COMMENT", LineNo: 1}}} step2 := &parser.Step{Value: "dsfdsfdsf", LineText: "dsfdsfdsf", IsConcept: true, LineNo: 2, Items: []parser.Item{&parser.Step{Value: "sfd", LineText: "sfd", IsConcept: false}, &parser.Step{Value: "sdfsdf" + "T", LineText: "sdfsdf" + "T", IsConcept: false}}} - dictionary.Add([]*parser.Step{step1, step2}, "file.cpt") + + dictionary.ConceptsMap[step1.Value] = &parser.Concept{ConceptStep: step1, FileName: "file.cpt"} + dictionary.ConceptsMap[step2.Value] = &parser.Concept{ConceptStep: step2, FileName: "file.cpt"} formatted := FormatConcepts(dictionary) c.Assert(formatted["file.cpt"], Equals, `COMMENT diff --git a/parser/conceptParser.go b/parser/conceptParser.go index b10717e15..45c8beb58 100644 --- a/parser/conceptParser.go +++ b/parser/conceptParser.go @@ -31,7 +31,6 @@ import ( type ConceptDictionary struct { ConceptsMap map[string]*Concept constructionMap map[string][]*Step - referenceMap map[*Step][]*Step } type Concept struct { @@ -232,25 +231,6 @@ func AddConcepts(conceptFile string, conceptDictionary *ConceptDictionary) *Pars if parseResults != nil && parseResults.Error != nil { return parseResults.Error } - return conceptDictionary.Add(concepts, conceptFile) -} - -func NewConceptDictionary() *ConceptDictionary { - return &ConceptDictionary{ConceptsMap: make(map[string]*Concept, 0)} -} - -func (conceptDictionary *ConceptDictionary) isConcept(step *Step) bool { - _, ok := conceptDictionary.ConceptsMap[step.Value] - return ok - -} -func (conceptDictionary *ConceptDictionary) Add(concepts []*Step, conceptFile string) *ParseError { - if conceptDictionary.ConceptsMap == nil { - conceptDictionary.ConceptsMap = make(map[string]*Concept) - } - if conceptDictionary.constructionMap == nil { - conceptDictionary.constructionMap = make(map[string][]*Step) - } for _, conceptStep := range concepts { if _, exists := conceptDictionary.ConceptsMap[conceptStep.Value]; exists { return &ParseError{Message: "Duplicate concept definition found", LineNo: conceptStep.LineNo, LineText: conceptStep.LineText} @@ -262,6 +242,16 @@ func (conceptDictionary *ConceptDictionary) Add(concepts []*Step, conceptFile st return conceptDictionary.validateConcepts() } +func NewConceptDictionary() *ConceptDictionary { + return &ConceptDictionary{ConceptsMap: make(map[string]*Concept, 0), constructionMap: make(map[string][]*Step, 0)} +} + +func (conceptDictionary *ConceptDictionary) isConcept(step *Step) bool { + _, ok := conceptDictionary.ConceptsMap[step.Value] + return ok + +} + func (conceptDictionary *ConceptDictionary) search(stepValue string) *Concept { if concept, ok := conceptDictionary.ConceptsMap[stepValue]; ok { return concept diff --git a/parser/conceptParser_test.go b/parser/conceptParser_test.go index a048c9418..9d90ee9e9 100644 --- a/parser/conceptParser_test.go +++ b/parser/conceptParser_test.go @@ -18,134 +18,87 @@ package parser import ( - . "gopkg.in/check.v1" + "path/filepath" "strings" + + . "gopkg.in/check.v1" ) +func assertStepEqual(c *C, expected, actual *Step) { + c.Assert(expected.LineNo, Equals, actual.LineNo) + c.Assert(expected.Value, Equals, actual.Value) + c.Assert(expected.LineText, Equals, actual.LineText) +} + func (s *MySuite) TestConceptDictionaryAdd(c *C) { - dictionary := new(ConceptDictionary) - step1 := &Step{Value: "test step 1"} - step2 := &Step{Value: "test step 2"} + dictionary := NewConceptDictionary() + step1Text := "test concept step 1" + step2Text := "test concept step 2" + step1 := &Step{Value: step1Text, LineNo: 1, IsConcept: true, LineText: step1Text} + step2 := &Step{Value: step2Text, LineNo: 4, IsConcept: true, LineText: step2Text} + path, _ := filepath.Abs(filepath.Join("testdata", "concept.cpt")) - err := dictionary.Add([]*Step{step1, step2}, "file.cpt") + err := AddConcepts(path, dictionary) c.Assert(err, IsNil) - c.Assert(dictionary.ConceptsMap["test step 1"].ConceptStep, Equals, step1) - c.Assert(dictionary.ConceptsMap["test step 1"].FileName, Equals, "file.cpt") - c.Assert(dictionary.ConceptsMap["test step 2"].ConceptStep, Equals, step2) - c.Assert(dictionary.ConceptsMap["test step 2"].FileName, Equals, "file.cpt") + assertStepEqual(c, dictionary.ConceptsMap[step1Text].ConceptStep, step1) + c.Assert(dictionary.ConceptsMap[step1Text].FileName, Equals, path) + assertStepEqual(c, dictionary.ConceptsMap[step2Text].ConceptStep, step2) + c.Assert(dictionary.ConceptsMap[step2Text].FileName, Equals, path) } func (s *MySuite) TestConceptDictionaryAddDuplicateConcept(c *C) { - dictionary := new(ConceptDictionary) - step1 := &Step{Value: "test step {}", LineText: "test step "} - step2 := &Step{Value: "test step {}", LineText: "test step "} + dictionary := NewConceptDictionary() + path, _ := filepath.Abs(filepath.Join("testdata", "duplicate_concept.cpt")) - err := dictionary.Add([]*Step{step1, step2}, "file.cpt") + err := AddConcepts(path, dictionary) c.Assert(err, NotNil) c.Assert(err.Message, Equals, "Duplicate concept definition found") } func (s *MySuite) TestConceptDictionaryWithNestedConcepts(c *C) { - dictionary := new(ConceptDictionary) - normalStep1 := &Step{Value: "normal step 1", LineText: "normal step 1"} - normalStep2 := &Step{Value: "normal step 2", LineText: "normal step 2"} - nestedConceptStep := &Step{Value: "nested concept", LineText: "nested concept"} - nestedConcept := &Step{Value: "nested concept", LineText: "nested concept", IsConcept: true, ConceptSteps: []*Step{normalStep2}} - - topLevelConcept := &Step{Value: "top level concept", IsConcept: true, ConceptSteps: []*Step{nestedConceptStep, normalStep1}} - - dictionary.Add([]*Step{nestedConcept}, "file1.cpt") - dictionary.Add([]*Step{topLevelConcept}, "file2.cpt") + dictionary := NewConceptDictionary() + path, _ := filepath.Abs(filepath.Join("testdata", "nested_concept.cpt")) - concept := dictionary.search("top level concept") - c.Assert(len(concept.ConceptStep.ConceptSteps), Equals, 2) - actualnestedConcept := concept.ConceptStep.ConceptSteps[0] - c.Assert(actualnestedConcept.IsConcept, Equals, true) - c.Assert(len(actualnestedConcept.ConceptSteps), Equals, 1) - c.Assert(actualnestedConcept.ConceptSteps[0].Value, Equals, normalStep2.Value) - c.Assert(concept.ConceptStep.ConceptSteps[1].Value, Equals, normalStep1.Value) -} + AddConcepts(path, dictionary) + concept := dictionary.search("test concept step 1") -func (s *MySuite) TestConceptDictionaryWithNestedConceptsWithParameter(c *C) { - conceptDictionary := new(ConceptDictionary) - conceptText := SpecBuilder(). - specHeading("assign id"). - step("add id"). - specHeading("create user"). - step("assign id"). - step("assign id").String() - concepts, _ := new(ConceptParser).Parse(conceptText) - conceptDictionary.Add(concepts, "file.cpt") - concept := conceptDictionary.search("create user") - c.Assert(concept.ConceptStep.ConceptSteps[0].Value, Equals, "assign id") - c.Assert(concept.ConceptStep.ConceptSteps[0].IsConcept, Equals, true) - c.Assert(concept.ConceptStep.ConceptSteps[1].Value, Equals, "assign id") - c.Assert(concept.ConceptStep.ConceptSteps[1].IsConcept, Equals, true) -} + c.Assert(len(concept.ConceptStep.ConceptSteps), Equals, 1) -func (s *MySuite) TestConceptDictionaryWithNestedConceptsWithDefinitionAfterUsage(c *C) { - conceptDictionary := new(ConceptDictionary) - conceptText := SpecBuilder(). - specHeading("create user"). - step("assign id"). - step("assign id"). - step("assign id"). - specHeading("assign id"). - step("add id").String() - concepts, _ := new(ConceptParser).Parse(conceptText) - conceptDictionary.Add(concepts, "file.cpt") - concept := conceptDictionary.search("create user") - c.Assert(concept.ConceptStep.ConceptSteps[0].Value, Equals, "assign id") - c.Assert(concept.ConceptStep.ConceptSteps[1].Value, Equals, "assign id") - c.Assert(concept.ConceptStep.ConceptSteps[2].Value, Equals, "assign id") - c.Assert(concept.ConceptStep.ConceptSteps[0].IsConcept, Equals, true) - c.Assert(concept.ConceptStep.ConceptSteps[1].IsConcept, Equals, true) - c.Assert(concept.ConceptStep.ConceptSteps[2].IsConcept, Equals, true) + actualNestedConcept := concept.ConceptStep.ConceptSteps[0] + c.Assert(actualNestedConcept.IsConcept, Equals, true) + c.Assert(len(actualNestedConcept.ConceptSteps), Equals, 1) + c.Assert(actualNestedConcept.ConceptSteps[0].Value, Equals, "step 2") } -func (s *MySuite) TestConceptDictionaryWithNestedConceptsWithParameters(c *C) { - conceptDictionary := new(ConceptDictionary) - conceptText := SpecBuilder(). - specHeading("create user and "). - step("assign id and name "). - specHeading("assign id and name "). - step("add id "). - step("add name ").String() - concepts, _ := new(ConceptParser).Parse(conceptText) - conceptDictionary.Add(concepts, "file.cpt") +func (s *MySuite) TestConceptDictionaryWithNestedConceptsWithDynamicParameters(c *C) { + conceptDictionary := NewConceptDictionary() + path, _ := filepath.Abs(filepath.Join("testdata", "dynamic_param_concept.cpt")) + AddConcepts(path, conceptDictionary) concept := conceptDictionary.search("create user {} {} and {}") c.Assert(len(concept.ConceptStep.ConceptSteps), Equals, 1) - actualnestedConcept := concept.ConceptStep.ConceptSteps[0] - c.Assert(actualnestedConcept.IsConcept, Equals, true) - - c.Assert(len(actualnestedConcept.ConceptSteps), Equals, 2) - c.Assert(actualnestedConcept.ConceptSteps[0].Value, Equals, "add id {}") - c.Assert(actualnestedConcept.ConceptSteps[0].Args[0].ArgType, Equals, Dynamic) - c.Assert(actualnestedConcept.ConceptSteps[0].Args[0].Value, Equals, "userid") - c.Assert(len(concepts[0].Items), Equals, 2) - - c.Assert(actualnestedConcept.ConceptSteps[1].Value, Equals, "add name {}") - c.Assert(actualnestedConcept.ConceptSteps[1].Args[0].ArgType, Equals, Dynamic) - c.Assert(actualnestedConcept.ConceptSteps[1].Args[0].Value, Equals, "username") - c.Assert(len(concepts[1].Items), Equals, 3) + actualNestedConcept := concept.ConceptStep.ConceptSteps[0] + c.Assert(actualNestedConcept.IsConcept, Equals, true) + + c.Assert(len(actualNestedConcept.ConceptSteps), Equals, 2) + c.Assert(actualNestedConcept.ConceptSteps[0].Value, Equals, "add id {}") + c.Assert(actualNestedConcept.ConceptSteps[0].Args[0].ArgType, Equals, Dynamic) + c.Assert(actualNestedConcept.ConceptSteps[0].Args[0].Value, Equals, "userid") + + c.Assert(actualNestedConcept.ConceptSteps[1].Value, Equals, "add name {}") + c.Assert(actualNestedConcept.ConceptSteps[1].Args[0].ArgType, Equals, Dynamic) + c.Assert(actualNestedConcept.ConceptSteps[1].Args[0].Value, Equals, "username") } func (s *MySuite) TestConceptDictionaryWithNestedConceptsWithStaticParameters(c *C) { - conceptDictionary := new(ConceptDictionary) - conceptText := SpecBuilder(). - specHeading("assign id and name "). - step("add id "). - step("add name "). - specHeading("create user and "). - step("assign id and name \"static-value\"").String() - concepts, _ := new(ConceptParser).Parse(conceptText) - conceptDictionary.Add(concepts, "file.cpt") + conceptDictionary := NewConceptDictionary() + path, _ := filepath.Abs(filepath.Join("testdata", "static_param_concept.cpt")) + AddConcepts(path, conceptDictionary) concept := conceptDictionary.search("create user {} {} and {}") - c.Assert(len(concept.ConceptStep.ConceptSteps), Equals, 1) + c.Assert(len(concept.ConceptStep.ConceptSteps), Equals, 2) actualNestedConcept := concept.ConceptStep.ConceptSteps[0] c.Assert(actualNestedConcept.IsConcept, Equals, true) @@ -163,160 +116,68 @@ func (s *MySuite) TestConceptDictionaryWithNestedConceptsWithStaticParameters(c c.Assert(actualNestedConcept.ConceptSteps[0].Value, Equals, "add id {}") c.Assert(actualNestedConcept.ConceptSteps[0].Args[0].ArgType, Equals, Dynamic) c.Assert(actualNestedConcept.ConceptSteps[0].Args[0].Value, Equals, "userid") - c.Assert(len(concepts[0].Items), Equals, 3) c.Assert(actualNestedConcept.ConceptSteps[1].Value, Equals, "add name {}") c.Assert(actualNestedConcept.ConceptSteps[1].Args[0].ArgType, Equals, Dynamic) c.Assert(actualNestedConcept.ConceptSteps[1].Args[0].Value, Equals, "username") - c.Assert(len(concepts[1].Items), Equals, 2) } func (s *MySuite) TestConceptHavingItemsWithComments(c *C) { - conceptDictionary := new(ConceptDictionary) - conceptText := SpecBuilder(). - specHeading("create user and "). - step("assign id and name "). - text("Comments"). - specHeading("assign id and name "). - step("add id "). - step("add name "). - text("Comment1").String() - concepts, _ := new(ConceptParser).Parse(conceptText) - conceptDictionary.Add(concepts, "file.cpt") + conceptDictionary := NewConceptDictionary() + path, _ := filepath.Abs(filepath.Join("testdata", "dynamic_param_concept.cpt")) + AddConcepts(path, conceptDictionary) concept := conceptDictionary.search("create user {} {} and {}") - c.Assert(len(concept.ConceptStep.ConceptSteps), Equals, 1) - actualnestedConcept := concept.ConceptStep.ConceptSteps[0] - c.Assert(actualnestedConcept.IsConcept, Equals, true) - - c.Assert(len(actualnestedConcept.ConceptSteps), Equals, 2) - c.Assert(actualnestedConcept.ConceptSteps[0].Value, Equals, "add id {}") - c.Assert(actualnestedConcept.ConceptSteps[0].Args[0].ArgType, Equals, Dynamic) - c.Assert(actualnestedConcept.ConceptSteps[0].Args[0].Value, Equals, "userid") - c.Assert(len(concepts[0].Items), Equals, 3) - c.Assert(concepts[0].Items[2].(*Comment).Value, Equals, "Comments") - - c.Assert(actualnestedConcept.ConceptSteps[1].Value, Equals, "add name {}") - c.Assert(actualnestedConcept.ConceptSteps[1].Args[0].ArgType, Equals, Dynamic) - c.Assert(actualnestedConcept.ConceptSteps[1].Args[0].Value, Equals, "username") - c.Assert(len(concepts[1].Items), Equals, 4) -} - -func (s *MySuite) TestConceptHavingItemsWithTablesAndPreComments(c *C) { - conceptDictionary := new(ConceptDictionary) - concepts, _ := new(ConceptParser).Parse("COMMENT\n# my concept \n * first step with and inline table\n |id|name|\n|1|vishnu|\n|2|prateek|\n comment") - conceptDictionary.Add(concepts, "concept.cpt") - c.Assert(len(concepts[0].Items), Equals, 3) - c.Assert(len(concepts[0].PreComments), Equals, 1) - c.Assert(concepts[0].PreComments[0].Value, Equals, "COMMENT") -} - -/* -#top level concept -* nested concept -* normal step 1 - -#top level concept 2 -* nested concept - -# nested concept -* normal step 2 -*/ -func (s *MySuite) TestNestedConceptsWhenReferencedConceptParsedLater(c *C) { - dictionary := new(ConceptDictionary) - normalStep1 := &Step{Value: "normal step 1", LineText: "normal step 1"} - normalStep2 := &Step{Value: "normal step 2", LineText: "normal step 2"} + c.Assert(len(concept.ConceptStep.Items), Equals, 3) + c.Assert(concept.ConceptStep.Items[2].(*Comment).Value, Equals, "Comments") - nestedConceptStep := &Step{Value: "nested concept", LineText: "nested concept"} + concept = conceptDictionary.search("assign id {} and name {}") - topLevelConcept := &Step{Value: "top level concept", IsConcept: true, ConceptSteps: []*Step{nestedConceptStep, normalStep1}} - anotherTopLevelConcept := &Step{Value: "top level concept 2", IsConcept: true, ConceptSteps: []*Step{nestedConceptStep}} - nestedConcept := &Step{Value: "nested concept", LineText: "nested concept", IsConcept: true, ConceptSteps: []*Step{normalStep2}} + c.Assert(len(concept.ConceptStep.Items), Equals, 4) + c.Assert(concept.ConceptStep.Items[3].(*Comment).Value, Equals, "Comment1") +} - dictionary.Add([]*Step{topLevelConcept}, "file1.cpt") - dictionary.Add([]*Step{anotherTopLevelConcept}, "file1.cpt") - dictionary.Add([]*Step{nestedConcept}, "file2.cpt") +func (s *MySuite) TestConceptHavingItemsWithTablesAndComments(c *C) { + conceptDictionary := NewConceptDictionary() + path, _ := filepath.Abs(filepath.Join("testdata", "tabular_concept.cpt")) - concept := dictionary.search("top level concept") - c.Assert(len(concept.ConceptStep.ConceptSteps), Equals, 2) - actualNestedConcept := concept.ConceptStep.ConceptSteps[0] - c.Assert(actualNestedConcept.IsConcept, Equals, true) - c.Assert(len(actualNestedConcept.ConceptSteps), Equals, 1) - c.Assert(actualNestedConcept.ConceptSteps[0].Value, Equals, normalStep2.Value) - c.Assert(concept.ConceptStep.ConceptSteps[1].Value, Equals, normalStep1.Value) + AddConcepts(path, conceptDictionary) - topLevelConcept2 := dictionary.search("top level concept 2") - c.Assert(len(topLevelConcept2.ConceptStep.ConceptSteps), Equals, 1) - actualNestedConcept = topLevelConcept2.ConceptStep.ConceptSteps[0] - c.Assert(actualNestedConcept.IsConcept, Equals, true) - c.Assert(len(actualNestedConcept.ConceptSteps), Equals, 1) - c.Assert(actualNestedConcept.ConceptSteps[0].Value, Equals, normalStep2.Value) + concept := conceptDictionary.search("my concept {}") + c.Assert(len(concept.ConceptStep.Items), Equals, 3) + c.Assert(len(concept.ConceptStep.PreComments), Equals, 1) + c.Assert(concept.ConceptStep.PreComments[0].Value, Equals, "COMMENT") + c.Assert(concept.ConceptStep.Items[2].(*Comment).Value, Equals, " comment") } -/* -# top level concept -* nested concept -* normal step 1 - -# another nested concept -* normal step 3 - -# nested concept -* another nested concept -* normal step 2 -*/ func (s *MySuite) TestMultiLevelConcept(c *C) { - dictionary := new(ConceptDictionary) - normalStep1 := &Step{Value: "normal step 1", LineText: "normal step 1"} - normalStep2 := &Step{Value: "normal step 2", LineText: "normal step 2"} - normalStep3 := &Step{Value: "normal step 3", LineText: "normal step 3"} - nestedConceptStep := &Step{Value: "nested concept", LineText: "nested concept"} - - topLevelConcept := &Step{Value: "top level concept", IsConcept: true, ConceptSteps: []*Step{nestedConceptStep, normalStep1}} - anotherNestedConcept := &Step{Value: "another nested concept", IsConcept: true, ConceptSteps: []*Step{normalStep3}} - nestedConcept := &Step{Value: "nested concept", IsConcept: true, ConceptSteps: []*Step{anotherNestedConcept, normalStep2}} + conceptDictionary := NewConceptDictionary() + path, _ := filepath.Abs(filepath.Join("testdata", "nested_concept2.cpt")) - dictionary.Add([]*Step{topLevelConcept}, "file1.cpt") - dictionary.Add([]*Step{anotherNestedConcept}, "file1.cpt") - dictionary.Add([]*Step{nestedConcept}, "file1.cpt") - - actualTopLevelConcept := dictionary.search("top level concept") + AddConcepts(path, conceptDictionary) + actualTopLevelConcept := conceptDictionary.search("top level concept") c.Assert(len(actualTopLevelConcept.ConceptStep.ConceptSteps), Equals, 2) actualNestedConcept := actualTopLevelConcept.ConceptStep.ConceptSteps[0] c.Assert(actualNestedConcept.IsConcept, Equals, true) c.Assert(len(actualNestedConcept.ConceptSteps), Equals, 2) - c.Assert(actualNestedConcept.ConceptSteps[0].Value, Equals, anotherNestedConcept.Value) - c.Assert(actualNestedConcept.ConceptSteps[1].Value, Equals, normalStep2.Value) - c.Assert(actualTopLevelConcept.ConceptStep.ConceptSteps[1].Value, Equals, normalStep1.Value) + c.Assert(actualNestedConcept.ConceptSteps[0].Value, Equals, "another nested concept") + c.Assert(actualNestedConcept.ConceptSteps[1].Value, Equals, "normal step 2") + c.Assert(actualTopLevelConcept.ConceptStep.ConceptSteps[1].Value, Equals, "normal step 1") - actualAnotherNestedConcept := dictionary.search("another nested concept") + actualAnotherNestedConcept := conceptDictionary.search("another nested concept") c.Assert(len(actualAnotherNestedConcept.ConceptStep.ConceptSteps), Equals, 1) step := actualAnotherNestedConcept.ConceptStep.ConceptSteps[0] c.Assert(step.IsConcept, Equals, false) - c.Assert(step.Value, Equals, normalStep3.Value) + c.Assert(step.Value, Equals, "normal step 3") - nestedConcept2 := dictionary.search("nested concept") + nestedConcept2 := conceptDictionary.search("nested concept") c.Assert(len(nestedConcept2.ConceptStep.ConceptSteps), Equals, 2) actualAnotherNestedConcept2 := nestedConcept2.ConceptStep.ConceptSteps[0] c.Assert(actualAnotherNestedConcept2.IsConcept, Equals, true) c.Assert(len(actualAnotherNestedConcept2.ConceptSteps), Equals, 1) - c.Assert(actualAnotherNestedConcept2.ConceptSteps[0].Value, Equals, normalStep3.Value) - c.Assert(nestedConcept2.ConceptStep.ConceptSteps[1].Value, Equals, normalStep2.Value) - -} - -func (s *MySuite) TestConceptDictionarySearch(c *C) { - dictionary := new(ConceptDictionary) - step1 := &Step{Value: "test step 1"} - step2 := &Step{Value: "test step 2"} - - dictionary.Add([]*Step{step1, step2}, "file.cpt") - - c.Assert(dictionary.search(step1.Value).ConceptStep, Equals, step1) - c.Assert(dictionary.search(step1.Value).FileName, Equals, "file.cpt") - c.Assert(dictionary.search(step2.Value).ConceptStep, Equals, step2) - c.Assert(dictionary.search(step2.Value).FileName, Equals, "file.cpt") + c.Assert(actualAnotherNestedConcept2.ConceptSteps[0].Value, Equals, "normal step 3") + c.Assert(nestedConcept2.ConceptStep.ConceptSteps[1].Value, Equals, "normal step 2") } func (s *MySuite) TestParsingSimpleConcept(c *C) { @@ -482,19 +343,11 @@ func (s *MySuite) TestErrorParsingConceptWithInvalidInlineTable(c *C) { } func (s *MySuite) TestDeepCopyOfConcept(c *C) { - dictionary := new(ConceptDictionary) - normalStep1 := &Step{Value: "normal step 1", LineText: "normal step 1"} - normalStep2 := &Step{Value: "normal step 2", LineText: "normal step 2"} - - nestedConceptStep := &Step{Value: "nested concept", LineText: "nested concept"} + dictionary := NewConceptDictionary() + path, _ := filepath.Abs(filepath.Join("testdata", "concept.cpt")) - topLevelConcept := &Step{Value: "top level concept", IsConcept: true, ConceptSteps: []*Step{nestedConceptStep, normalStep1}} - nestedConcept := &Step{Value: "nested concept", LineText: "nested concept", IsConcept: true, ConceptSteps: []*Step{normalStep2}} - - dictionary.Add([]*Step{topLevelConcept}, "file1.cpt") - dictionary.Add([]*Step{nestedConcept}, "file2.cpt") - - actualConcept := dictionary.search("top level concept") + AddConcepts(path, dictionary) + actualConcept := dictionary.search("test concept step 1") copiedTopLevelConcept := actualConcept.deepCopy() @@ -508,25 +361,17 @@ func verifyCopiedConcept(copiedConcept *Concept, actualConcept *Concept, c *C) { func (s *MySuite) TestNestedConceptLooksUpArgsFromParent(c *C) { parser := new(SpecParser) - conceptDictionary := new(ConceptDictionary) specText := SpecBuilder().specHeading("A spec heading"). scenarioHeading("First flow"). step("create user \"foo\" \"doo\""). step("another step").String() - conceptText := SpecBuilder(). - specHeading("create user "). - step("assign role "). - step("step 2"). - specHeading("assign role "). - step("add admin rights "). - step("give root access").String() - - concepts, _ := new(ConceptParser).Parse(conceptText) + dictionary := NewConceptDictionary() + path, _ := filepath.Abs(filepath.Join("testdata", "param_nested_concept.cpt")) - conceptDictionary.Add(concepts, "file.cpt") + AddConcepts(path, dictionary) tokens, _ := parser.GenerateTokens(specText) - spec, parseResult := parser.CreateSpecification(tokens, conceptDictionary) + spec, parseResult := parser.CreateSpecification(tokens, dictionary) c.Assert(parseResult.Ok, Equals, true) firstStepInSpec := spec.Scenarios[0].Steps[0] @@ -537,123 +382,44 @@ func (s *MySuite) TestNestedConceptLooksUpArgsFromParent(c *C) { c.Assert(nestedConceptArg2.Value, Equals, "doo") } -func (s *MySuite) TestNestedConceptLooksUpArgsFromParentPresentWhenNestedConceptDefinedFirst(c *C) { - parser := new(SpecParser) - conceptDictionary := new(ConceptDictionary) - - specText := SpecBuilder().specHeading("A spec heading"). - scenarioHeading("First scenario"). - step("create user \"foo\" \"prateek\" and \"007\""). - String() - - conceptText := SpecBuilder(). - specHeading("assign id and name "). - step("add id "). - step("add name "). - specHeading("create user and "). - step("assign id and name \"static-name\"").String() - - concepts, _ := new(ConceptParser).Parse(conceptText) - - conceptDictionary.Add(concepts, "file.cpt") - tokens, _ := parser.GenerateTokens(specText) - spec, parseResult := parser.CreateSpecification(tokens, conceptDictionary) - - c.Assert(parseResult.Ok, Equals, true) - firstLevelConcept := spec.Scenarios[0].Steps[0] - c.Assert(firstLevelConcept.getArg("user-id").Value, Equals, "foo") - c.Assert(firstLevelConcept.getArg("user-name").Value, Equals, "prateek") - c.Assert(firstLevelConcept.getArg("user-phone").Value, Equals, "007") - - nestedConcept := firstLevelConcept.ConceptSteps[0] - - c.Assert(nestedConcept.getArg("userid").Value, Equals, "foo") - c.Assert(nestedConcept.getArg("username").Value, Equals, "static-name") - -} - -func (s *MySuite) TestNestedConceptLooksUpArgsFromParentPresentWhenNestedConceptDefinedSecond(c *C) { - parser := new(SpecParser) - conceptDictionary := new(ConceptDictionary) - - specText := SpecBuilder().specHeading("A spec heading"). - scenarioHeading("First scenario"). - step("create user \"foo\" \"prateek\" and \"007\""). - String() - - conceptText := SpecBuilder(). - specHeading("create user and "). - step("assign id and name \"static-name\""). - specHeading("assign id and name "). - step("add id "). - step("add name ").String() - - concepts, _ := new(ConceptParser).Parse(conceptText) - - conceptDictionary.Add(concepts, "file.cpt") - tokens, _ := parser.GenerateTokens(specText) - spec, parseResult := parser.CreateSpecification(tokens, conceptDictionary) - - c.Assert(parseResult.Ok, Equals, true) - firstLevelConcept := spec.Scenarios[0].Steps[0] - c.Assert(firstLevelConcept.getArg("user-id").Value, Equals, "foo") - c.Assert(firstLevelConcept.getArg("user-name").Value, Equals, "prateek") - c.Assert(firstLevelConcept.getArg("user-phone").Value, Equals, "007") - - nestedConcept := firstLevelConcept.ConceptSteps[0] - c.Assert(nestedConcept.getArg("userid").Value, Equals, "foo") - c.Assert(nestedConcept.getArg("username").Value, Equals, "static-name") - -} - func (s *MySuite) TestNestedConceptLooksUpDataTableArgs(c *C) { parser := new(SpecParser) - conceptDictionary := new(ConceptDictionary) specText := SpecBuilder().specHeading("A spec heading"). tableHeader("id", "name", "phone"). tableHeader("123", "prateek", "8800"). tableHeader("456", "apoorva", "9800"). tableHeader("789", "srikanth", "7900"). scenarioHeading("First scenario"). - step("create user and "). + step("create user "). step("another step").String() - conceptText := SpecBuilder(). - specHeading("create user and "). - step("assign id and name "). - step("assign number "). - specHeading("assign id and name "). - step("add id "). - step("add name ").String() + dictionary := NewConceptDictionary() + path, _ := filepath.Abs(filepath.Join("testdata", "param_nested_concept.cpt")) - concepts, _ := new(ConceptParser).Parse(conceptText) + AddConcepts(path, dictionary) - conceptDictionary.Add(concepts, "file.cpt") tokens, _ := parser.GenerateTokens(specText) - spec, parseResult := parser.CreateSpecification(tokens, conceptDictionary) + spec, parseResult := parser.CreateSpecification(tokens, dictionary) c.Assert(parseResult.Ok, Equals, true) firstStepInSpec := spec.Scenarios[0].Steps[0] c.Assert(firstStepInSpec.IsConcept, Equals, true) - c.Assert(firstStepInSpec.getArg("user-id").ArgType, Equals, Dynamic) - c.Assert(firstStepInSpec.getArg("user-name").ArgType, Equals, Dynamic) - c.Assert(firstStepInSpec.getArg("user-phone").ArgType, Equals, Dynamic) - c.Assert(firstStepInSpec.getArg("user-id").Value, Equals, "id") - c.Assert(firstStepInSpec.getArg("user-name").Value, Equals, "name") - c.Assert(firstStepInSpec.getArg("user-phone").Value, Equals, "phone") + c.Assert(firstStepInSpec.getArg("bar").ArgType, Equals, Dynamic) + c.Assert(firstStepInSpec.getArg("far").ArgType, Equals, Dynamic) + c.Assert(firstStepInSpec.getArg("bar").Value, Equals, "id") + c.Assert(firstStepInSpec.getArg("far").Value, Equals, "name") nestedConcept := firstStepInSpec.ConceptSteps[0] - c.Assert(nestedConcept.getArg("userid").ArgType, Equals, Dynamic) - c.Assert(nestedConcept.getArg("username").ArgType, Equals, Dynamic) - c.Assert(nestedConcept.getArg("userid").Value, Equals, "id") - c.Assert(nestedConcept.getArg("username").Value, Equals, "name") + c.Assert(nestedConcept.getArg("baz").ArgType, Equals, Dynamic) + c.Assert(nestedConcept.getArg("boo").ArgType, Equals, Dynamic) + c.Assert(nestedConcept.getArg("baz").Value, Equals, "id") + c.Assert(nestedConcept.getArg("boo").Value, Equals, "name") } func (s *MySuite) TestNestedConceptLooksUpWhenParameterPlaceholdersAreSame(c *C) { parser := new(SpecParser) - conceptDictionary := new(ConceptDictionary) specText := SpecBuilder().specHeading("A spec heading"). tableHeader("id", "name", "phone"). tableHeader("123", "prateek", "8800"). @@ -663,19 +429,13 @@ func (s *MySuite) TestNestedConceptLooksUpWhenParameterPlaceholdersAreSame(c *C) step("create user and "). step("another step").String() - conceptText := SpecBuilder(). - specHeading("create user and "). - step("assign id and name "). - step("assign number "). - specHeading("assign id and name "). - step("add id "). - step("add name ").String() + dictionary := NewConceptDictionary() + path, _ := filepath.Abs(filepath.Join("testdata", "param_nested_concept2.cpt")) - concepts, _ := new(ConceptParser).Parse(conceptText) + AddConcepts(path, dictionary) - conceptDictionary.Add(concepts, "file.cpt") tokens, _ := parser.GenerateTokens(specText) - spec, parseResult := parser.CreateSpecification(tokens, conceptDictionary) + spec, parseResult := parser.CreateSpecification(tokens, dictionary) c.Assert(parseResult.Ok, Equals, true) @@ -697,45 +457,11 @@ func (s *MySuite) TestNestedConceptLooksUpWhenParameterPlaceholdersAreSame(c *C) } func (s *MySuite) TestErrorOnCircularReferenceInConcept(c *C) { - conceptDictionary := new(ConceptDictionary) - - conceptText := SpecBuilder(). - specHeading("another concept"). - step("second step"). - step("my concept"). - specHeading("my concept"). - step("first step"). - step("another concept").String() - - concepts, parseErr := new(ConceptParser).Parse(conceptText) - c.Assert(parseErr.Error, IsNil) - err := conceptDictionary.Add(concepts, "file.cpt") - c.Assert(err, NotNil) - c.Assert(true, Equals, strings.Contains(err.Message, "Circular reference found in concept")) -} + dictionary := NewConceptDictionary() + path, _ := filepath.Abs(filepath.Join("testdata", "circular_concept.cpt")) -func (s *MySuite) TestErrorOnCircularReferenceInDeepNestedConceptConcept(c *C) { - conceptDictionary := new(ConceptDictionary) - conceptText := SpecBuilder(). - specHeading("first concept and "). - step("a step step"). - step("a nested concept "). - specHeading("a nested concept "). - step("second nested "). - step("another step").String() - - secondConceptText := SpecBuilder(). - specHeading("second nested "). - step("a nested concept ").String() - - concepts1, parseRes := new(ConceptParser).Parse(conceptText) - c.Assert(parseRes.Error, IsNil) - concepts2, parseRes := new(ConceptParser).Parse(secondConceptText) - - err := conceptDictionary.Add(concepts1, "file.cpt") - c.Assert(err, IsNil) + err := AddConcepts(path, dictionary) - err = conceptDictionary.Add(concepts2, "file2.cpt") c.Assert(err, NotNil) c.Assert(true, Equals, strings.Contains(err.Message, "Circular reference found in concept")) } diff --git a/parser/helper.go b/parser/helper.go index 9ed1805ff..b94c15889 100644 --- a/parser/helper.go +++ b/parser/helper.go @@ -91,6 +91,7 @@ func arrayContains(array []string, toFind string) bool { return false } +//remove this func getIndexFor(scenario *Scenario, scenarios []*Scenario) int { for index, anItem := range scenarios { if reflect.DeepEqual(scenario, anItem) { diff --git a/parser/resolver_test.go b/parser/resolver_test.go index f11ad271b..796b9ffc5 100644 --- a/parser/resolver_test.go +++ b/parser/resolver_test.go @@ -18,6 +18,8 @@ package parser import ( + "path/filepath" + "github.com/getgauge/gauge/util" . "gopkg.in/check.v1" ) @@ -83,8 +85,6 @@ func (s *MySuite) TestParsingUnknownSpecialType(c *C) { func (s *MySuite) TestPopulatingConceptLookup(c *C) { parser := new(SpecParser) - conceptDictionary := new(ConceptDictionary) - specText := SpecBuilder().specHeading("A spec heading"). tableHeader("id", "name", "phone"). tableHeader("123", "foo", "888"). @@ -92,14 +92,9 @@ func (s *MySuite) TestPopulatingConceptLookup(c *C) { step("create user and "). String() - conceptText := SpecBuilder(). - specHeading("create user and "). - step("assign id and name "). - step("assign number ").String() - - concepts, _ := new(ConceptParser).Parse(conceptText) - - conceptDictionary.Add(concepts, "file.cpt") + conceptDictionary := NewConceptDictionary() + path, _ := filepath.Abs(filepath.Join("testdata", "dynamic_param_concept.cpt")) + AddConcepts(path, conceptDictionary) spec, _ := parser.Parse(specText, conceptDictionary) concept := spec.Scenarios[0].Steps[0] @@ -114,8 +109,6 @@ func (s *MySuite) TestPopulatingConceptLookup(c *C) { func (s *MySuite) TestPopulatingNestedConceptLookup(c *C) { parser := new(SpecParser) - conceptDictionary := new(ConceptDictionary) - specText := SpecBuilder().specHeading("A spec heading"). tableHeader("id", "name", "phone"). tableHeader("123", "prateek", "8800"). @@ -124,16 +117,9 @@ func (s *MySuite) TestPopulatingNestedConceptLookup(c *C) { step("create user \"456\" \"foo\" and \"9900\""). String() - conceptText := SpecBuilder(). - specHeading("create user and "). - step("assign id and name "). - specHeading("assign id and name "). - step("add id "). - step("add name ").String() - - concepts, _ := new(ConceptParser).Parse(conceptText) - - conceptDictionary.Add(concepts, "file.cpt") + conceptDictionary := NewConceptDictionary() + path, _ := filepath.Abs(filepath.Join("testdata", "dynamic_param_concept.cpt")) + AddConcepts(path, conceptDictionary) spec, _ := parser.Parse(specText, conceptDictionary) concept1 := spec.Scenarios[0].Steps[0] @@ -161,25 +147,15 @@ func (s *MySuite) TestPopulatingNestedConceptLookup(c *C) { func (s *MySuite) TestPopulatingNestedConceptsWithStaticParametersLookup(c *C) { parser := new(SpecParser) - conceptDictionary := new(ConceptDictionary) - specText := SpecBuilder().specHeading("A spec heading"). scenarioHeading("First scenario"). - step("create user \"456\" \"foo\" and \"prateek\""). + step("create user \"456\" \"foo\" and \"123456\""). String() - conceptText := SpecBuilder(). - specHeading("assign id and name "). - step("add id \"some-id\""). - step("second nested \"s-value\""). - specHeading("create user and "). - step("assign id and name \"static-name\""). - specHeading("second nested "). - step("add id ").String() + conceptDictionary := NewConceptDictionary() + path, _ := filepath.Abs(filepath.Join("testdata", "static_param_concept.cpt")) + AddConcepts(path, conceptDictionary) - concepts, _ := new(ConceptParser).Parse(conceptText) - - conceptDictionary.Add(concepts, "file.cpt") spec, _ := parser.Parse(specText, conceptDictionary) concept1 := spec.Scenarios[0].Steps[0] @@ -188,86 +164,31 @@ func (s *MySuite) TestPopulatingNestedConceptsWithStaticParametersLookup(c *C) { c.Assert(concept1.getArg("user-id").Value, Equals, "456") c.Assert(concept1.getArg("user-name").Value, Equals, "foo") - c.Assert(concept1.getArg("user-phone").Value, Equals, "prateek") + c.Assert(concept1.getArg("user-phone").Value, Equals, "123456") nestedConcept := concept1.ConceptSteps[0] c.Assert(nestedConcept.getArg("userid").Value, Equals, "456") - c.Assert(nestedConcept.getArg("username").Value, Equals, "static-name") - - c.Assert(nestedConcept.ConceptSteps[0].Args[0].ArgType, Equals, Static) - c.Assert(nestedConcept.ConceptSteps[0].Args[0].Value, Equals, "some-id") - - secondLevelNestedConcept := nestedConcept.ConceptSteps[1] - c.Assert(secondLevelNestedConcept.getArg("baz").Value, Equals, "s-value") - c.Assert(secondLevelNestedConcept.getArg("baz").ArgType, Equals, Static) + c.Assert(nestedConcept.getArg("username").Value, Equals, "static-value") } func (s *MySuite) TestEachConceptUsageIsUpdatedWithRespectiveParams(c *C) { parser := new(SpecParser) - conceptDictionary := new(ConceptDictionary) - - specText := SpecBuilder().specHeading("A spec heading"). - scenarioHeading("First scenario"). - step("Concept"). - String() - - conceptText := SpecBuilder(). - specHeading("Concept"). - step("Heading \"a\""). - step("Heading \"b\""). - specHeading("Heading "). - step("Say to ").String() - - concepts, _ := new(ConceptParser).Parse(conceptText) - - conceptDictionary.Add(concepts, "file.cpt") - spec, _ := parser.Parse(specText, conceptDictionary) - concept1 := spec.Scenarios[0].Steps[0] - - nestedConcept := concept1.ConceptSteps[0] - nestedConcept1 := concept1.ConceptSteps[1] - - c.Assert(nestedConcept.getArg("h").Value, Equals, "a") - c.Assert(nestedConcept1.getArg("h").Value, Equals, "b") -} - -func (s *MySuite) TestEachConceptUsageIsUpdatedWithRespectiveParamsIncludingDynamicParams(c *C) { - parser := new(SpecParser) - conceptDictionary := new(ConceptDictionary) - specText := SpecBuilder().specHeading("A spec heading"). scenarioHeading("First scenario"). - step("Concept \"abc\""). + step("create user \"sdf\" \"name\" and \"1234\""). String() - conceptText := SpecBuilder(). - specHeading("Concept "). - step("Heading \"a\" and \"a\""). - step("Heading \"b\" and \"b\""). - step("Heading and \"a\""). - step("Heading \"c\" and \"a\""). - specHeading("Heading and "). - step("Say to ").String() - - concepts, _ := new(ConceptParser).Parse(conceptText) - - conceptDictionary.Add(concepts, "file.cpt") + conceptDictionary := NewConceptDictionary() + path, _ := filepath.Abs(filepath.Join("testdata", "static_param_concept.cpt")) + AddConcepts(path, conceptDictionary) spec, _ := parser.Parse(specText, conceptDictionary) concept1 := spec.Scenarios[0].Steps[0] nestedConcept := concept1.ConceptSteps[0] - c.Assert(nestedConcept.getArg("h").Value, Equals, "a") - c.Assert(nestedConcept.getArg("i").Value, Equals, "a") - nestedConcept1 := concept1.ConceptSteps[1] - c.Assert(nestedConcept1.getArg("h").Value, Equals, "b") - c.Assert(nestedConcept1.getArg("i").Value, Equals, "b") - - nestedConcept2 := concept1.ConceptSteps[2] - c.Assert(nestedConcept2.getArg("h").Value, Equals, "abc") - c.Assert(nestedConcept2.getArg("i").Value, Equals, "a") - nestedConcept3 := concept1.ConceptSteps[3] - c.Assert(nestedConcept3.getArg("h").Value, Equals, "c") - c.Assert(nestedConcept3.getArg("i").Value, Equals, "a") + c.Assert(nestedConcept.getArg("username").Value, Equals, "static-value") + c.Assert(nestedConcept1.getArg("username").Value, Equals, "static-value1") + c.Assert(nestedConcept.getArg("userid").Value, Equals, "sdf") + c.Assert(nestedConcept1.getArg("userid").Value, Equals, "sdf") } diff --git a/parser/specification_test.go b/parser/specification_test.go index 746d93d8f..9dca978c0 100644 --- a/parser/specification_test.go +++ b/parser/specification_test.go @@ -18,6 +18,8 @@ package parser import ( + "path/filepath" + "github.com/getgauge/gauge/gauge_messages" "github.com/golang/protobuf/proto" . "gopkg.in/check.v1" @@ -563,58 +565,57 @@ func (s *MySuite) TestCreateStepFromSimpleConcept(c *C) { tokens := []*Token{ &Token{Kind: SpecKind, Value: "Spec Heading", LineNo: 1}, &Token{Kind: ScenarioKind, Value: "Scenario Heading", LineNo: 2}, - &Token{Kind: StepKind, Value: "concept step", LineNo: 3}, + &Token{Kind: StepKind, Value: "test concept step 1", LineNo: 3}, } - conceptDictionary := new(ConceptDictionary) - firstStep := &Step{Value: "step 1"} - secondStep := &Step{Value: "step 2"} - conceptStep := &Step{Value: "concept step", IsConcept: true, ConceptSteps: []*Step{firstStep, secondStep}} - conceptDictionary.Add([]*Step{conceptStep}, "file.cpt") + conceptDictionary := NewConceptDictionary() + path, _ := filepath.Abs(filepath.Join("testdata", "concept.cpt")) + AddConcepts(path, conceptDictionary) spec, result := new(SpecParser).CreateSpecification(tokens, conceptDictionary) c.Assert(result.Ok, Equals, true) c.Assert(len(spec.Scenarios[0].Steps), Equals, 1) specConceptStep := spec.Scenarios[0].Steps[0] c.Assert(specConceptStep.IsConcept, Equals, true) - c.Assert(specConceptStep.ConceptSteps[0], Equals, firstStep) - c.Assert(specConceptStep.ConceptSteps[1], Equals, secondStep) + assertStepEqual(c, &Step{LineNo: 2, Value: "step 1", LineText: "step 1"}, specConceptStep.ConceptSteps[0]) } func (s *MySuite) TestCreateStepFromConceptWithParameters(c *C) { tokens := []*Token{ &Token{Kind: SpecKind, Value: "Spec Heading", LineNo: 1}, &Token{Kind: ScenarioKind, Value: "Scenario Heading", LineNo: 2}, - &Token{Kind: StepKind, Value: "create user {static}", Args: []string{"foo"}, LineNo: 3}, - &Token{Kind: StepKind, Value: "create user {static}", Args: []string{"bar"}, LineNo: 4}, + &Token{Kind: StepKind, Value: "assign id {static} and name {static}", Args: []string{"foo", "foo1"}, LineNo: 3}, + &Token{Kind: StepKind, Value: "assign id {static} and name {static}", Args: []string{"bar", "bar1"}, LineNo: 4}, } - concepts, _ := new(ConceptParser).Parse("#create user \n * enter user \n *select \"finish\"") - conceptsDictionary := new(ConceptDictionary) - conceptsDictionary.Add(concepts, "file.cpt") + conceptDictionary := NewConceptDictionary() + path, _ := filepath.Abs(filepath.Join("testdata", "dynamic_param_concept.cpt")) + AddConcepts(path, conceptDictionary) - spec, result := new(SpecParser).CreateSpecification(tokens, conceptsDictionary) + spec, result := new(SpecParser).CreateSpecification(tokens, conceptDictionary) c.Assert(result.Ok, Equals, true) c.Assert(len(spec.Scenarios[0].Steps), Equals, 2) firstConceptStep := spec.Scenarios[0].Steps[0] c.Assert(firstConceptStep.IsConcept, Equals, true) - c.Assert(firstConceptStep.ConceptSteps[0].Value, Equals, "enter user {}") - c.Assert(firstConceptStep.ConceptSteps[0].Args[0].Value, Equals, "username") - c.Assert(firstConceptStep.ConceptSteps[1].Value, Equals, "select {}") - c.Assert(firstConceptStep.ConceptSteps[1].Args[0].Value, Equals, "finish") - c.Assert(len(firstConceptStep.Lookup.paramValue), Equals, 1) - c.Assert(firstConceptStep.getArg("username").Value, Equals, "foo") + c.Assert(firstConceptStep.ConceptSteps[0].Value, Equals, "add id {}") + c.Assert(firstConceptStep.ConceptSteps[0].Args[0].Value, Equals, "userid") + c.Assert(firstConceptStep.ConceptSteps[1].Value, Equals, "add name {}") + c.Assert(firstConceptStep.ConceptSteps[1].Args[0].Value, Equals, "username") + c.Assert(len(firstConceptStep.Lookup.paramValue), Equals, 2) + c.Assert(firstConceptStep.getArg("username").Value, Equals, "foo1") + c.Assert(firstConceptStep.getArg("userid").Value, Equals, "foo") secondConceptStep := spec.Scenarios[0].Steps[1] c.Assert(secondConceptStep.IsConcept, Equals, true) - c.Assert(secondConceptStep.ConceptSteps[0].Value, Equals, "enter user {}") - c.Assert(secondConceptStep.ConceptSteps[0].Args[0].Value, Equals, "username") - c.Assert(secondConceptStep.ConceptSteps[1].Value, Equals, "select {}") - c.Assert(secondConceptStep.ConceptSteps[1].Args[0].Value, Equals, "finish") - c.Assert(len(secondConceptStep.Lookup.paramValue), Equals, 1) - c.Assert(secondConceptStep.getArg("username").Value, Equals, "bar") + c.Assert(secondConceptStep.ConceptSteps[0].Value, Equals, "add id {}") + c.Assert(secondConceptStep.ConceptSteps[0].Args[0].Value, Equals, "userid") + c.Assert(secondConceptStep.ConceptSteps[1].Value, Equals, "add name {}") + c.Assert(secondConceptStep.ConceptSteps[1].Args[0].Value, Equals, "username") + c.Assert(len(secondConceptStep.Lookup.paramValue), Equals, 2) + c.Assert(secondConceptStep.getArg("username").Value, Equals, "bar1") + c.Assert(secondConceptStep.getArg("userid").Value, Equals, "bar") } @@ -624,14 +625,13 @@ func (s *MySuite) TestCreateStepFromConceptWithDynamicParameters(c *C) { &Token{Kind: TableHeader, Args: []string{"id", "description"}, LineNo: 2}, &Token{Kind: TableRow, Args: []string{"123", "Admin fellow"}, LineNo: 3}, &Token{Kind: ScenarioKind, Value: "Scenario Heading", LineNo: 4}, - &Token{Kind: StepKind, Value: "create user {dynamic} and {dynamic}", Args: []string{"id", "description"}, LineNo: 5}, - &Token{Kind: StepKind, Value: "create user {static} and {static}", Args: []string{"456", "Regular fellow"}, LineNo: 6}, + &Token{Kind: StepKind, Value: "assign id {dynamic} and name {dynamic}", Args: []string{"id", "description"}, LineNo: 5}, } - concepts, _ := new(ConceptParser).Parse("#create user and \n * enter user and \n *select \"finish\"") - conceptsDictionary := new(ConceptDictionary) - conceptsDictionary.Add(concepts, "file.cpt") - spec, result := new(SpecParser).CreateSpecification(tokens, conceptsDictionary) + conceptDictionary := NewConceptDictionary() + path, _ := filepath.Abs(filepath.Join("testdata", "dynamic_param_concept.cpt")) + AddConcepts(path, conceptDictionary) + spec, result := new(SpecParser).CreateSpecification(tokens, conceptDictionary) c.Assert(result.Ok, Equals, true) c.Assert(len(spec.Items), Equals, 2) @@ -640,77 +640,50 @@ func (s *MySuite) TestCreateStepFromConceptWithDynamicParameters(c *C) { scenarioItems := (spec.Items[1]).(*Scenario).Items c.Assert(scenarioItems[0], Equals, spec.Scenarios[0].Steps[0]) - c.Assert(scenarioItems[1], DeepEquals, spec.Scenarios[0].Steps[1]) - c.Assert(len(spec.Scenarios[0].Steps), Equals, 2) + c.Assert(len(spec.Scenarios[0].Steps), Equals, 1) firstConcept := spec.Scenarios[0].Steps[0] c.Assert(firstConcept.IsConcept, Equals, true) - c.Assert(firstConcept.ConceptSteps[0].Value, Equals, "enter user {} and {}") + c.Assert(firstConcept.ConceptSteps[0].Value, Equals, "add id {}") c.Assert(firstConcept.ConceptSteps[0].Args[0].ArgType, Equals, Dynamic) - c.Assert(firstConcept.ConceptSteps[0].Args[0].Value, Equals, "user-id") - c.Assert(firstConcept.ConceptSteps[0].Args[0].Name, Equals, "user-id") - c.Assert(firstConcept.ConceptSteps[0].Args[1].ArgType, Equals, Dynamic) - c.Assert(firstConcept.ConceptSteps[0].Args[1].Value, Equals, "user-description") - c.Assert(firstConcept.ConceptSteps[0].Args[1].Name, Equals, "user-description") - c.Assert(firstConcept.ConceptSteps[1].Value, Equals, "select {}") - c.Assert(firstConcept.ConceptSteps[1].Args[0].Value, Equals, "finish") - c.Assert(firstConcept.ConceptSteps[1].Args[0].ArgType, Equals, Static) + c.Assert(firstConcept.ConceptSteps[0].Args[0].Value, Equals, "userid") + c.Assert(firstConcept.ConceptSteps[1].Value, Equals, "add name {}") + c.Assert(firstConcept.ConceptSteps[1].Args[0].Value, Equals, "username") + c.Assert(firstConcept.ConceptSteps[1].Args[0].ArgType, Equals, Dynamic) c.Assert(len(firstConcept.Lookup.paramValue), Equals, 2) - arg1 := firstConcept.Lookup.getArg("user-id") + arg1 := firstConcept.Lookup.getArg("userid") c.Assert(arg1.Value, Equals, "id") c.Assert(arg1.ArgType, Equals, Dynamic) - arg2 := firstConcept.Lookup.getArg("user-description") + arg2 := firstConcept.Lookup.getArg("username") c.Assert(arg2.Value, Equals, "description") c.Assert(arg2.ArgType, Equals, Dynamic) - - secondConcept := spec.Scenarios[0].Steps[1] - c.Assert(secondConcept.IsConcept, Equals, true) - c.Assert(secondConcept.ConceptSteps[0].Value, Equals, "enter user {} and {}") - c.Assert(secondConcept.ConceptSteps[0].Args[0].ArgType, Equals, Dynamic) - c.Assert(secondConcept.ConceptSteps[0].Args[0].Value, Equals, "user-id") - c.Assert(secondConcept.ConceptSteps[0].Args[0].Name, Equals, "user-id") - c.Assert(secondConcept.ConceptSteps[0].Args[1].ArgType, Equals, Dynamic) - c.Assert(secondConcept.ConceptSteps[0].Args[1].Value, Equals, "user-description") - c.Assert(secondConcept.ConceptSteps[0].Args[1].Name, Equals, "user-description") - c.Assert(secondConcept.ConceptSteps[1].Value, Equals, "select {}") - c.Assert(secondConcept.ConceptSteps[1].Args[0].Value, Equals, "finish") - c.Assert(secondConcept.ConceptSteps[1].Args[0].ArgType, Equals, Static) - - c.Assert(len(secondConcept.Lookup.paramValue), Equals, 2) - arg1 = secondConcept.Lookup.getArg("user-id") - arg2 = secondConcept.Lookup.getArg("user-description") - c.Assert(arg1.Value, Equals, "456") - c.Assert(arg1.ArgType, Equals, Static) - c.Assert(arg2.Value, Equals, "Regular fellow") - c.Assert(arg2.ArgType, Equals, Static) - } func (s *MySuite) TestCreateStepFromConceptWithInlineTable(c *C) { tokens := []*Token{ &Token{Kind: SpecKind, Value: "Spec Heading", LineNo: 1}, &Token{Kind: ScenarioKind, Value: "Scenario Heading", LineNo: 4}, - &Token{Kind: StepKind, Value: "create users", LineNo: 3}, + &Token{Kind: StepKind, Value: "assign id {static} and name", Args: []string{"sdf"}, LineNo: 3}, &Token{Kind: TableHeader, Args: []string{"id", "description"}, LineNo: 4}, &Token{Kind: TableRow, Args: []string{"123", "Admin"}, LineNo: 5}, &Token{Kind: TableRow, Args: []string{"456", "normal fellow"}, LineNo: 6}, } - concepts, _ := new(ConceptParser).Parse("#create users \n * enter details from
\n *select \"finish\"") - conceptsDictionary := new(ConceptDictionary) - conceptsDictionary.Add(concepts, "file.cpt") - spec, result := new(SpecParser).CreateSpecification(tokens, conceptsDictionary) + conceptDictionary := NewConceptDictionary() + path, _ := filepath.Abs(filepath.Join("testdata", "dynamic_param_concept.cpt")) + AddConcepts(path, conceptDictionary) + spec, result := new(SpecParser).CreateSpecification(tokens, conceptDictionary) c.Assert(result.Ok, Equals, true) steps := spec.Scenarios[0].Steps c.Assert(len(steps), Equals, 1) c.Assert(steps[0].IsConcept, Equals, true) - c.Assert(steps[0].Value, Equals, "create users {}") - c.Assert(len(steps[0].Args), Equals, 1) - c.Assert(steps[0].Args[0].ArgType, Equals, TableArg) + c.Assert(steps[0].Value, Equals, "assign id {} and name {}") + c.Assert(len(steps[0].Args), Equals, 2) + c.Assert(steps[0].Args[1].ArgType, Equals, TableArg) c.Assert(len(steps[0].ConceptSteps), Equals, 2) } @@ -721,28 +694,24 @@ func (s *MySuite) TestCreateStepFromConceptWithInlineTableHavingDynamicParam(c * &Token{Kind: TableRow, Args: []string{"123", "Admin"}, LineNo: 3}, &Token{Kind: TableRow, Args: []string{"456", "normal fellow"}, LineNo: 4}, &Token{Kind: ScenarioKind, Value: "Scenario Heading", LineNo: 5}, - &Token{Kind: StepKind, Value: "create users", LineNo: 6}, + &Token{Kind: StepKind, Value: "assign id {static} and name", Args: []string{"sdf"}, LineNo: 6}, &Token{Kind: TableHeader, Args: []string{"user-id", "description", "name"}, LineNo: 7}, &Token{Kind: TableRow, Args: []string{"", "", "root"}, LineNo: 8}, - &Token{Kind: StepKind, Value: "create users", LineNo: 9}, - &Token{Kind: TableHeader, Args: []string{"user-id", "description", "name"}, LineNo: 10}, - &Token{Kind: TableRow, Args: []string{"1", "normal", "wheel"}, LineNo: 11}, } - concepts, _ := new(ConceptParser).Parse("#create users \n * enter details from \n *select \"finish\"") - conceptsDictionary := new(ConceptDictionary) - conceptsDictionary.Add(concepts, "file.cpt") - spec, result := new(SpecParser).CreateSpecification(tokens, conceptsDictionary) + conceptDictionary := NewConceptDictionary() + path, _ := filepath.Abs(filepath.Join("testdata", "dynamic_param_concept.cpt")) + AddConcepts(path, conceptDictionary) + spec, result := new(SpecParser).CreateSpecification(tokens, conceptDictionary) c.Assert(result.Ok, Equals, true) steps := spec.Scenarios[0].Steps - c.Assert(len(steps), Equals, 2) + c.Assert(len(steps), Equals, 1) c.Assert(steps[0].IsConcept, Equals, true) - c.Assert(steps[1].IsConcept, Equals, true) - c.Assert(steps[0].Value, Equals, "create users {}") - c.Assert(len(steps[0].Args), Equals, 1) - c.Assert(steps[0].Args[0].ArgType, Equals, TableArg) - table := steps[0].Args[0].Table + c.Assert(steps[0].Value, Equals, "assign id {} and name {}") + c.Assert(len(steps[0].Args), Equals, 2) + c.Assert(steps[0].Args[1].ArgType, Equals, TableArg) + table := steps[0].Args[1].Table c.Assert(table.Get("user-id")[0].Value, Equals, "id") c.Assert(table.Get("user-id")[0].CellType, Equals, Dynamic) c.Assert(table.Get("description")[0].Value, Equals, "description") @@ -880,43 +849,43 @@ func (s *MySuite) TestUpdatePropertiesFromAnotherConcept(c *C) { } func (s *MySuite) TestCreateConceptStep(c *C) { - conceptText := SpecBuilder(). - specHeading("concept with "). - step("nested concept with "). - specHeading("nested concept with "). - step("nested concept step wiht ").String() - concepts, _ := new(ConceptParser).Parse(conceptText) - - dictionary := new(ConceptDictionary) - dictionary.Add(concepts, "file.cpt") + dictionary := NewConceptDictionary() + path, _ := filepath.Abs(filepath.Join("testdata", "param_nested_concept.cpt")) + AddConcepts(path, dictionary) - argsInStep := []*StepArg{&StepArg{Name: "arg1", Value: "value", ArgType: Static}} + argsInStep := []*StepArg{&StepArg{Name: "bar", Value: "first name", ArgType: Static}, &StepArg{Name: "far", Value: "last name", ArgType: Static}} originalStep := &Step{ LineNo: 12, - Value: "concept with {}", - LineText: "concept with \"value\"", + Value: "create user {} {}", + LineText: "create user \"first name\" \"last name\"", Args: argsInStep, - IsConcept: true, + IsConcept: false, HasInlineTable: false} - new(Specification).createConceptStep(dictionary.search("concept with {}").ConceptStep, originalStep) + + new(Specification).createConceptStep(dictionary.search("create user {} {}").ConceptStep, originalStep) + c.Assert(originalStep.IsConcept, Equals, true) c.Assert(len(originalStep.ConceptSteps), Equals, 1) - c.Assert(originalStep.Args[0].Value, Equals, "value") - - c.Assert(originalStep.Lookup.getArg("foo").Value, Equals, "value") + c.Assert(originalStep.Args[0].Value, Equals, "first name") + c.Assert(originalStep.Lookup.getArg("bar").Value, Equals, "first name") + c.Assert(originalStep.Args[1].Value, Equals, "last name") + c.Assert(originalStep.Lookup.getArg("far").Value, Equals, "last name") nestedConcept := originalStep.ConceptSteps[0] c.Assert(nestedConcept.IsConcept, Equals, true) c.Assert(len(nestedConcept.ConceptSteps), Equals, 1) c.Assert(nestedConcept.Args[0].ArgType, Equals, Dynamic) - c.Assert(nestedConcept.Args[0].Value, Equals, "foo") + c.Assert(nestedConcept.Args[0].Name, Equals, "bar") + + c.Assert(nestedConcept.Args[1].ArgType, Equals, Dynamic) + c.Assert(nestedConcept.Args[1].Name, Equals, "far") c.Assert(nestedConcept.ConceptSteps[0].Args[0].ArgType, Equals, Dynamic) - c.Assert(nestedConcept.ConceptSteps[0].Args[0].Value, Equals, "baz") + c.Assert(nestedConcept.ConceptSteps[0].Args[0].Name, Equals, "baz") c.Assert(nestedConcept.Lookup.getArg("baz").ArgType, Equals, Dynamic) - c.Assert(nestedConcept.Lookup.getArg("baz").Value, Equals, "foo") + c.Assert(nestedConcept.Lookup.getArg("baz").Value, Equals, "bar") } func (s *MySuite) TestRenameStep(c *C) { diff --git a/parser/specparser_test.go b/parser/specparser_test.go index 0576f9b54..cb56e0555 100644 --- a/parser/specparser_test.go +++ b/parser/specparser_test.go @@ -18,8 +18,10 @@ package parser import ( - . "gopkg.in/check.v1" + "path/filepath" "testing" + + . "gopkg.in/check.v1" ) // Hook up gocheck into the "go test" runner. @@ -541,15 +543,13 @@ func (s *MySuite) TestParsingSpecWithTearDownSteps(c *C) { func (s *MySuite) TestParsingConceptInSpec(c *C) { parser := new(SpecParser) - conceptDictionary := new(ConceptDictionary) specText := SpecBuilder().specHeading("A spec heading"). scenarioHeading("First flow"). - step("concept step"). + step("test concept step 1"). step("another step").String() - step1 := &Step{Value: "step 1"} - step2 := &Step{Value: "step 2"} - concept1 := &Step{Value: "concept step", ConceptSteps: []*Step{step1, step2}, IsConcept: true} - err := conceptDictionary.Add([]*Step{concept1}, "file.cpt") + conceptDictionary := NewConceptDictionary() + path, _ := filepath.Abs(filepath.Join("testdata", "concept.cpt")) + AddConcepts(path, conceptDictionary) tokens, err := parser.GenerateTokens(specText) c.Assert(err, IsNil) spec, parseResult := parser.CreateSpecification(tokens, conceptDictionary) @@ -558,7 +558,6 @@ func (s *MySuite) TestParsingConceptInSpec(c *C) { firstStepInSpec := spec.Scenarios[0].Steps[0] secondStepInSpec := spec.Scenarios[0].Steps[1] c.Assert(firstStepInSpec.ConceptSteps[0].Parent, Equals, firstStepInSpec) - c.Assert(firstStepInSpec.ConceptSteps[1].Parent, Equals, firstStepInSpec) c.Assert(firstStepInSpec.Parent, IsNil) c.Assert(secondStepInSpec.Parent, IsNil) } diff --git a/parser/testdata/circular_concept.cpt b/parser/testdata/circular_concept.cpt new file mode 100644 index 000000000..689171f4d --- /dev/null +++ b/parser/testdata/circular_concept.cpt @@ -0,0 +1,8 @@ +# test concept step 1 +* test concept step 2 + +# test concept step 2 +* test concept step 3 + +# test concept step 3 +* test concept step 1 diff --git a/parser/testdata/concept.cpt b/parser/testdata/concept.cpt new file mode 100644 index 000000000..a639c6c3f --- /dev/null +++ b/parser/testdata/concept.cpt @@ -0,0 +1,5 @@ +# test concept step 1 +* step 1 + +# test concept step 2 +* step 2 diff --git a/parser/testdata/duplicate_concept.cpt b/parser/testdata/duplicate_concept.cpt new file mode 100644 index 000000000..91a760999 --- /dev/null +++ b/parser/testdata/duplicate_concept.cpt @@ -0,0 +1,5 @@ +# test concept step 1 +* step 1 + +# test concept step 1 +* step 2 diff --git a/parser/testdata/dynamic_param_concept.cpt b/parser/testdata/dynamic_param_concept.cpt new file mode 100644 index 000000000..8f4b58531 --- /dev/null +++ b/parser/testdata/dynamic_param_concept.cpt @@ -0,0 +1,7 @@ +# create user and +* assign id and name +Comments +# assign id and name +* add id +* add name +Comment1 diff --git a/parser/testdata/nested_concept.cpt b/parser/testdata/nested_concept.cpt new file mode 100644 index 000000000..b80095a06 --- /dev/null +++ b/parser/testdata/nested_concept.cpt @@ -0,0 +1,5 @@ +# test concept step 1 +* test concept step 2 + +# test concept step 2 +* step 2 diff --git a/parser/testdata/nested_concept2.cpt b/parser/testdata/nested_concept2.cpt new file mode 100644 index 000000000..ab6cc097d --- /dev/null +++ b/parser/testdata/nested_concept2.cpt @@ -0,0 +1,10 @@ +# top level concept +* nested concept +* normal step 1 + +# another nested concept +* normal step 3 + +# nested concept +* another nested concept +* normal step 2 diff --git a/parser/testdata/param_nested_concept.cpt b/parser/testdata/param_nested_concept.cpt new file mode 100644 index 000000000..eaaa1f562 --- /dev/null +++ b/parser/testdata/param_nested_concept.cpt @@ -0,0 +1,5 @@ +# create user +* assign role + +# assign role +* add admin rights diff --git a/parser/testdata/param_nested_concept2.cpt b/parser/testdata/param_nested_concept2.cpt new file mode 100644 index 000000000..ffab68a7f --- /dev/null +++ b/parser/testdata/param_nested_concept2.cpt @@ -0,0 +1,6 @@ +# create user and +* assign id and name + +# assign id and name +* add id +* add name diff --git a/parser/testdata/static_param_concept.cpt b/parser/testdata/static_param_concept.cpt new file mode 100644 index 000000000..29346b566 --- /dev/null +++ b/parser/testdata/static_param_concept.cpt @@ -0,0 +1,7 @@ +# create user and +* assign id and name "static-value" +* assign id and name "static-value1" + +# assign id and name +* add id +* add name diff --git a/parser/testdata/tabular_concept.cpt b/parser/testdata/tabular_concept.cpt new file mode 100644 index 000000000..ecc04ad63 --- /dev/null +++ b/parser/testdata/tabular_concept.cpt @@ -0,0 +1,7 @@ +COMMENT +# my concept +* first step with and inline table + |id|name | + |1 |gauge | + |2 |mingle| + comment diff --git a/refactor/refactor_test.go b/refactor/refactor_test.go index bc45b840e..6ef759005 100644 --- a/refactor/refactor_test.go +++ b/refactor/refactor_test.go @@ -18,9 +18,10 @@ package refactor import ( + "testing" + "github.com/getgauge/gauge/parser" . "gopkg.in/check.v1" - "testing" ) func Test(t *testing.T) { TestingT(t) } @@ -118,10 +119,12 @@ func (s *MySuite) TestRefactoringOfStepsWithNoArgsInConceptFiles(c *C) { spec, _ := new(parser.SpecParser).CreateSpecification(tokens, new(parser.ConceptDictionary)) agent, _ := getRefactorAgent(oldStep, newStep, nil) specs := append(make([]*parser.Specification, 0), spec) - dictionary := new(parser.ConceptDictionary) + dictionary := parser.NewConceptDictionary() step1 := &parser.Step{Value: oldStep + "sdsf", IsConcept: true} step2 := &parser.Step{Value: unchanged, IsConcept: true, Items: []parser.Item{&parser.Step{Value: oldStep, IsConcept: false}, &parser.Step{Value: oldStep + "T", IsConcept: false}}} - dictionary.Add([]*parser.Step{step1, step2}, "file.cpt") + + dictionary.ConceptsMap[step1.Value] = &parser.Concept{ConceptStep: step1, FileName: "file.cpt"} + dictionary.ConceptsMap[step2.Value] = &parser.Concept{ConceptStep: step2, FileName: "file.cpt"} agent.rephraseInSpecsAndConcepts(&specs, dictionary) @@ -164,13 +167,14 @@ func (s *MySuite) TestRefactoringGivesOnlyThoseConceptFilesWhichAreRefactored(c spec, _ := new(parser.SpecParser).CreateSpecification(tokens, new(parser.ConceptDictionary)) agent, _ := getRefactorAgent(oldStep, newStep, nil) specs := append(make([]*parser.Specification, 0), spec) - dictionary := new(parser.ConceptDictionary) + dictionary := parser.NewConceptDictionary() step1 := &parser.Step{Value: oldStep + "sdsf", IsConcept: true} step2 := &parser.Step{Value: unchanged, IsConcept: true, Items: []parser.Item{&parser.Step{Value: newStep, IsConcept: false}, &parser.Step{Value: oldStep + "T", IsConcept: false}}} step3 := &parser.Step{Value: "Concept value", IsConcept: true, Items: []parser.Item{&parser.Step{Value: oldStep, IsConcept: false}, &parser.Step{Value: oldStep + "T", IsConcept: false}}} fileName := "file.cpt" - dictionary.Add([]*parser.Step{step1, step2}, fileName) - dictionary.Add([]*parser.Step{step3}, "e"+fileName) + dictionary.ConceptsMap[step1.Value] = &parser.Concept{ConceptStep: step1, FileName: fileName} + dictionary.ConceptsMap[step2.Value] = &parser.Concept{ConceptStep: step2, FileName: fileName} + dictionary.ConceptsMap[step3.Value] = &parser.Concept{ConceptStep: step3, FileName: "e" + fileName} _, filesRefactored := agent.rephraseInSpecsAndConcepts(&specs, dictionary)