github.com/miolini/go@v0.0.0-20160405192216-fca68c8cb408/src/cmd/vet/testdata/structtag.go (about)

     1  // Copyright 2010 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.
     4  
     5  // This file contains the test for canonical struct tags.
     6  
     7  package testdata
     8  
     9  type StructTagTest struct {
    10  	A   int "hello"            // ERROR "not compatible with reflect.StructTag.Get: bad syntax for struct tag pair"
    11  	B   int "\tx:\"y\""        // ERROR "not compatible with reflect.StructTag.Get: bad syntax for struct tag key"
    12  	C   int "x:\"y\"\tx:\"y\"" // ERROR "not compatible with reflect.StructTag.Get"
    13  	D   int "x:`y`"            // ERROR "not compatible with reflect.StructTag.Get: bad syntax for struct tag value"
    14  	E   int "ct\brl:\"char\""  // ERROR "not compatible with reflect.StructTag.Get: bad syntax for struct tag pair"
    15  	F   int `:"emptykey"`      // ERROR "not compatible with reflect.StructTag.Get: bad syntax for struct tag key"
    16  	G   int `x:"noEndQuote`    // ERROR "not compatible with reflect.StructTag.Get: bad syntax for struct tag value"
    17  	H   int `x:"trunc\x0"`     // ERROR "not compatible with reflect.StructTag.Get: bad syntax for struct tag value"
    18  	OK0 int `x:"y" u:"v" w:""`
    19  	OK1 int `x:"y:z" u:"v" w:""` // note multiple colons.
    20  	OK2 int "k0:\"values contain spaces\" k1:\"literal\ttabs\" k2:\"and\\tescaped\\tabs\""
    21  	OK3 int `under_scores:"and" CAPS:"ARE_OK"`
    22  }
    23  
    24  type UnexportedEncodingTagTest struct {
    25  	x int `json:"xx"` // ERROR "struct field x has json tag but is not exported"
    26  	y int `xml:"yy"`  // ERROR "struct field y has xml tag but is not exported"
    27  	z int
    28  	A int `json:"aa" xml:"bb"`
    29  }
    30  
    31  type unexp struct{}
    32  
    33  type JSONEmbeddedField struct {
    34  	UnexportedEncodingTagTest `is:"embedded"`
    35  	unexp                     `is:"embedded,notexported" json:"unexp"` // OK for now, see issue 7363
    36  }