cuelang.org/go@v0.13.0/pkg/encoding/json/testdata/gen.txtar (about) 1 # generated from the original tests. 2 # Henceforth it may be nicer to group tests into separate files. 3 -- in.cue -- 4 import "encoding/json" 5 6 validate: [string]: { 7 str: string | *"{\"a\":10}" 8 schema: _ 9 result: json.Validate(str, schema) 10 } 11 validate: t1: schema: {b: string} 12 validate: t2: schema: {a: <3} 13 14 validate: disjunctionRequired: schema: {a!: int} | {b!: int} 15 validate: disjunctionClosed: schema: close({a: int}) | close({b: int}) 16 17 // Issue #2395 18 validate: enforceRequired: { 19 str: "{}" 20 schema: {x!: int} 21 } 22 23 issue3932: { 24 f: json.Validate({name!: string}) 25 f: json.Marshal({name: "foo"}) 26 } 27 28 valid: [string]: { 29 string // input 30 #result: json.Valid(string) 31 } 32 valid: t1: "1" 33 34 compact: [string]: X={ 35 _ // input 36 #result: json.Compact(X) 37 } 38 compact: t1: "[1, 2]" 39 40 indent: [string]: X={ 41 string // input 42 #initial: *"" | string 43 #indent: *" " | string 44 #result: json.Indent(X, #initial, #indent) 45 } 46 indent: t1: #"{"a": 1, "b": 2}"# 47 48 unmarshal: [string]: X={ 49 string // input 50 #result: json.Unmarshal(X) 51 } 52 unmarshal: t1: "1" 53 unmarshal: { 54 trailingValid: #"{"a": 1}{"b": 2}"# 55 trailingInvalid: #"{"a": 1}}invalid json"# 56 } 57 58 marshalStream: [string]: X={ 59 [...] // input 60 #result: json.MarshalStream(X) 61 } 62 marshalStream: t1: [{a: 1}, {b: 2}] 63 marshalStream: t2: [{a: 1}, {b: int | *2}] 64 marshalStream: t3: [{a: #"\ " & < >"#}, {b: ""}] 65 66 67 marshal: [string]: X={ 68 _ // input 69 #result: json.Marshal(X) 70 } 71 marshal: t1: { 72 #x: int 73 a: #x 74 } 75 76 marshal: t2: {a: #"\ " & < >"#} 77 78 htmlEscape: [string]: X={ 79 string // input 80 #result: json.HTMLEscape(X) 81 } 82 htmlEscape: t1: marshal.t2.#result 83 htmlEscape: t2: marshalStream.t3.#result 84 85 unmarshalStream: [string]: X={ 86 string | bytes // input 87 #result: json.UnmarshalStream(X) 88 } 89 unmarshalStream: { 90 t1: #"{"a": 1}{"b": 2}"# 91 t2: #'{"a": 1}{"b": 2}'# 92 empty1: '' 93 empty2: "" 94 nums1: '1 2' 95 nums2: "1 2" 96 } 97 -- out/json -- 98 Errors: 99 validate.t2.result: error in call to encoding/json.Validate: invalid value 10 (out of bound <3): 100 ./in.cue:6:10 101 ./in.cue:9:27 102 json.Validate:1:6 103 unmarshal.trailingInvalid.#result: error in call to encoding/json.Unmarshal: json: invalid JSON: 104 ./in.cue:47:11 105 unmarshal.trailingValid.#result: error in call to encoding/json.Unmarshal: json: invalid JSON: 106 ./in.cue:47:11 107 108 Result: 109 import "encoding/json" 110 111 validate: { 112 t1: { 113 str: *"{\"a\":10}" | string 114 schema: { 115 b: string 116 } 117 result: true 118 } 119 t2: { 120 str: *"{\"a\":10}" | string 121 schema: { 122 a: <3 123 } 124 result: _|_ // validate.t2.result: error in call to encoding/json.Validate: validate.t2.result.a: invalid value 10 (out of bound <3) 125 } 126 disjunctionRequired: { 127 str: *"{\"a\":10}" | string 128 schema: { 129 a!: int 130 } | { 131 b!: int 132 } 133 result: true 134 } 135 disjunctionClosed: { 136 str: *"{\"a\":10}" | string 137 schema: { 138 a: int 139 } | { 140 b: int 141 } 142 result: true 143 } 144 145 // Issue #2395 146 enforceRequired: { 147 str: "{}" 148 schema: { 149 x!: int 150 } 151 result: json.Validate(str, schema) 152 } 153 } 154 issue3932: { 155 f: "{\"name\":\"foo\"}" 156 } 157 valid: { 158 t1: { 159 "1" 160 #result: json.Valid(string) 161 } 162 } 163 compact: { 164 t1: { 165 "[1, 2]" 166 #result: "[1,2]" 167 } 168 } 169 indent: { 170 t1: { 171 "{\"a\": 1, \"b\": 2}" 172 #initial: *"" | string 173 #indent: *" " | string 174 #result: """ 175 { 176 "a": 1, 177 "b": 2 178 } 179 """ 180 } 181 } 182 unmarshal: { 183 t1: { 184 "1" 185 #result: 1 186 } 187 trailingValid: { 188 #result: _|_ // unmarshal.trailingValid.#result: error in call to encoding/json.Unmarshal: json: invalid JSON 189 } 190 trailingInvalid: { 191 #result: _|_ // unmarshal.trailingInvalid.#result: error in call to encoding/json.Unmarshal: json: invalid JSON 192 } 193 } 194 marshalStream: { 195 t1: { 196 #result: """ 197 {"a":1} 198 {"b":2} 199 200 """ 201 [{ 202 a: 1 203 }, { 204 b: 2 205 }] 206 } 207 t2: { 208 #result: """ 209 {"a":1} 210 {"b":2} 211 212 """ 213 [{ 214 a: 1 215 }, { 216 b: *2 | int 217 }] 218 } 219 t3: { 220 #result: """ 221 {"a":"\\\\ \\" & < >"} 222 {"b":""} 223 224 """ 225 [{ 226 a: "\\ \" & < >" 227 }, { 228 b: "" 229 }] 230 } 231 } 232 marshal: { 233 t1: { 234 #result: json.Marshal(X) 235 #x: int 236 a: int 237 } 238 t2: { 239 #result: "{\"a\":\"\\\\ \\\" & < >\"}" 240 a: "\\ \" & < >" 241 } 242 } 243 htmlEscape: { 244 t1: { 245 "{\"a\":\"\\\\ \\\" & < >\"}" 246 #result: "{\"a\":\"\\\\ \\\" \\u0026 \\u003c \\u003e\"}" 247 } 248 t2: { 249 """ 250 {"a":"\\\\ \\" & < >"} 251 {"b":""} 252 253 """ 254 #result: """ 255 {"a":"\\\\ \\" \\u0026 \\u003c \\u003e"} 256 {"b":""} 257 258 """ 259 } 260 } 261 unmarshalStream: { 262 t1: { 263 "{\"a\": 1}{\"b\": 2}" 264 #result: [{ 265 a: 1 266 }, { 267 b: 2 268 }] 269 } 270 t2: { 271 '{"a": 1}{"b": 2}' 272 #result: [{ 273 a: 1 274 }, { 275 b: 2 276 }] 277 } 278 empty1: { 279 '' 280 #result: [] 281 } 282 empty2: { 283 "" 284 #result: [] 285 } 286 nums1: { 287 '1 2' 288 #result: [1, 2] 289 } 290 nums2: { 291 "1 2" 292 #result: [1, 2] 293 } 294 }