|
|
|
@ -27,7 +27,8 @@ func (t *QuotesTest) TestParse() {
|
|
|
|
|
t.NoError(err)
|
|
|
|
|
|
|
|
|
|
expanded, _ := token.(Expandable).Expand(nil, nil, nil)
|
|
|
|
|
t.Equal("word1 word2 word3\n word4", strings.Join(expanded, " "))
|
|
|
|
|
t.Equal(1, len(expanded))
|
|
|
|
|
t.Equal("word1 word2 word3\n word4", expanded[0])
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
func (t *QuotesTest) TestExpandVariables() {
|
|
|
|
@ -72,6 +73,52 @@ func (t *QuotesTest) TestExpandSubshell() {
|
|
|
|
|
t.Equal("This is a subshell", expanded[0])
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
func (t *QuotesTest) TestExpandBacktick() {
|
|
|
|
|
parser := &BaseParser{&QuoteParameters{}}
|
|
|
|
|
reader := bufio.NewReader(
|
|
|
|
|
strings.NewReader("\"This is `echo a backtick`\""),
|
|
|
|
|
)
|
|
|
|
|
|
|
|
|
|
state := NewShellState()
|
|
|
|
|
|
|
|
|
|
echo := &builtins.Echo{}
|
|
|
|
|
state.SetCommand(echo.Name(), echo)
|
|
|
|
|
|
|
|
|
|
iterator, err := NewCharIterator(reader)
|
|
|
|
|
t.NoError(err)
|
|
|
|
|
|
|
|
|
|
token, err := parser.Parse(iterator, &CharCollection{})
|
|
|
|
|
t.NoError(err)
|
|
|
|
|
|
|
|
|
|
expanded, _ := token.(Expandable).Expand(state, nil, nil)
|
|
|
|
|
t.Equal(1, len(expanded))
|
|
|
|
|
t.Equal("This is a backtick", expanded[0])
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
// The only way backticks can be nested at the moment is by wrapping them in
|
|
|
|
|
// quotes.
|
|
|
|
|
func (t *QuotesTest) TestExpandNestedBacktick() {
|
|
|
|
|
parser := &BaseParser{&QuoteParameters{}}
|
|
|
|
|
reader := bufio.NewReader(
|
|
|
|
|
strings.NewReader("\"This is `echo a \"`echo backtick`\"`\""),
|
|
|
|
|
)
|
|
|
|
|
|
|
|
|
|
state := NewShellState()
|
|
|
|
|
|
|
|
|
|
echo := &builtins.Echo{}
|
|
|
|
|
state.SetCommand(echo.Name(), echo)
|
|
|
|
|
|
|
|
|
|
iterator, err := NewCharIterator(reader)
|
|
|
|
|
t.NoError(err)
|
|
|
|
|
|
|
|
|
|
token, err := parser.Parse(iterator, &CharCollection{})
|
|
|
|
|
t.NoError(err)
|
|
|
|
|
|
|
|
|
|
expanded, _ := token.(Expandable).Expand(state, nil, nil)
|
|
|
|
|
t.Equal(1, len(expanded))
|
|
|
|
|
t.Equal("This is a backtick", expanded[0])
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
func TestQuotesTest(t *testing.T) {
|
|
|
|
|
suite.Run(t, new(QuotesTest))
|
|
|
|
|
}
|
|
|
|
|