Skip to content
Permalink
Browse files

syntax: re-add tests for ${# ambiguity

These were added along with the code in question a while ago, but the
test cases stopped erroring, so we deleted them.

Add them again as successful parse tests, to actually test the code.
Also fix it, as the positions were wrong.
  • Loading branch information...
mvdan committed Aug 27, 2019
1 parent 825607a commit 6af96bc17993a990fcd2c341c83a168a3158daa1
Showing with 22 additions and 2 deletions.
  1. +19 −0 syntax/filetests_test.go
  2. +3 −2 syntax/parser.go
@@ -2379,6 +2379,25 @@ var fileTests = []testCase{
word(&ParamExp{Length: true, Param: lit("?")}),
),
},
{
Strs: []string{`${#-foo} ${#?bar}`},
common: call(
word(&ParamExp{
Param: lit("#"),
Exp: &Expansion{
Op: DefaultUnset,
Word: litWord("foo"),
},
}),
word(&ParamExp{
Param: lit("#"),
Exp: &Expansion{
Op: ErrorUnset,
Word: litWord("bar"),
},
}),
),
},
{
Strs: []string{`"${foo}"`},
common: dblQuoted(&ParamExp{Param: lit("foo")}),
@@ -1346,9 +1346,10 @@ func (p *Parser) paramExp() *ParamExp {
p.next()
case quest, minus:
if pe.Length && p.r != '}' {
// actually ${#-default}, not ${#-}; error below
// actually ${#-default}, not ${#-}; fix the ambiguity
pe.Length = false
pe.Param = p.lit(p.pos, "#")
pe.Param = p.lit(posAddCol(p.pos, -1), "#")
pe.Param.ValueEnd = p.pos
break
}
fallthrough

0 comments on commit 6af96bc

Please sign in to comment.
You can’t perform that action at this time.