summaryrefslogtreecommitdiffstats
path: root/vendor/github.com/golang/protobuf/protoc-gen-go/generator/name_test.go
diff options
context:
space:
mode:
Diffstat (limited to 'vendor/github.com/golang/protobuf/protoc-gen-go/generator/name_test.go')
-rw-r--r--vendor/github.com/golang/protobuf/protoc-gen-go/generator/name_test.go29
1 files changed, 29 insertions, 0 deletions
diff --git a/vendor/github.com/golang/protobuf/protoc-gen-go/generator/name_test.go b/vendor/github.com/golang/protobuf/protoc-gen-go/generator/name_test.go
index a5ebc8533..76808f3b7 100644
--- a/vendor/github.com/golang/protobuf/protoc-gen-go/generator/name_test.go
+++ b/vendor/github.com/golang/protobuf/protoc-gen-go/generator/name_test.go
@@ -83,3 +83,32 @@ func TestGoPackageOption(t *testing.T) {
}
}
}
+
+func TestUnescape(t *testing.T) {
+ tests := []struct {
+ in string
+ out string
+ }{
+ // successful cases, including all kinds of escapes
+ {"", ""},
+ {"foo bar baz frob nitz", "foo bar baz frob nitz"},
+ {`\000\001\002\003\004\005\006\007`, string([]byte{0, 1, 2, 3, 4, 5, 6, 7})},
+ {`\a\b\f\n\r\t\v\\\?\'\"`, string([]byte{'\a', '\b', '\f', '\n', '\r', '\t', '\v', '\\', '?', '\'', '"'})},
+ {`\x10\x20\x30\x40\x50\x60\x70\x80`, string([]byte{16, 32, 48, 64, 80, 96, 112, 128})},
+ // variable length octal escapes
+ {`\0\018\222\377\3\04\005\6\07`, string([]byte{0, 1, '8', 0222, 255, 3, 4, 5, 6, 7})},
+ // malformed escape sequences left as is
+ {"foo \\g bar", "foo \\g bar"},
+ {"foo \\xg0 bar", "foo \\xg0 bar"},
+ {"\\", "\\"},
+ {"\\x", "\\x"},
+ {"\\xf", "\\xf"},
+ {"\\777", "\\777"}, // overflows byte
+ }
+ for _, tc := range tests {
+ s := unescape(tc.in)
+ if s != tc.out {
+ t.Errorf("doUnescape(%q) = %q; should have been %q", tc.in, s, tc.out)
+ }
+ }
+}