예제 #1
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()
}
예제 #2
0
파일: specparser.go 프로젝트: 0-T-0/gauge
func validateDynamicArg(argValue string, token *Token, lookup *gauge.ArgLookup) (*gauge.StepArg, *ParseDetailResult) {
	if !isConceptHeader(lookup) && !lookup.ContainsArg(argValue) {
		return nil, &ParseDetailResult{Error: &ParseError{LineNo: token.LineNo, Message: fmt.Sprintf("Dynamic parameter <%s> could not be resolved", argValue), LineText: token.LineText}}
	}
	stepArgument := &gauge.StepArg{ArgType: gauge.Dynamic, Value: argValue, Name: argValue}
	return stepArgument, nil
}
예제 #3
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

}
예제 #4
0
파일: specparser.go 프로젝트: 0-T-0/gauge
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}
}
예제 #5
0
func (resolver *ParamResolver) createProtoStepTable(table *gauge.Table, dataTableLookup *gauge.ArgLookup) *gauge_messages.ProtoTable {
	protoTable := new(gauge_messages.ProtoTable)
	protoTable.Headers = &gauge_messages.ProtoTableRow{Cells: table.Headers}
	tableRows := make([]*gauge_messages.ProtoTableRow, 0)
	if len(table.Columns) == 0 {
		protoTable.Rows = tableRows
		return protoTable
	}
	for i := 0; i < len(table.Columns[0]); i++ {
		row := make([]string, 0)
		for _, header := range table.Headers {
			tableCell := table.Get(header)[i]
			value := tableCell.Value
			if tableCell.CellType == gauge.Dynamic {
				//if concept has a table with dynamic cell, fetch from datatable
				value = dataTableLookup.GetArg(tableCell.Value).Value
			}
			row = append(row, value)
		}
		tableRows = append(tableRows, &gauge_messages.ProtoTableRow{Cells: row})
	}
	protoTable.Rows = tableRows
	return protoTable
}