@@ -12,128 +12,130 @@ function test(includeExampleData) {
12
12
{
13
13
input : '{"SourceCode": "exampleDataHere"}' ,
14
14
expected :
15
- 'type AutoGenerated struct {\n\tSourceCode string `json:"SourceCode"`\n}' ,
15
+ 'type AutoGenerated struct {\n\tSourceCode string `json:"SourceCode"`\n}\n ' ,
16
16
expectedWithExample :
17
- 'type AutoGenerated struct {\n\tSourceCode string `json:"SourceCode" example:"exampleDataHere"`\n}' ,
17
+ 'type AutoGenerated struct {\n\tSourceCode string `json:"SourceCode" example:"exampleDataHere"`\n}\n ' ,
18
18
} ,
19
19
{
20
20
input : '{"source_code": "exampleDataHere"}' ,
21
21
expected :
22
- 'type AutoGenerated struct {\n\tSourceCode string `json:"source_code"`\n}' ,
22
+ 'type AutoGenerated struct {\n\tSourceCode string `json:"source_code"`\n}\n ' ,
23
23
expectedWithExample :
24
- 'type AutoGenerated struct {\n\tSourceCode string `json:"source_code" example:"exampleDataHere"`\n}'
25
- } ,
24
+ 'type AutoGenerated struct {\n\tSourceCode string `json:"source_code" example:"exampleDataHere"`\n}\n' ,
25
+ } ,
26
26
{
27
27
input : '{"sourceCode": "exampleDataHere"}' ,
28
28
expected :
29
- 'type AutoGenerated struct {\n\tSourceCode string `json:"sourceCode"`\n}' ,
29
+ 'type AutoGenerated struct {\n\tSourceCode string `json:"sourceCode"`\n}\n ' ,
30
30
expectedWithExample :
31
- 'type AutoGenerated struct {\n\tSourceCode string `json:"sourceCode" example:"exampleDataHere"`\n}' } ,
31
+ 'type AutoGenerated struct {\n\tSourceCode string `json:"sourceCode" example:"exampleDataHere"`\n}\n' ,
32
+ } ,
32
33
{
33
34
input : '{"SOURCE_CODE": ""}' ,
34
35
expected :
35
- 'type AutoGenerated struct {\n\tSourceCode string `json:"SOURCE_CODE"`\n}' ,
36
+ 'type AutoGenerated struct {\n\tSourceCode string `json:"SOURCE_CODE"`\n}\n ' ,
36
37
expectedWithExample :
37
- 'type AutoGenerated struct {\n\tSourceCode string `json:"SOURCE_CODE"`\n}'
38
+ 'type AutoGenerated struct {\n\tSourceCode string `json:"SOURCE_CODE"`\n}\n' ,
38
39
} ,
39
40
{
40
41
input : '{"PublicIP": ""}' ,
41
42
expected :
42
- 'type AutoGenerated struct {\n\tPublicIP string `json:"PublicIP"`\n}' ,
43
+ 'type AutoGenerated struct {\n\tPublicIP string `json:"PublicIP"`\n}\n ' ,
43
44
expectedWithExample :
44
- 'type AutoGenerated struct {\n\tPublicIP string `json:"PublicIP"`\n}'
45
+ 'type AutoGenerated struct {\n\tPublicIP string `json:"PublicIP"`\n}\n' ,
45
46
} ,
46
47
{
47
48
input : '{"public_ip": ""}' ,
48
49
expected :
49
- 'type AutoGenerated struct {\n\tPublicIP string `json:"public_ip"`\n}' ,
50
+ 'type AutoGenerated struct {\n\tPublicIP string `json:"public_ip"`\n}\n ' ,
50
51
expectedWithExample :
51
- 'type AutoGenerated struct {\n\tPublicIP string `json:"public_ip"`\n}'
52
+ 'type AutoGenerated struct {\n\tPublicIP string `json:"public_ip"`\n}\n' ,
52
53
} ,
53
54
{
54
55
input : '{"publicIP": ""}' ,
55
56
expected :
56
- 'type AutoGenerated struct {\n\tPublicIP string `json:"publicIP"`\n}' ,
57
+ 'type AutoGenerated struct {\n\tPublicIP string `json:"publicIP"`\n}\n ' ,
57
58
expectedWithExample :
58
- 'type AutoGenerated struct {\n\tPublicIP string `json:"publicIP"`\n}'
59
+ 'type AutoGenerated struct {\n\tPublicIP string `json:"publicIP"`\n}\n' ,
59
60
} ,
60
61
{
61
62
input : '{"PUBLIC_IP": ""}' ,
62
63
expected :
63
- 'type AutoGenerated struct {\n\tPublicIP string `json:"PUBLIC_IP"`\n}' ,
64
+ 'type AutoGenerated struct {\n\tPublicIP string `json:"PUBLIC_IP"`\n}\n ' ,
64
65
expectedWithExample :
65
- 'type AutoGenerated struct {\n\tPublicIP string `json:"PUBLIC_IP"`\n}'
66
+ 'type AutoGenerated struct {\n\tPublicIP string `json:"PUBLIC_IP"`\n}\n' ,
66
67
} ,
67
68
{
68
69
input : '{"+1": "Fails", "-1": "This should not cause duplicate field name"}' ,
69
70
expected :
70
- 'type AutoGenerated struct {\n\tNum1 string `json:"+1"`\n\tNum10 string `json:"-1"`\n}' ,
71
+ 'type AutoGenerated struct {\n\tNum1 string `json:"+1"`\n\tNum10 string `json:"-1"`\n}\n ' ,
71
72
expectedWithExample :
72
- 'type AutoGenerated struct {\n\tNum1 string `json:"+1" example:"Fails"`\n\tNum10 string `json:"-1" example:"This should not cause duplicate field name"`\n}'
73
+ 'type AutoGenerated struct {\n\tNum1 string `json:"+1" example:"Fails"`\n\tNum10 string `json:"-1" example:"This should not cause duplicate field name"`\n}\n' ,
73
74
} ,
74
75
{
75
76
input : '{"age": 46}' ,
76
77
expected :
77
- 'type AutoGenerated struct {\n\tAge int `json:"age"`\n}' ,
78
+ 'type AutoGenerated struct {\n\tAge int `json:"age"`\n}\n ' ,
78
79
expectedWithExample :
79
- 'type AutoGenerated struct {\n\tAge int `json:"age" example:"46"`\n}'
80
+ 'type AutoGenerated struct {\n\tAge int `json:"age" example:"46"`\n}\n' ,
80
81
} ,
81
82
{
82
83
input : '{"negativeFloat": -1.00}' ,
83
84
expected :
84
- 'type AutoGenerated struct {\n\tNegativeFloat float64 `json:"negativeFloat"`\n}' ,
85
+ 'type AutoGenerated struct {\n\tNegativeFloat float64 `json:"negativeFloat"`\n}\n ' ,
85
86
expectedWithExample :
86
- 'type AutoGenerated struct {\n\tNegativeFloat float64 `json:"negativeFloat" example:"-1.1"`\n}'
87
+ 'type AutoGenerated struct {\n\tNegativeFloat float64 `json:"negativeFloat" example:"-1.1"`\n}\n' ,
87
88
} ,
88
89
{
89
90
input : '{"zeroFloat": 0.00}' ,
90
91
expected :
91
- 'type AutoGenerated struct {\n\tZeroFloat float64 `json:"zeroFloat"`\n}' ,
92
+ 'type AutoGenerated struct {\n\tZeroFloat float64 `json:"zeroFloat"`\n}\n ' ,
92
93
expectedWithExample :
93
- 'type AutoGenerated struct {\n\tZeroFloat float64 `json:"zeroFloat" example:"0.1"`\n}'
94
+ 'type AutoGenerated struct {\n\tZeroFloat float64 `json:"zeroFloat" example:"0.1"`\n}\n' ,
94
95
} ,
95
96
{
96
97
input : '{"positiveFloat": 1.00}' ,
97
98
expected :
98
- 'type AutoGenerated struct {\n\tPositiveFloat float64 `json:"positiveFloat"`\n}' ,
99
+ 'type AutoGenerated struct {\n\tPositiveFloat float64 `json:"positiveFloat"`\n}\n ' ,
99
100
expectedWithExample :
100
- 'type AutoGenerated struct {\n\tPositiveFloat float64 `json:"positiveFloat" example:"1.1"`\n}'
101
+ 'type AutoGenerated struct {\n\tPositiveFloat float64 `json:"positiveFloat" example:"1.1"`\n}\n' ,
101
102
} ,
102
103
{
103
104
input : '{"negativeFloats": [-1.00, -2.00, -3.00]}' ,
104
105
expected :
105
- 'type AutoGenerated struct {\n\tNegativeFloats []float64 `json:"negativeFloats"`\n}' ,
106
+ 'type AutoGenerated struct {\n\tNegativeFloats []float64 `json:"negativeFloats"`\n}\n ' ,
106
107
expectedWithExample :
107
- 'type AutoGenerated struct {\n\tNegativeFloats []float64 `json:"negativeFloats"`\n}'
108
+ 'type AutoGenerated struct {\n\tNegativeFloats []float64 `json:"negativeFloats"`\n}\n' ,
108
109
} ,
109
110
{
110
111
input : '{"zeroFloats": [0.00, 0.00, 0.00]}' ,
111
112
expected :
112
- 'type AutoGenerated struct {\n\tZeroFloats []float64 `json:"zeroFloats"`\n}' ,
113
+ 'type AutoGenerated struct {\n\tZeroFloats []float64 `json:"zeroFloats"`\n}\n ' ,
113
114
expectedWithExample :
114
- 'type AutoGenerated struct {\n\tZeroFloats []float64 `json:"zeroFloats"`\n}'
115
+ 'type AutoGenerated struct {\n\tZeroFloats []float64 `json:"zeroFloats"`\n}\n' ,
115
116
} ,
116
117
{
117
118
input : '{"positiveFloats": [1.00, 2.00, 3.00]}' ,
118
119
expected :
119
- 'type AutoGenerated struct {\n\tPositiveFloats []float64 `json:"positiveFloats"`\n}' ,
120
+ 'type AutoGenerated struct {\n\tPositiveFloats []float64 `json:"positiveFloats"`\n}\n ' ,
120
121
expectedWithExample :
121
- 'type AutoGenerated struct {\n\tPositiveFloats []float64 `json:"positiveFloats"`\n}'
122
+ 'type AutoGenerated struct {\n\tPositiveFloats []float64 `json:"positiveFloats"`\n}\n' ,
122
123
} ,
123
124
{
124
125
input : '{"topLevel": { "secondLevel": "exampleDataHere"} }' ,
125
126
expected :
126
- 'type AutoGenerated struct {\n\tTopLevel struct {\n\t\tSecondLevel string `json:"secondLevel"`\n\t} `json:"topLevel"`\n}' ,
127
+ 'type AutoGenerated struct {\n\tTopLevel struct {\n\t\tSecondLevel string `json:"secondLevel"`\n\t} `json:"topLevel"`\n}\n ' ,
127
128
expectedWithExample :
128
- 'type AutoGenerated struct {\n\tTopLevel struct {\n\t\tSecondLevel string `json:"secondLevel" example:"exampleDataHere"`\n\t} `json:"topLevel"`\n}'
129
+ 'type AutoGenerated struct {\n\tTopLevel struct {\n\t\tSecondLevel string `json:"secondLevel" example:"exampleDataHere"`\n\t} `json:"topLevel"`\n}\n' ,
129
130
} ,
130
131
{
131
132
input : '{"people": [{ "name": "Frank"}, {"name": "Dennis"}, {"name": "Dee"}, {"name": "Charley"}, {"name":"Mac"}] }' ,
132
133
expected :
133
- 'type AutoGenerated struct {\n\tPeople []struct {\n\t\tName string `json:"name"`\n\t} `json:"people"`\n}' ,
134
+ 'type AutoGenerated struct {\n\tPeople []struct {\n\t\tName string `json:"name"`\n\t} `json:"people"`\n}\n ' ,
134
135
expectedWithExample :
135
- 'type AutoGenerated struct {\n\tPeople []struct {\n\t\tName string `json:"name" example:"Frank"`\n\t} `json:"people"`\n}'
136
- } ] ;
136
+ 'type AutoGenerated struct {\n\tPeople []struct {\n\t\tName string `json:"name" example:"Frank"`\n\t} `json:"people"`\n}\n' ,
137
+ } ,
138
+ ] ;
137
139
138
140
for ( const testCase of testCases ) {
139
141
const got = jsonToGo ( testCase . input , null , null , includeExampleData ) ;
@@ -143,9 +145,7 @@ function test(includeExampleData) {
143
145
exp = includeExampleData ? testCase . expectedWithExample : testCase . expected
144
146
console . assert (
145
147
got . go === exp ,
146
- `format('${ testCase . input } '): \n\tgot: ${ quote ( got . go ) } \n\twant: ${
147
- quote ( exp )
148
- } `
148
+ `format('${ testCase . input } '): \n\tgot: ${ quote ( got . go ) } \n\twant: ${ quote ( exp ) } `
149
149
) ;
150
150
}
151
151
}
@@ -154,4 +154,4 @@ function test(includeExampleData) {
154
154
}
155
155
156
156
test ( false ) ;
157
- test ( true )
157
+ test ( true )
0 commit comments