1 2 3 4 5 6 7 8 9 10 11 12 13 14 15 16 17 18 19 20 21 22 23 24 25 26 27 28 29 30 31 32 33 34 35 36
|
package parse
import (
"testing"
"github.com/elves/elvish/tt"
)
var quoteTests = tt.Table{
// Empty string is single-quoted.
tt.Args("").Rets(`''`),
// Bareword when possible.
tt.Args("x-y:z@h/d").Rets("x-y:z@h/d"),
// Single quote when there are special characters but no unprintable
// characters.
tt.Args("x$y[]ef'").Rets("'x$y[]ef'''"),
// Tilde needs quoting only leading the expression.
tt.Args("~x").Rets("'~x'"),
tt.Args("x~").Rets("x~"),
// Double quote when there is unprintable char.
tt.Args("a\nb").Rets(`"a\nb"`),
tt.Args("\x1b\"\\").Rets(`"\e\"\\"`),
// Commas and equal signs are always quoted, so that the quoted string is
// safe for use everywhere.
tt.Args("a,b").Rets(`'a,b'`),
tt.Args("a=b").Rets(`'a=b'`),
}
func TestQuote(t *testing.T) {
tt.Test(t, tt.Fn("Quote", Quote).ArgsFmt("(%q)").RetsFmt("%q"), quoteTests)
}
|