Giant blob of minor changes
[dotfiles/.git] / .config / coc / extensions / coc-go-data / tools / pkg / mod / golang.org / x / tools@v0.0.0-20201105173854-bc9fc8d8c4bc / go / analysis / passes / structtag / testdata / src / a / a.go
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 a
8
9 import (
10         "a/b"
11         "encoding/xml"
12 )
13
14 type StructTagTest struct {
15         A   int "hello"            // want "`hello` not compatible with reflect.StructTag.Get: bad syntax for struct tag pair"
16         B   int "\tx:\"y\""        // want "not compatible with reflect.StructTag.Get: bad syntax for struct tag key"
17         C   int "x:\"y\"\tx:\"y\"" // want "not compatible with reflect.StructTag.Get"
18         D   int "x:`y`"            // want "not compatible with reflect.StructTag.Get: bad syntax for struct tag value"
19         E   int "ct\brl:\"char\""  // want "not compatible with reflect.StructTag.Get: bad syntax for struct tag pair"
20         F   int `:"emptykey"`      // want "not compatible with reflect.StructTag.Get: bad syntax for struct tag key"
21         G   int `x:"noEndQuote`    // want "not compatible with reflect.StructTag.Get: bad syntax for struct tag value"
22         H   int `x:"trunc\x0"`     // want "not compatible with reflect.StructTag.Get: bad syntax for struct tag value"
23         I   int `x:"foo",y:"bar"`  // want "not compatible with reflect.StructTag.Get: key:.value. pairs not separated by spaces"
24         J   int `x:"foo"y:"bar"`   // want "not compatible with reflect.StructTag.Get: key:.value. pairs not separated by spaces"
25         OK0 int `x:"y" u:"v" w:""`
26         OK1 int `x:"y:z" u:"v" w:""` // note multiple colons.
27         OK2 int "k0:\"values contain spaces\" k1:\"literal\ttabs\" k2:\"and\\tescaped\\tabs\""
28         OK3 int `under_scores:"and" CAPS:"ARE_OK"`
29 }
30
31 type UnexportedEncodingTagTest struct {
32         x int `json:"xx"` // want "struct field x has json tag but is not exported"
33         y int `xml:"yy"`  // want "struct field y has xml tag but is not exported"
34         z int
35         A int `json:"aa" xml:"bb"`
36         b int `json:"-"`
37         C int `json:"-"`
38 }
39
40 type unexp struct{}
41
42 type JSONEmbeddedField struct {
43         UnexportedEncodingTagTest `is:"embedded"`
44         unexp                     `is:"embedded,notexported" json:"unexp"` // OK for now, see issue 7363
45 }
46
47 type AnonymousJSON struct{}
48 type AnonymousXML struct{}
49
50 type AnonymousJSONField struct {
51         DuplicateAnonJSON int `json:"a"`
52
53         A int "hello" // want "`hello` not compatible with reflect.StructTag.Get: bad syntax for struct tag pair"
54 }
55
56 // With different names to allow using as anonymous fields multiple times.
57
58 type AnonymousJSONField2 struct {
59         DuplicateAnonJSON int `json:"a"`
60 }
61 type AnonymousJSONField3 struct {
62         DuplicateAnonJSON int `json:"a"`
63 }
64
65 type DuplicateJSONFields struct {
66         JSON              int `json:"a"`
67         DuplicateJSON     int `json:"a"` // want "struct field DuplicateJSON repeats json tag .a. also at a.go:66"
68         IgnoredJSON       int `json:"-"`
69         OtherIgnoredJSON  int `json:"-"`
70         OmitJSON          int `json:",omitempty"`
71         OtherOmitJSON     int `json:",omitempty"`
72         DuplicateOmitJSON int `json:"a,omitempty"` // want "struct field DuplicateOmitJSON repeats json tag .a. also at a.go:66"
73         NonJSON           int `foo:"a"`
74         DuplicateNonJSON  int `foo:"a"`
75         Embedded          struct {
76                 DuplicateJSON int `json:"a"` // OK because it's not in the same struct type
77         }
78         AnonymousJSON `json:"a"` // want "struct field AnonymousJSON repeats json tag .a. also at a.go:66"
79
80         XML              int `xml:"a"`
81         DuplicateXML     int `xml:"a"` // want "struct field DuplicateXML repeats xml tag .a. also at a.go:80"
82         IgnoredXML       int `xml:"-"`
83         OtherIgnoredXML  int `xml:"-"`
84         OmitXML          int `xml:",omitempty"`
85         OtherOmitXML     int `xml:",omitempty"`
86         DuplicateOmitXML int `xml:"a,omitempty"` // want "struct field DuplicateOmitXML repeats xml tag .a. also at a.go:80"
87         NonXML           int `foo:"a"`
88         DuplicateNonXML  int `foo:"a"`
89         Embedded2        struct {
90                 DuplicateXML int `xml:"a"` // OK because it's not in the same struct type
91         }
92         AnonymousXML `xml:"a"` // want "struct field AnonymousXML repeats xml tag .a. also at a.go:80"
93         Attribute    struct {
94                 XMLName     xml.Name `xml:"b"`
95                 NoDup       int      `xml:"b"`                // OK because XMLName above affects enclosing struct.
96                 Attr        int      `xml:"b,attr"`           // OK because <b b="0"><b>0</b></b> is valid.
97                 DupAttr     int      `xml:"b,attr"`           // want "struct field DupAttr repeats xml attribute tag .b. also at a.go:96"
98                 DupOmitAttr int      `xml:"b,omitempty,attr"` // want "struct field DupOmitAttr repeats xml attribute tag .b. also at a.go:96"
99
100                 AnonymousXML `xml:"b,attr"` // want "struct field AnonymousXML repeats xml attribute tag .b. also at a.go:96"
101         }
102
103         AnonymousJSONField2 `json:"not_anon"` // ok; fields aren't embedded in JSON
104         AnonymousJSONField3 `json:"-"`        // ok; entire field is ignored in JSON
105 }
106
107 type UnexpectedSpacetest struct {
108         A int `json:"a,omitempty"`
109         B int `json:"b, omitempty"` // want "suspicious space in struct tag value"
110         C int `json:"c ,omitempty"`
111         D int `json:"d,omitempty, string"` // want "suspicious space in struct tag value"
112         E int `xml:"e local"`
113         F int `xml:"f "`                 // want "suspicious space in struct tag value"
114         G int `xml:" g"`                 // want "suspicious space in struct tag value"
115         H int `xml:"h ,omitempty"`       // want "suspicious space in struct tag value"
116         I int `xml:"i, omitempty"`       // want "suspicious space in struct tag value"
117         J int `xml:"j local ,omitempty"` // want "suspicious space in struct tag value"
118         K int `xml:"k local, omitempty"` // want "suspicious space in struct tag value"
119         L int `xml:" l local,omitempty"` // want "suspicious space in struct tag value"
120         M int `xml:"m  local,omitempty"` // want "suspicious space in struct tag value"
121         N int `xml:" "`                  // want "suspicious space in struct tag value"
122         O int `xml:""`
123         P int `xml:","`
124         Q int `foo:" doesn't care "`
125 }
126
127 // Nested fiels can be shadowed by fields further up. For example,
128 // ShadowingAnonJSON replaces the json:"a" field in AnonymousJSONField.
129 // However, if the two conflicting fields appear at the same level like in
130 // DuplicateWithAnotherPackage, we should error.
131
132 type ShadowingJsonFieldName struct {
133         AnonymousJSONField
134         ShadowingAnonJSON int `json:"a"`
135 }
136
137 type DuplicateWithAnotherPackage struct {
138         b.AnonymousJSONField
139         AnonymousJSONField2 // want "struct field DuplicateAnonJSON repeats json tag .a. also at b.b.go:8"
140 }