Exemplo n.º 1
0
func addArgsFromTable(concept *gauge.Step, conceptName *string, args []string) {
	for _, arg := range args {
		concept.Value += " {}"
		concept.Args = append(concept.Args, &gauge.StepArg{Value: arg, ArgType: gauge.Dynamic, Name: arg})
		*conceptName += fmt.Sprintf(" <%s>", arg)
	}
}
Exemplo n.º 2
0
// Creating a copy of the lookup and populating table values
func PopulateConceptDynamicParams(concept *gauge.Step, dataTableLookup *gauge.ArgLookup) {
	//If it is a top level concept
	if concept.Parent == nil {
		lookup := concept.Lookup.GetCopy()
		for key, _ := range lookup.ParamIndexMap {
			conceptLookupArg := lookup.GetArg(key)
			if conceptLookupArg.ArgType == gauge.Dynamic {
				resolvedArg := dataTableLookup.GetArg(conceptLookupArg.Value)
				lookup.AddArgValue(key, resolvedArg)
			}
		}
		concept.Lookup = *lookup
	}

	//Updating values inside the concept step as well
	newArgs := make([]*gauge.StepArg, 0)
	for _, arg := range concept.Args {
		if arg.ArgType == gauge.Dynamic {
			if concept.Parent != nil {
				newArgs = append(newArgs, concept.Parent.GetArg(arg.Value))
			} else {
				newArgs = append(newArgs, dataTableLookup.GetArg(arg.Value))
			}
		} else {
			newArgs = append(newArgs, arg)
		}
	}
	concept.Args = newArgs
	concept.PopulateFragments()
}
Exemplo n.º 3
0
func (self *extractor) handleTable(stepInConcept *gauge.Step, step *gauge_messages.Step) {
	stepInConcept.Value += " {}"
	specText := self.fileContent + step.GetTable()
	spec, result := new(parser.SpecParser).Parse(specText, &gauge.ConceptDictionary{})
	if !result.Ok {
		self.errors = append(self.errors, result.ParseError)
		return
	}
	stepArgs := []*gauge.StepArg{spec.Scenarios[0].Steps[0].Args[0]}
	self.addTableAsParam(step, stepArgs)
	stepInConcept.Args = append(stepInConcept.Args, stepArgs[0])
}
Exemplo n.º 4
0
func createConceptStep(spec *gauge.Specification, concept *gauge.Step, originalStep *gauge.Step) {
	stepCopy := concept.GetCopy()
	originalArgs := originalStep.Args
	originalStep.CopyFrom(stepCopy)
	originalStep.Args = originalArgs

	// set parent of all concept steps to be the current concept (referred as originalStep here)
	// this is used to fetch from parent's lookup when nested
	for _, conceptStep := range originalStep.ConceptSteps {
		conceptStep.Parent = originalStep
	}

	spec.PopulateConceptLookup(&originalStep.Lookup, concept.Args, originalStep.Args)
}
Exemplo n.º 5
0
func (parser *ConceptParser) processConceptHeading(token *Token) (*gauge.Step, *ParseDetailResult) {
	processStep(new(SpecParser), token)
	token.LineText = strings.TrimSpace(strings.TrimLeft(strings.TrimSpace(token.LineText), "#"))
	var concept *gauge.Step
	var parseDetails *ParseDetailResult
	concept, parseDetails = CreateStepUsingLookup(token, nil)
	if parseDetails != nil && parseDetails.Error != nil {
		return nil, parseDetails
	}
	if !parser.hasOnlyDynamicParams(concept) {
		parseDetails.Error = &ParseError{LineNo: token.LineNo, Message: "Concept heading can have only Dynamic Parameters"}
		return nil, parseDetails
	}

	concept.IsConcept = true
	parser.createConceptLookup(concept)
	concept.Items = append(concept.Items, concept)
	return concept, parseDetails
}
Exemplo n.º 6
0
func (paramResolver *ParamResolver) GetResolvedParams(step *gauge.Step, parent *gauge.Step, dataTableLookup *gauge.ArgLookup) []*gauge_messages.Parameter {
	parameters := make([]*gauge_messages.Parameter, 0)
	for _, arg := range step.Args {
		parameter := new(gauge_messages.Parameter)
		parameter.Name = proto.String(arg.Name)
		if arg.ArgType == gauge.Static {
			parameter.ParameterType = gauge_messages.Parameter_Static.Enum()
			parameter.Value = proto.String(arg.Value)
		} else if arg.ArgType == gauge.Dynamic {
			var resolvedArg *gauge.StepArg
			if parent != nil {
				resolvedArg = parent.GetArg(arg.Value)
			} else {
				resolvedArg = dataTableLookup.GetArg(arg.Value)
			}
			//In case a special table used in a concept, you will get a dynamic table value which has to be resolved from the concept lookup
			parameter.Name = proto.String(resolvedArg.Name)
			if resolvedArg.Table.IsInitialized() {
				parameter.ParameterType = gauge_messages.Parameter_Special_Table.Enum()
				parameter.Table = paramResolver.createProtoStepTable(&resolvedArg.Table, dataTableLookup)
			} else {
				parameter.ParameterType = gauge_messages.Parameter_Dynamic.Enum()
				parameter.Value = proto.String(resolvedArg.Value)
			}
		} else if arg.ArgType == gauge.SpecialString {
			parameter.ParameterType = gauge_messages.Parameter_Special_String.Enum()
			parameter.Value = proto.String(arg.Value)
		} else if arg.ArgType == gauge.SpecialTable {
			parameter.ParameterType = gauge_messages.Parameter_Special_Table.Enum()
			parameter.Table = paramResolver.createProtoStepTable(&arg.Table, dataTableLookup)
		} else {
			parameter.ParameterType = gauge_messages.Parameter_Table.Enum()
			parameter.Table = paramResolver.createProtoStepTable(&arg.Table, dataTableLookup)

		}
		parameters = append(parameters, parameter)
	}

	return parameters

}
Exemplo n.º 7
0
func addInlineTableRow(step *gauge.Step, token *Token, argLookup *gauge.ArgLookup) ParseResult {
	dynamicArgMatcher := regexp.MustCompile("^<(.*)>$")
	tableValues := make([]gauge.TableCell, 0)
	warnings := make([]*Warning, 0)
	for _, tableValue := range token.Args {
		if dynamicArgMatcher.MatchString(tableValue) {
			match := dynamicArgMatcher.FindAllStringSubmatch(tableValue, -1)
			param := match[0][1]
			if !argLookup.ContainsArg(param) {
				tableValues = append(tableValues, gauge.TableCell{Value: tableValue, CellType: gauge.Static})
				warnings = append(warnings, &Warning{LineNo: token.LineNo, Message: fmt.Sprintf("Dynamic param <%s> could not be resolved, Treating it as static param", param)})
			} else {
				tableValues = append(tableValues, gauge.TableCell{Value: param, CellType: gauge.Dynamic})
			}
		} else {
			tableValues = append(tableValues, gauge.TableCell{Value: tableValue, CellType: gauge.Static})
		}
	}
	step.AddInlineTableRow(tableValues)
	return ParseResult{Ok: true, Warnings: warnings}
}
Exemplo n.º 8
0
//Step value is modified when inline table is found to account for the new parameter by appending {}
//todo validate headers for dynamic
func addInlineTableHeader(step *gauge.Step, token *Token) {
	step.Value = fmt.Sprintf("%s %s", step.Value, gauge.ParameterPlaceholder)
	step.HasInlineTable = true
	step.AddInlineTableHeaders(token.Args)
}