Support complicated variable references

Bug: 226974242
Test: go test
Change-Id: Iaec16f5c498e7c75c9ee5d53d3499efadfba16bc
This commit is contained in:
Cole Faust
2022-04-28 14:29:57 -07:00
parent 85f8fa2c20
commit 1323877b7e
4 changed files with 55 additions and 3 deletions

View File

@@ -234,10 +234,10 @@ func (ms *MakeString) splitNFunc(n int, splitFunc func(s string, n int) []string
if n != 0 {
split := splitFunc(s, n)
if n != -1 {
if len(split) > n {
if len(split) > n || len(split) == 0 {
panic("oops!")
} else {
n -= len(split)
n -= len(split) - 1
}
}
curMs.appendString(split[0])

View File

@@ -75,6 +75,16 @@ var splitNTestCases = []struct {
genMakeString(""),
},
},
{
// "x$(var1)y bar"
in: genMakeString("x", "var1", "y bar"),
sep: " ",
n: 2,
expected: []*MakeString{
genMakeString("x", "var1", "y"),
genMakeString("bar"),
},
},
}
func TestMakeStringSplitN(t *testing.T) {