本文整理匯總了Golang中github.com/getgauge/gauge/gauge.NewConceptDictionary函數的典型用法代碼示例。如果您正苦於以下問題:Golang NewConceptDictionary函數的具體用法?Golang NewConceptDictionary怎麽用?Golang NewConceptDictionary使用的例子?那麽, 這裏精選的函數代碼示例或許可以為您提供幫助。
在下文中一共展示了NewConceptDictionary函數的15個代碼示例,這些例子默認根據受歡迎程度排序。您可以為喜歡或者感覺有用的代碼點讚,您的評價將有助於係統推薦出更棒的Golang代碼示例。
示例1: TestToFilterSpecsByWrongTagExpression
func (s *MySuite) TestToFilterSpecsByWrongTagExpression(c *C) {
myTags := []string{"tag1", "tag2"}
tokens := []*parser.Token{
&parser.Token{Kind: gauge.SpecKind, Value: "Spec Heading1", LineNo: 1},
&parser.Token{Kind: gauge.TagKind, Args: myTags, LineNo: 2},
&parser.Token{Kind: gauge.ScenarioKind, Value: "Scenario Heading 1", LineNo: 3},
&parser.Token{Kind: gauge.ScenarioKind, Value: "Scenario Heading 2", LineNo: 4},
}
spec1, result := new(parser.SpecParser).CreateSpecification(tokens, gauge.NewConceptDictionary())
c.Assert(result.Ok, Equals, true)
tokens1 := []*parser.Token{
&parser.Token{Kind: gauge.SpecKind, Value: "Spec Heading2", LineNo: 1},
&parser.Token{Kind: gauge.ScenarioKind, Value: "Scenario Heading 1", LineNo: 2},
&parser.Token{Kind: gauge.ScenarioKind, Value: "Scenario Heading 2", LineNo: 3},
}
spec2, result := new(parser.SpecParser).CreateSpecification(tokens1, gauge.NewConceptDictionary())
c.Assert(result.Ok, Equals, true)
var specs []*gauge.Specification
specs = append(specs, spec1)
specs = append(specs, spec2)
c.Assert(specs[0].Tags.Values[0], Equals, myTags[0])
c.Assert(specs[0].Tags.Values[1], Equals, myTags[1])
specs = filterSpecsByTags(specs, "(tag1 & tag2")
c.Assert(len(specs), Equals, 0)
}
示例2: TestRefactoringGivesOnlyThoseConceptFilesWhichAreRefactored
func (s *MySuite) TestRefactoringGivesOnlyThoseConceptFilesWhichAreRefactored(c *C) {
oldStep := "first step"
newStep := "second step"
unchanged := "unchanged"
tokens := []*parser.Token{
&parser.Token{Kind: gauge.SpecKind, Value: "Spec Heading", LineNo: 1},
&parser.Token{Kind: gauge.ScenarioKind, Value: "Scenario Heading 1", LineNo: 20},
}
spec, _ := new(parser.SpecParser).CreateSpecification(tokens, gauge.NewConceptDictionary())
agent, _ := getRefactorAgent(oldStep, newStep, nil)
specs := append(make([]*gauge.Specification, 0), spec)
dictionary := gauge.NewConceptDictionary()
step1 := &gauge.Step{Value: oldStep + "sdsf", IsConcept: true}
step2 := &gauge.Step{Value: unchanged, IsConcept: true, Items: []gauge.Item{&gauge.Step{Value: newStep, IsConcept: false}, &gauge.Step{Value: oldStep + "T", IsConcept: false}}}
step3 := &gauge.Step{Value: "Concept value", IsConcept: true, Items: []gauge.Item{&gauge.Step{Value: oldStep, IsConcept: false}, &gauge.Step{Value: oldStep + "T", IsConcept: false}}}
fileName := "file.cpt"
dictionary.ConceptsMap[step1.Value] = &gauge.Concept{ConceptStep: step1, FileName: fileName}
dictionary.ConceptsMap[step2.Value] = &gauge.Concept{ConceptStep: step2, FileName: fileName}
dictionary.ConceptsMap[step3.Value] = &gauge.Concept{ConceptStep: step3, FileName: "e" + fileName}
_, filesRefactored := agent.rephraseInSpecsAndConcepts(&specs, dictionary)
c.Assert(filesRefactored[fileName], Equals, false)
c.Assert(filesRefactored["e"+fileName], Equals, true)
}
示例3: TestToEvaluateTagExpression
func (s *MySuite) TestToEvaluateTagExpression(c *C) {
myTags := []string{"tag1", "tag2"}
tokens := []*parser.Token{
&parser.Token{Kind: gauge.SpecKind, Value: "Spec Heading1", LineNo: 1},
&parser.Token{Kind: gauge.ScenarioKind, Value: "Scenario Heading 01", LineNo: 2},
&parser.Token{Kind: gauge.TagKind, Args: []string{"tag1"}, LineNo: 3},
&parser.Token{Kind: gauge.ScenarioKind, Value: "Scenario Heading 02", LineNo: 4},
&parser.Token{Kind: gauge.TagKind, Args: []string{"tag3"}, LineNo: 5},
}
spec1, result := new(parser.SpecParser).CreateSpecification(tokens, gauge.NewConceptDictionary())
c.Assert(result.Ok, Equals, true)
tokens1 := []*parser.Token{
&parser.Token{Kind: gauge.SpecKind, Value: "Spec Heading2", LineNo: 1},
&parser.Token{Kind: gauge.TagKind, Args: myTags, LineNo: 2},
&parser.Token{Kind: gauge.ScenarioKind, Value: "Scenario Heading 1", LineNo: 3},
&parser.Token{Kind: gauge.ScenarioKind, Value: "Scenario Heading 2", LineNo: 4},
}
spec2, result := new(parser.SpecParser).CreateSpecification(tokens1, gauge.NewConceptDictionary())
c.Assert(result.Ok, Equals, true)
var specs []*gauge.Specification
specs = append(specs, spec1)
specs = append(specs, spec2)
specs = filterSpecsByTags(specs, "tag1 & !(tag1 & tag4) & (tag2 | tag3)")
c.Assert(len(specs), Equals, 1)
c.Assert(len(specs[0].Scenarios), Equals, 2)
c.Assert(specs[0].Scenarios[0].Heading.Value, Equals, "Scenario Heading 1")
c.Assert(specs[0].Scenarios[1].Heading.Value, Equals, "Scenario Heading 2")
}
示例4: TestRefactoringOfStepsWithNoArgsAndWithMoreThanOneSpec
func (s *MySuite) TestRefactoringOfStepsWithNoArgsAndWithMoreThanOneSpec(c *C) {
oldStep := " first step"
newStep := "second step"
tokens := []*parser.Token{
&parser.Token{Kind: gauge.SpecKind, Value: "Spec Heading", LineNo: 1},
&parser.Token{Kind: gauge.ScenarioKind, Value: "Scenario Heading", LineNo: 2},
&parser.Token{Kind: gauge.StepKind, Value: oldStep, LineNo: 3},
}
spec, _ := new(parser.SpecParser).CreateSpecification(tokens, gauge.NewConceptDictionary())
tokens = []*parser.Token{
&parser.Token{Kind: gauge.SpecKind, Value: "Spec Heading", LineNo: 10},
&parser.Token{Kind: gauge.ScenarioKind, Value: "Scenario Heading", LineNo: 20},
&parser.Token{Kind: gauge.StepKind, Value: oldStep, LineNo: 30},
}
spec1, _ := new(parser.SpecParser).CreateSpecification(tokens, gauge.NewConceptDictionary())
specs := append(make([]*gauge.Specification, 0), spec)
specs = append(specs, spec1)
agent, err := getRefactorAgent(oldStep, newStep, nil)
specRefactored, _ := agent.rephraseInSpecsAndConcepts(&specs, gauge.NewConceptDictionary())
for _, isRefactored := range specRefactored {
c.Assert(true, Equals, isRefactored)
}
c.Assert(err, Equals, nil)
c.Assert(len(specs[0].Scenarios[0].Steps), Equals, 1)
c.Assert(specs[0].Scenarios[0].Steps[0].Value, Equals, newStep)
c.Assert(len(specs[1].Scenarios[0].Steps), Equals, 1)
c.Assert(specs[1].Scenarios[0].Steps[0].Value, Equals, newStep)
}
示例5: TestFormatSpecificationWithTags
func (s *MySuite) TestFormatSpecificationWithTags(c *C) {
tokens := []*parser.Token{
&parser.Token{Kind: gauge.SpecKind, Value: "My Spec Heading", LineNo: 1},
&parser.Token{Kind: gauge.TagKind, Args: []string{"tag1", "tag2"}, LineNo: 2},
&parser.Token{Kind: gauge.ScenarioKind, Value: "Scenario Heading", LineNo: 3},
&parser.Token{Kind: gauge.TagKind, Args: []string{"tag3", "tag4"}, LineNo: 4},
&parser.Token{Kind: gauge.StepKind, Value: "Example step", LineNo: 5, LineText: "Example step"},
&parser.Token{Kind: gauge.ScenarioKind, Value: "Scenario Heading1", LineNo: 6},
&parser.Token{Kind: gauge.TagKind, Args: []string{"tag3", "tag4"}, LineNo: 7},
&parser.Token{Kind: gauge.StepKind, Value: "Example step", LineNo: 8, LineText: "Example step"},
}
spec, _ := new(parser.SpecParser).CreateSpecification(tokens, gauge.NewConceptDictionary())
formatted := FormatSpecification(spec)
c.Assert(formatted, Equals,
`My Spec Heading
===============
tags: tag1, tag2
Scenario Heading
----------------
tags: tag3, tag4
* Example step
Scenario Heading1
-----------------
tags: tag3, tag4
* Example step
`)
}
示例6: TestPopulatingNestedConceptsWithStaticParametersLookup
func (s *MySuite) TestPopulatingNestedConceptsWithStaticParametersLookup(c *C) {
parser := new(SpecParser)
specText := SpecBuilder().specHeading("A spec heading").
scenarioHeading("First scenario").
step("create user \"456\" \"foo\" and \"123456\"").
String()
conceptDictionary := gauge.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]
dataTableLookup := new(gauge.ArgLookup).FromDataTableRow(&spec.DataTable.Table, 0)
PopulateConceptDynamicParams(concept1, dataTableLookup)
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, "123456")
nestedConcept := concept1.ConceptSteps[0]
c.Assert(nestedConcept.GetArg("userid").Value, Equals, "456")
c.Assert(nestedConcept.GetArg("username").Value, Equals, "static-value")
}
示例7: TestCreateSkippedSpecResultWithScenarios
func (s *MySuite) TestCreateSkippedSpecResultWithScenarios(c *C) {
specText := SpecBuilder().specHeading("A spec heading").
scenarioHeading("First scenario").
step("create user \"456\" \"foo\" and \"9900\"").
String()
spec, _ := new(parser.SpecParser).Parse(specText, gauge.NewConceptDictionary())
spec.FileName = "FILE"
specExecutor := newSpecExecutor(spec, nil, nil, indexRange{start: 0, end: 0}, nil, nil)
specExecutor.errMap = &validationErrMaps{make(map[*gauge.Specification][]*stepValidationError), make(map[*gauge.Scenario][]*stepValidationError), make(map[*gauge.Step]*stepValidationError)}
specExecutor.consoleReporter = reporter.Current()
specExecutor.specResult = &result.SpecResult{ProtoSpec: &gauge_messages.ProtoSpec{}}
result := specExecutor.createSkippedSpecResult(fmt.Errorf("ERROR"))
c.Assert(result.IsFailed, Equals, false)
c.Assert(result.Skipped, Equals, true)
c.Assert(len(specExecutor.errMap.specErrs[spec]), Equals, 1)
c.Assert(specExecutor.errMap.specErrs[spec][0].Error(), Equals, "ERROR")
c.Assert(specExecutor.errMap.specErrs[spec][0].fileName, Equals, "FILE")
c.Assert(specExecutor.errMap.specErrs[spec][0].step.LineNo, Equals, 1)
c.Assert(specExecutor.errMap.specErrs[spec][0].step.LineText, Equals, "A spec heading")
c.Assert(len(specExecutor.errMap.scenarioErrs[spec.Scenarios[0]]), Equals, 1)
c.Assert(specExecutor.errMap.scenarioErrs[spec.Scenarios[0]][0].Error(), Equals, "ERROR")
c.Assert(specExecutor.errMap.scenarioErrs[spec.Scenarios[0]][0].fileName, Equals, "FILE")
c.Assert(specExecutor.errMap.scenarioErrs[spec.Scenarios[0]][0].step.LineNo, Equals, 1)
c.Assert(specExecutor.errMap.scenarioErrs[spec.Scenarios[0]][0].step.LineText, Equals, "A spec heading")
}
示例8: TestFormatSpecification
func (s *MySuite) TestFormatSpecification(c *C) {
tokens := []*parser.Token{
&parser.Token{Kind: gauge.SpecKind, Value: "Spec Heading", LineNo: 1},
&parser.Token{Kind: gauge.ScenarioKind, Value: "Scenario Heading", LineNo: 2},
&parser.Token{Kind: gauge.StepKind, Value: "Example step", LineNo: 3, LineText: "Example step"},
&parser.Token{Kind: gauge.StepKind, Value: "Step with inline table", LineNo: 3, LineText: "Step with inline table "},
&parser.Token{Kind: gauge.TableHeader, Args: []string{"id", "name"}},
&parser.Token{Kind: gauge.TableRow, Args: []string{"<1>", "foo"}},
&parser.Token{Kind: gauge.TableRow, Args: []string{"2", "bar"}},
}
spec, _ := new(parser.SpecParser).CreateSpecification(tokens, gauge.NewConceptDictionary())
formatted := FormatSpecification(spec)
c.Assert(formatted, Equals,
`Spec Heading
============
Scenario Heading
----------------
* Example step
* Step with inline table`+" "+`
|id |name|
|---|----|
|<1>|foo |
|2 |bar |
`)
}
示例9: TestMultiLevelConcept
func (s *MySuite) TestMultiLevelConcept(c *C) {
conceptDictionary := gauge.NewConceptDictionary()
path, _ := filepath.Abs(filepath.Join("testdata", "nested_concept2.cpt"))
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, "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 := 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, "normal step 3")
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, "normal step 3")
c.Assert(nestedConcept2.ConceptStep.ConceptSteps[1].Value, Equals, "normal step 2")
}
示例10: TestNestedConceptLooksUpDataTableArgs
func (s *MySuite) TestNestedConceptLooksUpDataTableArgs(c *C) {
parser := new(SpecParser)
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 <id> <name>").
step("another step").String()
dictionary := gauge.NewConceptDictionary()
path, _ := filepath.Abs(filepath.Join("testdata", "param_nested_concept.cpt"))
AddConcepts(path, dictionary)
tokens, _ := parser.GenerateTokens(specText)
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("bar").ArgType, Equals, gauge.Dynamic)
c.Assert(firstStepInSpec.GetArg("far").ArgType, Equals, gauge.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("baz").ArgType, Equals, gauge.Dynamic)
c.Assert(nestedConcept.GetArg("boo").ArgType, Equals, gauge.Dynamic)
c.Assert(nestedConcept.GetArg("baz").Value, Equals, "id")
c.Assert(nestedConcept.GetArg("boo").Value, Equals, "name")
}
示例11: TestConceptDictionaryWithNestedConceptsWithStaticParameters
func (s *MySuite) TestConceptDictionaryWithNestedConceptsWithStaticParameters(c *C) {
conceptDictionary := gauge.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, 2)
actualNestedConcept := concept.ConceptStep.ConceptSteps[0]
c.Assert(actualNestedConcept.IsConcept, Equals, true)
c.Assert(actualNestedConcept.Args[0].ArgType, Equals, gauge.Dynamic)
c.Assert(actualNestedConcept.Args[0].Value, Equals, "user-id")
c.Assert(actualNestedConcept.Args[1].ArgType, Equals, gauge.Static)
c.Assert(actualNestedConcept.Args[1].Value, Equals, "static-value")
c.Assert(actualNestedConcept.Lookup.GetArg("userid").Value, Equals, "user-id")
c.Assert(actualNestedConcept.Lookup.GetArg("userid").ArgType, Equals, gauge.Dynamic)
c.Assert(actualNestedConcept.Lookup.GetArg("username").Value, Equals, "static-value")
c.Assert(actualNestedConcept.Lookup.GetArg("username").ArgType, Equals, gauge.Static)
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, gauge.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, gauge.Dynamic)
c.Assert(actualNestedConcept.ConceptSteps[1].Args[0].Value, Equals, "username")
}
示例12: TestToFilterMultipleScenariosByMultipleTags
func (s *MySuite) TestToFilterMultipleScenariosByMultipleTags(c *C) {
myTags := []string{"tag1", "tag2"}
tokens := []*parser.Token{
&parser.Token{Kind: gauge.SpecKind, Value: "Spec Heading", LineNo: 1},
&parser.Token{Kind: gauge.ScenarioKind, Value: "Scenario Heading 1", LineNo: 2},
&parser.Token{Kind: gauge.TagKind, Args: []string{"tag1"}, LineNo: 3},
&parser.Token{Kind: gauge.ScenarioKind, Value: "Scenario Heading 2", LineNo: 4},
&parser.Token{Kind: gauge.TagKind, Args: myTags, LineNo: 5},
&parser.Token{Kind: gauge.ScenarioKind, Value: "Scenario Heading 3", LineNo: 6},
&parser.Token{Kind: gauge.TagKind, Args: myTags, LineNo: 7},
&parser.Token{Kind: gauge.ScenarioKind, Value: "Scenario Heading 4", LineNo: 8},
&parser.Token{Kind: gauge.TagKind, Args: []string{"prod", "tag7", "tag1", "tag2"}, LineNo: 9},
}
spec, result := new(parser.SpecParser).CreateSpecification(tokens, gauge.NewConceptDictionary())
c.Assert(result.Ok, Equals, true)
var specs []*gauge.Specification
specs = append(specs, spec)
c.Assert(len(specs[0].Scenarios), Equals, 4)
c.Assert(len(specs[0].Scenarios[0].Tags.Values), Equals, 1)
c.Assert(len(specs[0].Scenarios[1].Tags.Values), Equals, 2)
c.Assert(len(specs[0].Scenarios[2].Tags.Values), Equals, 2)
c.Assert(len(specs[0].Scenarios[3].Tags.Values), Equals, 4)
specs = filterSpecsByTags(specs, "tag1 & tag2")
c.Assert(len(specs[0].Scenarios), Equals, 3)
c.Assert(specs[0].Scenarios[0].Heading.Value, Equals, "Scenario Heading 2")
c.Assert(specs[0].Scenarios[1].Heading.Value, Equals, "Scenario Heading 3")
c.Assert(specs[0].Scenarios[2].Heading.Value, Equals, "Scenario Heading 4")
}
示例13: getParsedSpecs
func (s *SpecInfoGatherer) getParsedSpecs(specFiles []string) []*gauge.Specification {
if s.conceptDictionary == nil {
s.conceptDictionary = gauge.NewConceptDictionary()
}
parsedSpecs, parseResults := parser.ParseSpecFiles(specFiles, s.conceptDictionary)
s.handleParseFailures(parseResults)
return parsedSpecs
}
示例14: TestRenamingWhenNumberOfArgumentsAreSame
func (s *MySuite) TestRenamingWhenNumberOfArgumentsAreSame(c *C) {
oldStep := "first step {static} and {static}"
oldStep1 := "first step <a> and <b>"
newStep := "second step <a> and <b>"
tokens := []*parser.Token{
&parser.Token{Kind: gauge.SpecKind, Value: "Spec Heading", LineNo: 1},
&parser.Token{Kind: gauge.ScenarioKind, Value: "Scenario Heading 1", LineNo: 2},
&parser.Token{Kind: gauge.StepKind, Value: oldStep, LineNo: 3, Args: []string{"name", "address"}},
}
spec, _ := new(parser.SpecParser).CreateSpecification(tokens, gauge.NewConceptDictionary())
agent, _ := getRefactorAgent(oldStep1, newStep, nil)
specs := append(make([]*gauge.Specification, 0), spec)
dictionary := gauge.NewConceptDictionary()
agent.rephraseInSpecsAndConcepts(&specs, dictionary)
c.Assert(specs[0].Scenarios[0].Steps[0].Value, Equals, "second step {} and {}")
c.Assert(specs[0].Scenarios[0].Steps[0].Args[0].Value, Equals, "name")
c.Assert(specs[0].Scenarios[0].Steps[0].Args[1].Value, Equals, "address")
}
示例15: TestErrorOnCircularReferenceInConcept
func (s *MySuite) TestErrorOnCircularReferenceInConcept(c *C) {
dictionary := gauge.NewConceptDictionary()
path, _ := filepath.Abs(filepath.Join("testdata", "circular_concept.cpt"))
err := AddConcepts(path, dictionary)
c.Assert(err, NotNil)
c.Assert(true, Equals, strings.Contains(err.Message, "Circular reference found in concept"))
}