lang: Quote printed strings

This quotes printed strings that contain special characters such as
newline. This changes the output of some tests, but makes future tests
that include a raw \n more appropriate.
This commit is contained in:
James Shubin
2019-04-23 20:32:45 -04:00
parent 8f1f5d33fd
commit 97d60ac98d
10 changed files with 194 additions and 193 deletions

View File

@@ -22,6 +22,7 @@ import (
"fmt"
"reflect"
"sort"
"strconv"
"strings"
"github.com/purpleidea/mgmt/engine"
@@ -3554,7 +3555,7 @@ type ExprStr struct {
func (obj *ExprStr) Apply(fn func(interfaces.Node) error) error { return fn(obj) }
// String returns a short representation of this expression.
func (obj *ExprStr) String() string { return fmt.Sprintf("str(%s)", obj.V) }
func (obj *ExprStr) String() string { return fmt.Sprintf("str(%s)", strconv.Quote(obj.V)) }
// Init initializes this branch of the AST, and returns an error if it fails to
// validate.