Add functionality for replacing string values.
Test: go test -v Change-Id: I8e59bd1dc319d06c5645c6f288df46702901573b
This commit is contained in:
parent
5233841b7a
commit
c93385a75a
2 changed files with 53 additions and 5 deletions
|
@ -230,12 +230,20 @@ func processParameter(value parser.Expression, paramName, moduleName string,
|
|||
}
|
||||
|
||||
if (*replaceProperty).size() != 0 {
|
||||
list, ok := value.Eval().(*parser.List)
|
||||
if !ok {
|
||||
return false, []error{fmt.Errorf("expected parameter %s in module %s to be a list, found %s",
|
||||
paramName, moduleName, value.Type().String())}
|
||||
if list, ok := value.Eval().(*parser.List); ok {
|
||||
return parser.ReplaceStringsInList(list, (*replaceProperty).oldNameToNewName), nil
|
||||
} else if str, ok := value.Eval().(*parser.String); ok {
|
||||
oldVal := str.Value
|
||||
replacementValue := (*replaceProperty).oldNameToNewName[oldVal]
|
||||
if replacementValue != "" {
|
||||
str.Value = replacementValue
|
||||
return true, nil
|
||||
} else {
|
||||
return false, nil
|
||||
}
|
||||
}
|
||||
return parser.ReplaceStringsInList(list, (*replaceProperty).oldNameToNewName), nil
|
||||
return false, []error{fmt.Errorf("expected parameter %s in module %s to be a list or string, found %s",
|
||||
paramName, moduleName, value.Type().String())}
|
||||
}
|
||||
if len(addIdents.idents) > 0 || len(removeIdents.idents) > 0 {
|
||||
list, ok := value.(*parser.List)
|
||||
|
|
|
@ -395,6 +395,46 @@ var testCases = []struct {
|
|||
}
|
||||
`,
|
||||
replaceProperty: "baz:baz_lib,foobar:foobar_lib",
|
||||
}, {
|
||||
name: "replace property string value",
|
||||
property: "name",
|
||||
input: `
|
||||
cc_foo {
|
||||
name: "foo",
|
||||
deps: ["baz"],
|
||||
unchanged: ["baz"],
|
||||
required: ["foobar"],
|
||||
}
|
||||
`,
|
||||
output: `
|
||||
cc_foo {
|
||||
name: "foo_lib",
|
||||
deps: ["baz"],
|
||||
unchanged: ["baz"],
|
||||
required: ["foobar"],
|
||||
}
|
||||
`,
|
||||
replaceProperty: "foo:foo_lib",
|
||||
}, {
|
||||
name: "replace property string and list values",
|
||||
property: "name,deps",
|
||||
input: `
|
||||
cc_foo {
|
||||
name: "foo",
|
||||
deps: ["baz"],
|
||||
unchanged: ["baz"],
|
||||
required: ["foobar"],
|
||||
}
|
||||
`,
|
||||
output: `
|
||||
cc_foo {
|
||||
name: "foo_lib",
|
||||
deps: ["baz_lib"],
|
||||
unchanged: ["baz"],
|
||||
required: ["foobar"],
|
||||
}
|
||||
`,
|
||||
replaceProperty: "foo:foo_lib,baz:baz_lib",
|
||||
},
|
||||
}
|
||||
|
||||
|
|
Loading…
Reference in a new issue