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 {
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 emptyTag struct {
43 type misnamedTag struct {
44 X string `jsom:"Misnamed"`
47 type badFormatTag struct {
48 Y string `:"BadFormat"`
51 type badCodeTag struct {
52 Z string `json:" !\"#%&'()*+,./"`
55 var structTagObjectKeyTests = []struct {
60 {basicLatin2xTag{"2x"}, "2x", "$-"},
61 {basicLatin3xTag{"3x"}, "3x", "0123456789"},
62 {basicLatin4xTag{"4x"}, "4x", "ABCDEFGHIJKLMO"},
63 {basicLatin5xTag{"5x"}, "5x", "PQRSTUVWXYZ_"},
64 {basicLatin6xTag{"6x"}, "6x", "abcdefghijklmno"},
65 {basicLatin7xTag{"7x"}, "7x", "pqrstuvwxyz"},
66 {miscPlaneTag{"いろはにほへと"}, "いろはにほへと", "色は匂へど"},
67 {emptyTag{"Pour Moi"}, "Pour Moi", "W"},
68 {misnamedTag{"Animal Kingdom"}, "Animal Kingdom", "X"},
69 {badFormatTag{"Orfevre"}, "Orfevre", "Y"},
70 {badCodeTag{"Reliable Man"}, "Reliable Man", "Z"},
73 func TestStructTagObjectKey(t *testing.T) {
74 for _, tt := range structTagObjectKeyTests {
75 b, err := Marshal(tt.raw)
77 t.Fatalf("Marshal(%#q) failed: %v", tt.raw, err)
80 err = Unmarshal(b, &f)
82 t.Fatalf("Unmarshal(%#q) failed: %v", b, err)
84 for i, v := range f.(map[string]interface{}) {
87 if s, ok := v.(string); !ok || s != tt.value {
88 t.Fatalf("Unexpected value: %#q, want %v", s, tt.value)
91 t.Fatalf("Unexpected key: %#q", i)