Skip to content

Commit

Permalink
fix(variables): Add number suffix support to the variable extractor
Browse files Browse the repository at this point in the history
Signed-off-by: Suleiman Dibirov <[email protected]>
  • Loading branch information
idsulik authored and ndeloof committed Nov 12, 2024
1 parent 9d02caa commit 58f8cad
Show file tree
Hide file tree
Showing 2 changed files with 39 additions and 0 deletions.
3 changes: 3 additions & 0 deletions template/variables.go
Original file line number Diff line number Diff line change
Expand Up @@ -108,6 +108,9 @@ func extractVariable(value interface{}, pattern *regexp.Regexp) ([]Variable, boo
if r >= 'A' && r <= 'Z' {
return false
}
if r >= '0' && r <= '9' {
return false
}
if r == '_' {
return false
}
Expand Down
36 changes: 36 additions & 0 deletions template/variables_test.go
Original file line number Diff line number Diff line change
Expand Up @@ -50,6 +50,15 @@ func TestExtractVariables(t *testing.T) {
"bar": {Name: "bar"},
},
},
{
name: "variable-without-curly-braces-and-with-number-suffix",
dict: map[string]interface{}{
"foo": "$bar_1",
},
expected: map[string]Variable{
"bar_1": {Name: "bar_1"},
},
},
{
name: "variable",
dict: map[string]interface{}{
Expand All @@ -68,6 +77,15 @@ func TestExtractVariables(t *testing.T) {
"bar": {Name: "bar", DefaultValue: "", Required: true},
},
},
{
name: "required-variable-with-number-suffix",
dict: map[string]interface{}{
"foo": "${bar_1?:foo}",
},
expected: map[string]Variable{
"bar_1": {Name: "bar_1", DefaultValue: "", Required: true},
},
},
{
name: "required-variable2",
dict: map[string]interface{}{
Expand Down Expand Up @@ -95,6 +113,24 @@ func TestExtractVariables(t *testing.T) {
"bar": {Name: "bar", DefaultValue: "foo"},
},
},
{
name: "default-variable-with-number-suffix",
dict: map[string]interface{}{
"foo": "${bar_1:-foo}",
},
expected: map[string]Variable{
"bar_1": {Name: "bar_1", DefaultValue: "foo"},
},
},
{
name: "default-variable2-with-number-suffix",
dict: map[string]interface{}{
"foo": "${bar_1-foo}",
},
expected: map[string]Variable{
"bar_1": {Name: "bar_1", DefaultValue: "foo"},
},
},
{
name: "multiple-values",
dict: map[string]interface{}{
Expand Down

0 comments on commit 58f8cad

Please sign in to comment.