cuelang.org/go@v0.10.1/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 valid: [string]: { 24 string // input 25 #result: json.Valid(string) 26 } 27 valid: t1: "1" 28 29 compact: [string]: X={ 30 _ // input 31 #result: json.Compact(X) 32 } 33 compact: t1: "[1, 2]" 34 35 indent: [string]: X={ 36 string // input 37 #initial: *"" | string 38 #indent: *" " | string 39 #result: json.Indent(X, #initial, #indent) 40 } 41 indent: t1: #"{"a": 1, "b": 2}"# 42 43 unmarshal: [string]: X={ 44 string // input 45 #result: json.Unmarshal(X) 46 } 47 unmarshal: t1: "1" 48 unmarshal: { 49 trailingValid: #"{"a": 1}{"b": 2}"# 50 trailingInvalid: #"{"a": 1}}invalid json"# 51 } 52 53 marshalStream: [string]: X={ 54 [...] // input 55 #result: json.MarshalStream(X) 56 } 57 marshalStream: t1: [{a: 1}, {b: 2}] 58 marshalStream: t2: [{a: 1}, {b: int | *2}] 59 marshalStream: t3: [{a: #"\ " & < >"#}, {b: ""}] 60 61 62 marshal: [string]: X={ 63 _ // input 64 #result: json.Marshal(X) 65 } 66 marshal: t1: { 67 #x: int 68 a: #x 69 } 70 71 marshal: t2: {a: #"\ " & < >"#} 72 73 htmlEscape: [string]: X={ 74 string // input 75 #result: json.HTMLEscape(X) 76 } 77 htmlEscape: t1: marshal.t2.#result 78 htmlEscape: t2: marshalStream.t3.#result 79 80 unmarshalStream: [string]: X={ 81 string | bytes // input 82 #result: json.UnmarshalStream(X) 83 } 84 unmarshalStream: { 85 t1: #"{"a": 1}{"b": 2}"# 86 t2: #'{"a": 1}{"b": 2}'# 87 empty1: '' 88 empty2: "" 89 nums1: '1 2' 90 nums2: "1 2" 91 } 92 -- out/json-v3 -- 93 Errors: 94 validate.t2.result: error in call to encoding/json.Validate: invalid value 10 (out of bound <3): 95 ./in.cue:6:10 96 ./in.cue:9:27 97 json.Validate:1:6 98 unmarshal.trailingInvalid.#result: error in call to encoding/json.Unmarshal: json: invalid JSON: 99 ./in.cue:42:11 100 unmarshal.trailingValid.#result: error in call to encoding/json.Unmarshal: json: invalid JSON: 101 ./in.cue:42:11 102 103 Result: 104 import "encoding/json" 105 106 validate: { 107 t1: { 108 str: *"{\"a\":10}" | string 109 schema: { 110 b: string 111 } 112 result: true 113 } 114 t2: { 115 str: *"{\"a\":10}" | string 116 schema: { 117 a: <3 118 } 119 result: _|_ // validate.t2.result: error in call to encoding/json.Validate: validate.t2.schema.a: invalid value 10 (out of bound <3) 120 } 121 disjunctionRequired: { 122 str: *"{\"a\":10}" | string 123 schema: { 124 a!: int 125 } | { 126 b!: int 127 } 128 result: json.Validate(str, schema) 129 } 130 disjunctionClosed: { 131 str: *"{\"a\":10}" | string 132 schema: { 133 a: int 134 } | { 135 b: int 136 } 137 result: json.Validate(str, schema) 138 } 139 140 // Issue #2395 141 enforceRequired: { 142 str: "{}" 143 schema: { 144 x!: int 145 } 146 result: json.Validate(str, schema) 147 } 148 } 149 valid: { 150 t1: { 151 "1" 152 #result: json.Valid(string) 153 } 154 } 155 compact: { 156 t1: { 157 "[1, 2]" 158 #result: "[1,2]" 159 } 160 } 161 indent: { 162 t1: { 163 "{\"a\": 1, \"b\": 2}" 164 #initial: *"" | string 165 #indent: *" " | string 166 #result: """ 167 { 168 "a": 1, 169 "b": 2 170 } 171 """ 172 } 173 } 174 unmarshal: { 175 t1: { 176 "1" 177 #result: 1 178 } 179 trailingValid: { 180 #result: _|_ // unmarshal.trailingValid.#result: error in call to encoding/json.Unmarshal: json: invalid JSON 181 } 182 trailingInvalid: { 183 #result: _|_ // unmarshal.trailingInvalid.#result: error in call to encoding/json.Unmarshal: json: invalid JSON 184 } 185 } 186 marshalStream: { 187 t1: { 188 #result: json.MarshalStream(X) 189 [{ 190 a: 1 191 }, { 192 b: 2 193 }] 194 } 195 t2: { 196 #result: json.MarshalStream(X) 197 [{ 198 a: 1 199 }, { 200 b: *2 | int 201 }] 202 } 203 t3: { 204 #result: json.MarshalStream(X) 205 [{ 206 a: "\\ \" & < >" 207 }, { 208 b: "" 209 }] 210 } 211 } 212 marshal: { 213 t1: { 214 #x: int 215 a: #x 216 } & { 217 _ 218 #result: json.Marshal(X) 219 } 220 t2: { 221 a: #"\ " & < >"# 222 } & { 223 _ 224 #result: json.Marshal(X) 225 } 226 } 227 htmlEscape: { 228 t1: marshal.t2.#result & { 229 string 230 #result: json.HTMLEscape(X) 231 } 232 t2: marshalStream.t3.#result & { 233 string 234 #result: json.HTMLEscape(X) 235 } 236 } 237 unmarshalStream: { 238 t1: { 239 "{\"a\": 1}{\"b\": 2}" 240 #result: [{ 241 a: 1 242 }, { 243 b: 2 244 }] 245 } 246 t2: { 247 '{"a": 1}{"b": 2}' 248 #result: [{ 249 a: 1 250 }, { 251 b: 2 252 }] 253 } 254 empty1: { 255 '' 256 #result: [] 257 } 258 empty2: { 259 "" 260 #result: [] 261 } 262 nums1: { 263 '1 2' 264 #result: [1, 2] 265 } 266 nums2: { 267 "1 2" 268 #result: [1, 2] 269 } 270 } 271 -- diff/-out/json-v3<==>+out/json -- 272 diff old new 273 --- old 274 +++ new 275 @@ -93,23 +93,15 @@ 276 } 277 marshalStream: { 278 t1: { 279 - #result: """ 280 - {"a":1} 281 - {"b":2} 282 - 283 - """ 284 - [{ 285 - a: 1 286 - }, { 287 - b: 2 288 - }] 289 - } 290 - t2: { 291 - #result: """ 292 - {"a":1} 293 - {"b":2} 294 - 295 - """ 296 + #result: json.MarshalStream(X) 297 + [{ 298 + a: 1 299 + }, { 300 + b: 2 301 + }] 302 + } 303 + t2: { 304 + #result: json.MarshalStream(X) 305 [{ 306 a: 1 307 }, { 308 @@ -117,11 +109,7 @@ 309 }] 310 } 311 t3: { 312 - #result: """ 313 - {"a":"\\\\ \\" & < >"} 314 - {"b":""} 315 - 316 - """ 317 + #result: json.MarshalStream(X) 318 [{ 319 a: "\\ \" & < >" 320 }, { 321 @@ -131,31 +119,27 @@ 322 } 323 marshal: { 324 t1: { 325 - #x: int 326 - #result: json.Marshal(X) 327 - a: int 328 - } 329 - t2: { 330 - a: "\\ \" & < >" 331 - #result: "{\"a\":\"\\\\ \\\" & < >\"}" 332 + #x: int 333 + a: #x 334 + } & { 335 + _ 336 + #result: json.Marshal(X) 337 + } 338 + t2: { 339 + a: #"\ " & < >"# 340 + } & { 341 + _ 342 + #result: json.Marshal(X) 343 } 344 } 345 htmlEscape: { 346 - t1: { 347 - "{\"a\":\"\\\\ \\\" & < >\"}" 348 - #result: "{\"a\":\"\\\\ \\\" \\u0026 \\u003c \\u003e\"}" 349 - } 350 - t2: { 351 - """ 352 - {"a":"\\\\ \\" & < >"} 353 - {"b":""} 354 - 355 - """ 356 - #result: """ 357 - {"a":"\\\\ \\" \\u0026 \\u003c \\u003e"} 358 - {"b":""} 359 - 360 - """ 361 + t1: marshal.t2.#result & { 362 + string 363 + #result: json.HTMLEscape(X) 364 + } 365 + t2: marshalStream.t3.#result & { 366 + string 367 + #result: json.HTMLEscape(X) 368 } 369 } 370 unmarshalStream: { 371 -- diff/todo/p0 -- 372 Builtins left as unevaluated in output. 373 -- out/json -- 374 Errors: 375 validate.t2.result: error in call to encoding/json.Validate: invalid value 10 (out of bound <3): 376 ./in.cue:6:10 377 ./in.cue:9:27 378 json.Validate:1:6 379 unmarshal.trailingInvalid.#result: error in call to encoding/json.Unmarshal: json: invalid JSON: 380 ./in.cue:42:11 381 unmarshal.trailingValid.#result: error in call to encoding/json.Unmarshal: json: invalid JSON: 382 ./in.cue:42:11 383 384 Result: 385 import "encoding/json" 386 387 validate: { 388 t1: { 389 str: *"{\"a\":10}" | string 390 schema: { 391 b: string 392 } 393 result: true 394 } 395 t2: { 396 str: *"{\"a\":10}" | string 397 schema: { 398 a: <3 399 } 400 result: _|_ // validate.t2.result: error in call to encoding/json.Validate: validate.t2.schema.a: invalid value 10 (out of bound <3) 401 } 402 disjunctionRequired: { 403 str: *"{\"a\":10}" | string 404 schema: { 405 a!: int 406 } | { 407 b!: int 408 } 409 result: json.Validate(str, schema) 410 } 411 disjunctionClosed: { 412 str: *"{\"a\":10}" | string 413 schema: { 414 a: int 415 } | { 416 b: int 417 } 418 result: json.Validate(str, schema) 419 } 420 421 // Issue #2395 422 enforceRequired: { 423 str: "{}" 424 schema: { 425 x!: int 426 } 427 result: json.Validate(str, schema) 428 } 429 } 430 valid: { 431 t1: { 432 "1" 433 #result: json.Valid(string) 434 } 435 } 436 compact: { 437 t1: { 438 "[1, 2]" 439 #result: "[1,2]" 440 } 441 } 442 indent: { 443 t1: { 444 "{\"a\": 1, \"b\": 2}" 445 #initial: *"" | string 446 #indent: *" " | string 447 #result: """ 448 { 449 "a": 1, 450 "b": 2 451 } 452 """ 453 } 454 } 455 unmarshal: { 456 t1: { 457 "1" 458 #result: 1 459 } 460 trailingValid: { 461 #result: _|_ // unmarshal.trailingValid.#result: error in call to encoding/json.Unmarshal: json: invalid JSON 462 } 463 trailingInvalid: { 464 #result: _|_ // unmarshal.trailingInvalid.#result: error in call to encoding/json.Unmarshal: json: invalid JSON 465 } 466 } 467 marshalStream: { 468 t1: { 469 #result: """ 470 {"a":1} 471 {"b":2} 472 473 """ 474 [{ 475 a: 1 476 }, { 477 b: 2 478 }] 479 } 480 t2: { 481 #result: """ 482 {"a":1} 483 {"b":2} 484 485 """ 486 [{ 487 a: 1 488 }, { 489 b: *2 | int 490 }] 491 } 492 t3: { 493 #result: """ 494 {"a":"\\\\ \\" & < >"} 495 {"b":""} 496 497 """ 498 [{ 499 a: "\\ \" & < >" 500 }, { 501 b: "" 502 }] 503 } 504 } 505 marshal: { 506 t1: { 507 #x: int 508 #result: json.Marshal(X) 509 a: int 510 } 511 t2: { 512 a: "\\ \" & < >" 513 #result: "{\"a\":\"\\\\ \\\" & < >\"}" 514 } 515 } 516 htmlEscape: { 517 t1: { 518 "{\"a\":\"\\\\ \\\" & < >\"}" 519 #result: "{\"a\":\"\\\\ \\\" \\u0026 \\u003c \\u003e\"}" 520 } 521 t2: { 522 """ 523 {"a":"\\\\ \\" & < >"} 524 {"b":""} 525 526 """ 527 #result: """ 528 {"a":"\\\\ \\" \\u0026 \\u003c \\u003e"} 529 {"b":""} 530 531 """ 532 } 533 } 534 unmarshalStream: { 535 t1: { 536 "{\"a\": 1}{\"b\": 2}" 537 #result: [{ 538 a: 1 539 }, { 540 b: 2 541 }] 542 } 543 t2: { 544 '{"a": 1}{"b": 2}' 545 #result: [{ 546 a: 1 547 }, { 548 b: 2 549 }] 550 } 551 empty1: { 552 '' 553 #result: [] 554 } 555 empty2: { 556 "" 557 #result: [] 558 } 559 nums1: { 560 '1 2' 561 #result: [1, 2] 562 } 563 nums2: { 564 "1 2" 565 #result: [1, 2] 566 } 567 }