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