1 // Copyright 2011 The Go Authors. All rights reserved.
2 // Use of this source code is governed by a BSD-style
3 // license that can be found in the LICENSE file.
11 type basicLatin2xTag struct {
12 V string `json:"$%-/"`
15 type basicLatin3xTag struct {
16 V string `json:"0123456789"`
19 type basicLatin4xTag struct {
20 V string `json:"ABCDEFGHIJKLMO"`
23 type basicLatin5xTag struct {
24 V string `json:"PQRSTUVWXYZ_"`
27 type basicLatin6xTag struct {
28 V string `json:"abcdefghijklmno"`
31 type basicLatin7xTag struct {
32 V string `json:"pqrstuvwxyz"`
35 type miscPlaneTag struct {
36 V string `json:"色は匂へど"`
39 type percentSlashTag struct {
40 V string `json:"text/html%"` // http://golang.org/issue/2718
43 type emptyTag struct {
47 type misnamedTag struct {
48 X string `jsom:"Misnamed"`
51 type badFormatTag struct {
52 Y string `:"BadFormat"`
55 type badCodeTag struct {
56 Z string `json:" !\"#&'()*+,."`
59 var structTagObjectKeyTests = []struct {
64 {basicLatin2xTag{"2x"}, "2x", "$%-/"},
65 {basicLatin3xTag{"3x"}, "3x", "0123456789"},
66 {basicLatin4xTag{"4x"}, "4x", "ABCDEFGHIJKLMO"},
67 {basicLatin5xTag{"5x"}, "5x", "PQRSTUVWXYZ_"},
68 {basicLatin6xTag{"6x"}, "6x", "abcdefghijklmno"},
69 {basicLatin7xTag{"7x"}, "7x", "pqrstuvwxyz"},
70 {miscPlaneTag{"いろはにほへと"}, "いろはにほへと", "色は匂へど"},
71 {emptyTag{"Pour Moi"}, "Pour Moi", "W"},
72 {misnamedTag{"Animal Kingdom"}, "Animal Kingdom", "X"},
73 {badFormatTag{"Orfevre"}, "Orfevre", "Y"},
74 {badCodeTag{"Reliable Man"}, "Reliable Man", "Z"},
75 {percentSlashTag{"brut"}, "brut", "text/html%"},
78 func TestStructTagObjectKey(t *testing.T) {
79 for _, tt := range structTagObjectKeyTests {
80 b, err := Marshal(tt.raw)
82 t.Fatalf("Marshal(%#q) failed: %v", tt.raw, err)
85 err = Unmarshal(b, &f)
87 t.Fatalf("Unmarshal(%#q) failed: %v", b, err)
89 for i, v := range f.(map[string]interface{}) {
92 if s, ok := v.(string); !ok || s != tt.value {
93 t.Fatalf("Unexpected value: %#q, want %v", s, tt.value)
96 t.Fatalf("Unexpected key: %#q, from %#q", i, b)