5 type quoteTest struct {
11 var quotetests = []quoteTest{
12 {"\a\b\f\r\n\t\v", `"\a\b\f\r\n\t\v"`, `"\a\b\f\r\n\t\v"`},
13 {"\\", `"\\"`, `"\\"`},
14 {"abc\xffdef", `"abc\xffdef"`, `"abc\xffdef"`},
15 {"\u263a", `"☺"`, `"\u263a"`},
16 {"\U0010ffff", `"\U0010ffff"`, `"\U0010ffff"`},
17 {"\x04", `"\x04"`, `"\x04"`},
20 type unQuoteTest struct {
25 var unquotetests = []unQuoteTest{
30 {`"hello world"`, "hello world"},
33 {`"\u1234"`, "\u1234"},
34 {`"\U00010111"`, "\U00010111"},
35 {`"\U0001011111"`, "\U0001011111"},
36 {`"\a\b\f\n\r\t\v\\\""`, "\a\b\f\n\r\t\v\\\""},
38 {`"${file("foo")}"`, `${file("foo")}`},
39 {`"${file("\"foo\"")}"`, `${file("\"foo\"")}`},
40 {`"echo ${var.region}${element(split(",",var.zones),0)}"`,
41 `echo ${var.region}${element(split(",",var.zones),0)}`},
42 {`"${HH\\:mm\\:ss}"`, `${HH\\:mm\\:ss}`},
46 var misquoted = []string{
77 func TestUnquote(t *testing.T) {
78 for _, tt := range unquotetests {
79 if out, err := Unquote(tt.in); err != nil || out != tt.out {
80 t.Errorf("Unquote(%#q) = %q, %v want %q, nil", tt.in, out, err, tt.out)
84 // run the quote tests too, backward
85 for _, tt := range quotetests {
86 if in, err := Unquote(tt.out); in != tt.in {
87 t.Errorf("Unquote(%#q) = %q, %v, want %q, nil", tt.out, in, err, tt.in)
91 for _, s := range misquoted {
92 if out, err := Unquote(s); out != "" || err != ErrSyntax {
93 t.Errorf("Unquote(%#q) = %q, %v want %q, %v", s, out, err, "", ErrSyntax)