github.com/ladydascalie/elvish@v0.0.0-20170703214355-2964dd3ece7f/parse/quote_test.go (about) 1 package parse 2 3 import "testing" 4 5 var quoteTests = []struct { 6 text, quoted string 7 }{ 8 // Empty string is quoted with single quote. 9 {"", `''`}, 10 // Bareword when possible. 11 {"x-y,z@h/d", "x-y,z@h/d"}, 12 // Single quote when there is special char but no unprintable. 13 {"x$y[]ef'", "'x$y[]ef'''"}, 14 // Tilde needs quoting only when appearing at the beginning 15 {"~x", "'~x'"}, 16 {"x~", "x~"}, 17 // Double quote when there is unprintable char. 18 {"a\nb", `"a\nb"`}, 19 {"\x1b\"\\", `"\e\"\\"`}, 20 } 21 22 func TestQuote(t *testing.T) { 23 for _, tc := range quoteTests { 24 got := Quote(tc.text) 25 if got != tc.quoted { 26 t.Errorf("Quote(%q) => %s, want %s", tc.text, got, tc.quoted) 27 } 28 } 29 }