gopkg.in/easygen.v4@v4.1.0/test/jq-test_1.yaml (about) 1 # Test cases Copyright (c) 2016 of project 2 # https://github.com/stedolan/jq 3 4 # Test cases converted to YAML format by 5 # Tong Sun Copyright (c) 2016 6 # https://github.com/go-easygen/easygen 7 8 # To update, 9 # cp jq-test_1.y0 jq-test_1.yaml 10 # curl -s https://raw.githubusercontent.com/stedolan/jq/master/tests/jq.test | tr -d '\015' | sed '/^#/s/$/\n/' | perl -n0000e 'if (/^ *#/) { s|^ *# *||; print " - Comment:\n Str: $_" } elsif (/jq: error: |byte order mark/) { next; } else { @tc= split /\n/, $_; print " - TestCase:\n Name: case". ++$i. "\n Op: $tc[0]\n In: $tc[1]\n Out: $tc[2]\n\n" }' | sed -r "/^ Str: .*'/s/'//g; /^ Str: |^ (Op|In|Out): [^']*$/{ s/((Str|Op|In|Out): )/\1'/; s/\$/'/; }" >> jq-test_1.yaml 11 # easygen -tf jq-test_jq jq-test_1 | sed 's|// *$|//|' | gofmt > jq-test_1.go_ 12 13 Cases: 14 15 - Comment: 16 Str: 'Tests are groups of three lines: program, input, expected output' 17 18 - Comment: 19 Str: 'Blank lines and lines starting with # are ignored' 20 21 - Comment: 22 Str: '' 23 24 - Comment: 25 Str: 'Simple value tests to check parser. Input is irrelevant' 26 27 - Comment: 28 Str: '' 29 30 - TestCase: 31 Name: case1 32 Op: 'true' 33 In: 'null' 34 Out: 'true' 35 36 - TestCase: 37 Name: case2 38 Op: 'false' 39 In: 'null' 40 Out: 'false' 41 42 - TestCase: 43 Name: case3 44 Op: 'null' 45 In: '42' 46 Out: 'null' 47 48 - TestCase: 49 Name: case4 50 Op: '1' 51 In: 'null' 52 Out: '1' 53 54 - TestCase: 55 Name: case5 56 Op: '-1' 57 In: 'null' 58 Out: '-1' 59 60 - Comment: 61 Str: 'FIXME: much more number testing needed' 62 63 - TestCase: 64 Name: case6 65 Op: '{}' 66 In: 'null' 67 Out: '{}' 68 69 - TestCase: 70 Name: case7 71 Op: '[]' 72 In: 'null' 73 Out: '[]' 74 75 - TestCase: 76 Name: case8 77 Op: '{x: -1}' 78 In: 'null' 79 Out: '{"x": -1}' 80 81 - Comment: 82 Str: 'The input line starts with a 0xFEFF (byte order mark) codepoint' 83 84 - Comment: 85 Str: 'No, there is no reason to have a byte order mark in UTF8 text.' 86 87 - Comment: 88 Str: 'But apparently people do, so jq shouldnt break on it.' 89 90 - Comment: 91 Str: 'We test escapes by matching them against Unicode codepoints' 92 93 - Comment: 94 Str: 'FIXME: more tests needed for weird unicode stuff (e.g. utf16 pairs)' 95 96 - TestCase: 97 Name: case9 98 Op: '"Aa\r\n\t\b\f\u03bc"' 99 In: 'null' 100 Out: '"Aa\u000d\u000a\u0009\u0008\u000c\u03bc"' 101 102 - TestCase: 103 Name: case10 104 Op: '.' 105 In: '"Aa\r\n\t\b\f\u03bc"' 106 Out: '"Aa\u000d\u000a\u0009\u0008\u000c\u03bc"' 107 108 - TestCase: 109 Name: case11 110 Op: '"inter\("pol" + "ation")"' 111 In: 'null' 112 Out: '"interpolation"' 113 114 - TestCase: 115 Name: case12 116 Op: '@text,@json,([1,.] | (@csv, @tsv)),@html,@uri,@sh,@base64' 117 In: "<>&'\"\t" 118 Out: "<>&'\"\t" 119 120 - Comment: 121 Str: 'regression test for #436' 122 123 - TestCase: 124 Name: case13 125 Op: '@base64' 126 In: '"foóbar\n"' 127 Out: '"Zm/Ds2Jhcgo="' 128 129 - TestCase: 130 Name: case14 131 Op: '@uri' 132 In: '"\u03bc"' 133 Out: '"%CE%BC"' 134 135 - TestCase: 136 Name: case15 137 Op: '@html "<b>\(.)</b>"' 138 In: '"<script>hax</script>"' 139 Out: '"<b><script>hax</script></b>"' 140 141 - TestCase: 142 Name: case16 143 Op: '[.[]|tojson|fromjson]' 144 In: '["foo", 1, ["a", 1, "b", 2, {"foo":"bar"}]]' 145 Out: '["foo",1,["a",1,"b",2,{"foo":"bar"}]]' 146 147 - Comment: 148 Str: '' 149 150 - Comment: 151 Str: 'Dictionary construction syntax' 152 153 - Comment: 154 Str: '' 155 156 - TestCase: 157 Name: case17 158 Op: '{a: 1}' 159 In: 'null' 160 Out: '{"a":1}' 161 162 - TestCase: 163 Name: case18 164 Op: '{a,b,(.d):.a,e:.b}' 165 In: '{"a":1, "b":2, "c":3, "d":"c"}' 166 Out: '{"a":1, "b":2, "c":1, "e":2}' 167 168 - TestCase: 169 Name: case19 170 Op: '{"a",b,"a$\(1+1)"}' 171 In: '{"a":1, "b":2, "c":3, "a$2":4}' 172 Out: '{"a":1, "b":2, "a$2":4}' 173 174 - Comment: 175 Str: '' 176 177 - Comment: 178 Str: 'Field access, piping' 179 180 - Comment: 181 Str: '' 182 183 - TestCase: 184 Name: case20 185 Op: '.foo' 186 In: '{"foo": 42, "bar": 43}' 187 Out: '42' 188 189 - TestCase: 190 Name: case21 191 Op: '.foo | .bar' 192 In: '{"foo": {"bar": 42}, "bar": "badvalue"}' 193 Out: '42' 194 195 - TestCase: 196 Name: case22 197 Op: '.foo.bar' 198 In: '{"foo": {"bar": 42}, "bar": "badvalue"}' 199 Out: '42' 200 201 - TestCase: 202 Name: case23 203 Op: '.foo_bar' 204 In: '{"foo_bar": 2}' 205 Out: '2' 206 207 - TestCase: 208 Name: case24 209 Op: '.["foo"].bar' 210 In: '{"foo": {"bar": 42}, "bar": "badvalue"}' 211 Out: '42' 212 213 - TestCase: 214 Name: case25 215 Op: '."foo"."bar"' 216 In: '{"foo": {"bar": 20}}' 217 Out: '20' 218 219 - TestCase: 220 Name: case26 221 Op: '[.[]|.foo?]' 222 In: '[1,[2],{"foo":3,"bar":4},{},{"foo":5}]' 223 Out: '[3,null,5]' 224 225 - TestCase: 226 Name: case27 227 Op: '[.[]|.foo?.bar?]' 228 In: '[1,[2],[],{"foo":3},{"foo":{"bar":4}},{}]' 229 Out: '[4,null]' 230 231 - TestCase: 232 Name: case28 233 Op: '[..]' 234 In: '[1,[[2]],{ "a":[1]}]' 235 Out: '[[1,[[2]],{"a":[1]}],1,[[2]],[2],2,{"a":[1]},[1],1]' 236 237 - TestCase: 238 Name: case29 239 Op: '[.[]|.[]?]' 240 In: '[1,null,[],[1,[2,[[3]]]],[{}],[{"a":[1,[2]]}]]' 241 Out: '[1,[2,[[3]]],{},{"a":[1,[2]]}]' 242 243 - TestCase: 244 Name: case30 245 Op: '[.[]|.[1:3]?]' 246 In: '[1,null,true,false,"abcdef",{},{"a":1,"b":2},[],[1,2,3,4,5],[1,2]]' 247 Out: '[null,"bc",[],[2,3],[2]]' 248 249 - Comment: 250 Str: '' 251 252 - Comment: 253 Str: 'Negative array indices' 254 255 - Comment: 256 Str: '' 257 258 - TestCase: 259 Name: case31 260 Op: 'try (.foo[-1] = 0) catch .' 261 In: 'null' 262 Out: '"Out of bounds negative array index"' 263 264 - TestCase: 265 Name: case32 266 Op: 'try (.foo[-2] = 0) catch .' 267 In: 'null' 268 Out: '"Out of bounds negative array index"' 269 270 - TestCase: 271 Name: case33 272 Op: '.[-1] = 5' 273 In: '[0,1,2]' 274 Out: '[0,1,5]' 275 276 - TestCase: 277 Name: case34 278 Op: '.[-2] = 5' 279 In: '[0,1,2]' 280 Out: '[0,5,2]' 281 282 - Comment: 283 Str: '' 284 285 - Comment: 286 Str: 'Multiple outputs, iteration' 287 288 - Comment: 289 Str: '' 290 291 - TestCase: 292 Name: case35 293 Op: '.[]' 294 In: '[1,2,3]' 295 Out: '1' 296 297 - TestCase: 298 Name: case36 299 Op: '1,1' 300 In: '[]' 301 Out: '1' 302 303 - TestCase: 304 Name: case37 305 Op: '1,.' 306 In: '[]' 307 Out: '1' 308 309 - TestCase: 310 Name: case38 311 Op: '[.]' 312 In: '[2]' 313 Out: '[[2]]' 314 315 - TestCase: 316 Name: case39 317 Op: '[[2]]' 318 In: '[3]' 319 Out: '[[2]]' 320 321 - TestCase: 322 Name: case40 323 Op: '[{}]' 324 In: '[2]' 325 Out: '[{}]' 326 327 - TestCase: 328 Name: case41 329 Op: '[.[]]' 330 In: '["a"]' 331 Out: '["a"]' 332 333 - TestCase: 334 Name: case42 335 Op: '[(.,1),((.,.[]),(2,3))]' 336 In: '["a","b"]' 337 Out: '[["a","b"],1,["a","b"],"a","b",2,3]' 338 339 - TestCase: 340 Name: case43 341 Op: '[([5,5][]),.,.[]]' 342 In: '[1,2,3]' 343 Out: '[5,5,[1,2,3],1,2,3]' 344 345 - TestCase: 346 Name: case44 347 Op: '{x: (1,2)},{x:3} | .x' 348 In: 'null' 349 Out: '1' 350 351 - TestCase: 352 Name: case45 353 Op: '.[-2]' 354 In: '[1,2,3]' 355 Out: '2' 356 357 - TestCase: 358 Name: case46 359 Op: '[range(0;10)]' 360 In: 'null' 361 Out: '[0,1,2,3,4,5,6,7,8,9]' 362 363 - TestCase: 364 Name: case47 365 Op: '[range(0,1;3,4)]' 366 In: 'null' 367 Out: '[0,1,2, 0,1,2,3, 1,2, 1,2,3]' 368 369 - TestCase: 370 Name: case48 371 Op: '[range(0;10;3)]' 372 In: 'null' 373 Out: '[0,3,6,9]' 374 375 - TestCase: 376 Name: case49 377 Op: '[range(0;10;-1)]' 378 In: 'null' 379 Out: '[]' 380 381 - TestCase: 382 Name: case50 383 Op: '[range(0;-5;-1)]' 384 In: 'null' 385 Out: '[0,-1,-2,-3,-4]' 386 387 - TestCase: 388 Name: case51 389 Op: '[range(0,1;4,5;1,2)]' 390 In: 'null' 391 Out: '[0,1,2,3,0,2, 0,1,2,3,4,0,2,4, 1,2,3,1,3, 1,2,3,4,1,3]' 392 393 - TestCase: 394 Name: case52 395 Op: '[while(.<100; .*2)]' 396 In: '1' 397 Out: '[1,2,4,8,16,32,64]' 398 399 - TestCase: 400 Name: case53 401 Op: '[(label $here | .[] | if .>1 then break $here else . end), "hi!"]' 402 In: '[0,1,2]' 403 Out: '[0,1,"hi!"]' 404 405 - TestCase: 406 Name: case54 407 Op: '[(label $here | .[] | if .>1 then break $here else . end), "hi!"]' 408 In: '[0,2,1]' 409 Out: '[0,"hi!"]' 410 411 - TestCase: 412 Name: case55 413 Op: '[.[]|[.,1]|until(.[0] < 1; [.[0] - 1, .[1] * .[0]])|.[1]]' 414 In: '[1,2,3,4,5]' 415 Out: '[1,2,6,24,120]' 416 417 - TestCase: 418 Name: case56 419 Op: '[label $out | foreach .[] as $item ([3, null]; if .[0] < 1 then break $out else [.[0] -1, $item] end; .[1])]' 420 In: '[11,22,33,44,55,66,77,88,99]' 421 Out: '[11,22,33]' 422 423 - TestCase: 424 Name: case57 425 Op: '[foreach range(5) as $item (0; $item)]' 426 In: 'null' 427 Out: '[0,1,2,3,4]' 428 429 - TestCase: 430 Name: case58 431 Op: '[foreach .[] as [$i, $j] (0; . + $i - $j)]' 432 In: '[[2,1], [5,3], [6,4]]' 433 Out: '[1,3,5]' 434 435 - TestCase: 436 Name: case59 437 Op: '[foreach .[] as {a:$a} (0; . + $a; -.)]' 438 In: '[{"a":1}, {"b":2}, {"a":3, "b":4}]' 439 Out: '[-1, -1, -4]' 440 441 - TestCase: 442 Name: case60 443 Op: '[limit(3; .[])]' 444 In: '[11,22,33,44,55,66,77,88,99]' 445 Out: '[11,22,33]' 446 447 - TestCase: 448 Name: case61 449 Op: '[first(range(.)), last(range(.)), nth(0; range(.)), nth(5; range(.)), try nth(-1; range(.)) catch .]' 450 In: '10' 451 Out: [0,9,0,5,"nth doesn't support negative indices"] 452 453 - Comment: 454 Str: '' 455 456 - Comment: 457 Str: 'Check that various builtins evalute all arguments where appropriate,' 458 459 - Comment: 460 Str: 'doing cartesian products where appropriate.' 461 462 - Comment: 463 Str: '' 464 465 - Comment: 466 Str: 'Check that limit does work for each value produced by n!' 467 468 - TestCase: 469 Name: case62 470 Op: '[limit(5,7; range(9))]' 471 In: 'null' 472 Out: '[0,1,2,3,4,0,1,2,3,4,5,6]' 473 474 - Comment: 475 Str: 'Same check for nth' 476 477 - TestCase: 478 Name: case63 479 Op: '[nth(5,7; range(9;0;-1))]' 480 In: 'null' 481 Out: '[4,2]' 482 483 - Comment: 484 Str: 'Same check for range/3' 485 486 - TestCase: 487 Name: case64 488 Op: '[range(0,1,2;4,3,2;2,3)]' 489 In: 'null' 490 Out: '[0,2,0,3,0,2,0,0,0,1,3,1,1,1,1,1,2,2,2,2]' 491 492 - Comment: 493 Str: 'Same check for range/1' 494 495 - TestCase: 496 Name: case65 497 Op: '[range(3,5)]' 498 In: 'null' 499 Out: '[0,1,2,0,1,2,3,4]' 500 501 - Comment: 502 Str: 'Same check for index/1, rindex/1, indices/1' 503 504 - TestCase: 505 Name: case66 506 Op: '[(index(",","|"), rindex(",","|")), indices(",","|")]' 507 In: '"a,b|c,d,e||f,g,h,|,|,i,j"' 508 Out: '[1,3,22,19,[1,5,7,12,14,16,18,20,22],[3,9,10,17,19]]' 509 510 - Comment: 511 Str: 'Same check for join/1' 512 513 - TestCase: 514 Name: case67 515 Op: 'join(",","/")' 516 In: '["a","b","c","d"]' 517 Out: '"a,b,c,d"' 518 519 - TestCase: 520 Name: case68 521 Op: '[.[]|join("a")]' 522 In: '[[],[""],["",""],["","",""]]' 523 Out: '["","","a","aa"]' 524 525 - Comment: 526 Str: 'Same check for flatten/1' 527 528 - TestCase: 529 Name: case69 530 Op: 'flatten(3,2,1)' 531 In: '[0, [1], [[2]], [[[3]]]]' 532 Out: '[0,1,2,3]' 533 534 - Comment: 535 Str: '' 536 537 - Comment: 538 Str: 'Slices' 539 540 - Comment: 541 Str: '' 542 543 - TestCase: 544 Name: case70 545 Op: '[.[3:2], .[-5:4], .[:-2], .[-2:], .[3:3][1:], .[10:]]' 546 In: '[0,1,2,3,4,5,6]' 547 Out: '[[], [2,3], [0,1,2,3,4], [5,6], [], []]' 548 549 - TestCase: 550 Name: case71 551 Op: '[.[3:2], .[-5:4], .[:-2], .[-2:], .[3:3][1:], .[10:]]' 552 In: '"abcdefghi"' 553 Out: '["","","abcdefg","hi","",""]' 554 555 - TestCase: 556 Name: case72 557 Op: 'del(.[2:4],.[0],.[-2:])' 558 In: '[0,1,2,3,4,5,6,7]' 559 Out: '[1,4,5]' 560 561 - TestCase: 562 Name: case73 563 Op: '.[2:4] = ([], ["a","b"], ["a","b","c"])' 564 In: '[0,1,2,3,4,5,6,7]' 565 Out: '[0,1,4,5,6,7]' 566 567 - Comment: 568 Str: '' 569 570 - Comment: 571 Str: 'Variables' 572 573 - Comment: 574 Str: '' 575 576 - TestCase: 577 Name: case74 578 Op: '1 as $x | 2 as $y | [$x,$y,$x]' 579 In: 'null' 580 Out: '[1,2,1]' 581 582 - TestCase: 583 Name: case75 584 Op: '[1,2,3][] as $x | [[4,5,6,7][$x]]' 585 In: 'null' 586 Out: '[5]' 587 588 - TestCase: 589 Name: case76 590 Op: '42 as $x | . | . | . + 432 | $x + 1' 591 In: '34324' 592 Out: '43' 593 594 - TestCase: 595 Name: case77 596 Op: '1 as $x | [$x,$x,$x as $x | $x]' 597 In: 'null' 598 Out: '[1,1,1]' 599 600 - TestCase: 601 Name: case78 602 Op: '[1, {c:3, d:4}] as [$a, {c:$b, b:$c}] | $a, $b, $c' 603 In: 'null' 604 Out: '1' 605 606 - TestCase: 607 Name: case79 608 Op: '. as {as: $kw, "str": $str, ("e"+"x"+"p"): $exp} | [$kw, $str, $exp]' 609 In: '{"as": 1, "str": 2, "exp": 3}' 610 Out: '[1, 2, 3]' 611 612 - TestCase: 613 Name: case80 614 Op: '.[] as [$a, $b] | [$b, $a]' 615 In: '[[1], [1, 2, 3]]' 616 Out: '[null, 1]' 617 618 - TestCase: 619 Name: case81 620 Op: '. as $i | . as [$i] | $i' 621 In: '[0]' 622 Out: '0' 623 624 - TestCase: 625 Name: case82 626 Op: '. as [$i] | . as $i | $i' 627 In: '[0]' 628 Out: '[0]' 629 630 - Comment: 631 Str: '[.,(.[] | {x:.},.),.,.[]]' 632 633 - Comment: 634 Str: '' 635 636 - Comment: 637 Str: 'Builtin functions' 638 639 - Comment: 640 Str: '' 641 642 - TestCase: 643 Name: case83 644 Op: '1+1' 645 In: 'null' 646 Out: '2' 647 648 - TestCase: 649 Name: case84 650 Op: '1+1' 651 In: '"wtasdf"' 652 Out: '2.0' 653 654 - TestCase: 655 Name: case85 656 Op: '2-1' 657 In: 'null' 658 Out: '1' 659 660 - TestCase: 661 Name: case86 662 Op: '2-(-1)' 663 In: 'null' 664 Out: '3' 665 666 - TestCase: 667 Name: case87 668 Op: '1e+0+0.001e3' 669 In: '"I wonder what this will be?"' 670 Out: '20e-1' 671 672 - TestCase: 673 Name: case88 674 Op: '.+4' 675 In: '15' 676 Out: '19.0' 677 678 - TestCase: 679 Name: case89 680 Op: '.+null' 681 In: '{"a":42}' 682 Out: '{"a":42}' 683 684 - TestCase: 685 Name: case90 686 Op: 'null+.' 687 In: 'null' 688 Out: 'null' 689 690 - TestCase: 691 Name: case91 692 Op: '.a+.b' 693 In: '{"a":42}' 694 Out: '42' 695 696 - TestCase: 697 Name: case92 698 Op: '[1,2,3] + [.]' 699 In: 'null' 700 Out: '[1,2,3,null]' 701 702 - TestCase: 703 Name: case93 704 Op: '{"a":1} + {"b":2} + {"c":3}' 705 In: '"asdfasdf"' 706 Out: '{"a":1, "b":2, "c":3}' 707 708 - TestCase: 709 Name: case94 710 Op: '"asdf" + "jkl;" + . + . + .' 711 In: '"some string"' 712 Out: '"asdfjkl;some stringsome stringsome string"' 713 714 - TestCase: 715 Name: case95 716 Op: '"\u0000\u0020\u0000" + .' 717 In: '"\u0000\u0020\u0000"' 718 Out: '"\u0000 \u0000\u0000 \u0000"' 719 720 - TestCase: 721 Name: case96 722 Op: '42 - .' 723 In: '11' 724 Out: '31' 725 726 - TestCase: 727 Name: case97 728 Op: '[1,2,3,4,1] - [.,3]' 729 In: '1' 730 Out: '[2,4]' 731 732 - TestCase: 733 Name: case98 734 Op: '[10 * 20, 20 / .]' 735 In: '4' 736 Out: '[200, 5]' 737 738 - TestCase: 739 Name: case99 740 Op: '1 + 2 * 2 + 10 / 2' 741 In: 'null' 742 Out: '10' 743 744 - TestCase: 745 Name: case100 746 Op: '[16 / 4 / 2, 16 / 4 * 2, 16 - 4 - 2, 16 - 4 + 2]' 747 In: 'null' 748 Out: '[2, 8, 10, 14]' 749 750 - TestCase: 751 Name: case101 752 Op: '25 % 7' 753 In: 'null' 754 Out: '4' 755 756 - TestCase: 757 Name: case102 758 Op: '49732 % 472' 759 In: 'null' 760 Out: '172' 761 762 - TestCase: 763 Name: case103 764 Op: '1 + tonumber + ("10" | tonumber)' 765 In: '4' 766 Out: '15' 767 768 - TestCase: 769 Name: case104 770 Op: '[{"a":42},.object,10,.num,false,true,null,"b",[1,4]] | .[] as $x | [$x == .[]]' 771 In: '{"object": {"a":42}, "num":10.0}' 772 Out: '[true, true, false, false, false, false, false, false, false]' 773 774 - TestCase: 775 Name: case105 776 Op: '[.[] | length]' 777 In: '[[], {}, [1,2], {"a":42}, "asdf", "\u03bc"]' 778 Out: '[0, 0, 2, 1, 4, 1]' 779 780 - TestCase: 781 Name: case106 782 Op: 'utf8bytelength' 783 In: '"asdf\u03bc"' 784 Out: '6' 785 786 - TestCase: 787 Name: case107 788 Op: '[.[] | try utf8bytelength catch .]' 789 In: '[[], {}, [1,2], 55, true, false]' 790 Out: '["array ([]) only strings have UTF-8 byte length","object ({}) only strings have UTF-8 byte length","array ([1,2]) only strings have UTF-8 byte length","number (55) only strings have UTF-8 byte length","boolean (true) only strings have UTF-8 byte length","boolean (false) only strings have UTF-8 byte length"]' 791 792 - TestCase: 793 Name: case108 794 Op: 'map(keys)' 795 In: '[{}, {"abcd":1,"abc":2,"abcde":3}, {"x":1, "z": 3, "y":2}]' 796 Out: '[[], ["abc","abcd","abcde"], ["x","y","z"]]' 797 798 - TestCase: 799 Name: case109 800 Op: '[1,2,empty,3,empty,4]' 801 In: 'null' 802 Out: '[1,2,3,4]' 803 804 - TestCase: 805 Name: case110 806 Op: 'map(add)' 807 In: '[[], [1,2,3], ["a","b","c"], [[3],[4,5],[6]], [{"a":1}, {"b":2}, {"a":3}]]' 808 Out: '[null, 6, "abc", [3,4,5,6], {"a":3, "b": 2}]' 809 810 - TestCase: 811 Name: case111 812 Op: 'map_values(.+1)' 813 In: '[0,1,2]' 814 Out: '[1,2,3]' 815 816 - Comment: 817 Str: '' 818 819 - Comment: 820 Str: 'User-defined functions' 821 822 - Comment: 823 Str: 'Oh god.' 824 825 - Comment: 826 Str: '' 827 828 - TestCase: 829 Name: case112 830 Op: 'def f: . + 1; def g: def g: . + 100; f | g | f; (f | g), g' 831 In: '3.0' 832 Out: '106.0' 833 834 - TestCase: 835 Name: case113 836 Op: 'def f: (1000,2000); f' 837 In: '123412345' 838 Out: '1000' 839 840 - TestCase: 841 Name: case114 842 Op: 'def f(a;b;c;d;e;f): [a+1,b,c,d,e,f]; f(.[0];.[1];.[0];.[0];.[0];.[0])' 843 In: '[1,2]' 844 Out: '[2,2,1,1,1,1]' 845 846 - Comment: 847 Str: 'Test precedence of def vs |' 848 849 - TestCase: 850 Name: case115 851 Op: 'def a: 0; . | a' 852 In: 'null' 853 Out: '0' 854 855 - Comment: 856 Str: 'Many arguments' 857 858 - TestCase: 859 Name: case116 860 Op: 'def f(a;b;c;d;e;f;g;h;i;j): [j,i,h,g,f,e,d,c,b,a]; f(.[0];.[1];.[2];.[3];.[4];.[5];.[6];.[7];.[8];.[9])' 861 In: '[0,1,2,3,4,5,6,7,8,9]' 862 Out: '[9,8,7,6,5,4,3,2,1,0]' 863 864 - TestCase: 865 Name: case117 866 Op: '([1,2] + [4,5])' 867 In: '[1,2,3]' 868 Out: '[1,2,4,5]' 869 870 - TestCase: 871 Name: case118 872 Op: 'true' 873 In: '[1]' 874 Out: 'true' 875 876 - TestCase: 877 Name: case119 878 Op: 'null,1,null' 879 In: '"hello"' 880 Out: 'null' 881 882 - TestCase: 883 Name: case120 884 Op: '[1,2,3]' 885 In: '[5,6]' 886 Out: '[1,2,3]' 887 888 - TestCase: 889 Name: case121 890 Op: '[.[]|floor]' 891 In: '[-1.1,1.1,1.9]' 892 Out: '[-2, 1, 1]' 893 894 - TestCase: 895 Name: case122 896 Op: '[.[]|sqrt]' 897 In: '[4,9]' 898 Out: '[2,3]' 899 900 - TestCase: 901 Name: case123 902 Op: '(add / length) as $m | map((. - $m) as $d | $d * $d) | add / length | sqrt' 903 In: '[2,4,4,4,5,5,7,9]' 904 Out: '2' 905 906 - Comment: 907 Str: 'Should write a test that calls the -lm function from C (or bc(1)) to' 908 909 - Comment: 910 Str: 'check that they match the corresponding jq functions. However,' 911 912 - Comment: 913 Str: 'theres so little template code standing between that it suffices to' 914 915 - Comment: 916 Str: 'test a handful of these. The results were checked by eye against' 917 918 - Comment: 919 Str: 'bc(1).' 920 921 - TestCase: 922 Name: case124 923 Op: 'atan * 4 * 1000000|floor / 1000000' 924 In: '1' 925 Out: '3.141592' 926 927 - TestCase: 928 Name: case125 929 Op: '[(3.141592 / 2) * (range(0;20) / 20)|cos * 1000000|floor / 1000000]' 930 In: 'null' 931 Out: '[1,0.996917,0.987688,0.972369,0.951056,0.923879,0.891006,0.85264,0.809017,0.760406,0.707106,0.649448,0.587785,0.522498,0.45399,0.382683,0.309017,0.233445,0.156434,0.078459]' 932 933 - TestCase: 934 Name: case126 935 Op: '[(3.141592 / 2) * (range(0;20) / 20)|sin * 1000000|floor / 1000000]' 936 In: 'null' 937 Out: '[0,0.078459,0.156434,0.233445,0.309016,0.382683,0.45399,0.522498,0.587785,0.649447,0.707106,0.760405,0.809016,0.85264,0.891006,0.923879,0.951056,0.972369,0.987688,0.996917]' 938 939 - TestCase: 940 Name: case127 941 Op: 'def f(x): x | x; f([.], . + [42])' 942 In: '[1,2,3]' 943 Out: '[[[1,2,3]]]' 944 945 - Comment: 946 Str: 'test multiple function arities and redefinition' 947 948 - TestCase: 949 Name: case128 950 Op: 'def f: .+1; def g: f; def f: .+100; def f(a):a+.+11; [(g|f(20)), f]' 951 In: '1' 952 Out: '[33,101]' 953 954 - Comment: 955 Str: 'test closures and lexical scoping' 956 957 - TestCase: 958 Name: case129 959 Op: 'def id(x):x; 2000 as $x | def f(x):1 as $x | id([$x, x, x]); def g(x): 100 as $x | f($x,$x+x); g($x)' 960 In: '"more testing"' 961 Out: '[1,100,2100.0,100,2100.0]' 962 963 - Comment: 964 Str: 'test def f($a) syntax' 965 966 - TestCase: 967 Name: case130 968 Op: 'def x(a;b): a as $a | b as $b | $a + $b; def y($a;$b): $a + $b; def check(a;b): [x(a;b)] == [y(a;b)]; check(.[];.[]*2)' 969 In: '[1,2,3]' 970 Out: 'true' 971 972 - Comment: 973 Str: 'test backtracking through function calls and returns' 974 975 - Comment: 976 Str: 'this test is *evil*' 977 978 - TestCase: 979 Name: case131 980 Op: '[[20,10][1,0] as $x | def f: (100,200) as $y | def g: [$x + $y, .]; . + $x | g; f[0] | [f][0][1] | f]' 981 In: '999999999' 982 Out: '[[110.0, 130.0], [210.0, 130.0], [110.0, 230.0], [210.0, 230.0], [120.0, 160.0], [220.0, 160.0], [120.0, 260.0], [220.0, 260.0]]' 983 984 - Comment: 985 Str: 'test recursion' 986 987 - TestCase: 988 Name: case132 989 Op: 'def fac: if . == 1 then 1 else . * (. - 1 | fac) end; [.[] | fac]' 990 In: '[1,2,3,4]' 991 Out: '[1,2,6,24]' 992 993 - Comment: 994 Str: 'test stack overflow and reallocation' 995 996 - Comment: 997 Str: 'this test is disabled for now, it takes a realllllly long time.' 998 999 - Comment: 1000 Str: 'def f: if length > 1000 then . else .+[1]|f end; f | length' 1001 1002 - Comment: 1003 Str: '[]' 1004 1005 - Comment: 1006 Str: '1001' 1007 1008 - TestCase: 1009 Name: case133 1010 Op: 'reduce .[] as $x (0; . + $x)' 1011 In: '[1,2,4]' 1012 Out: '7' 1013 1014 - TestCase: 1015 Name: case134 1016 Op: 'reduce .[] as [$i, {j:$j}] (0; . + $i - $j)' 1017 In: '[[2,{"j":1}], [5,{"j":3}], [6,{"j":4}]]' 1018 Out: '5' 1019 1020 - TestCase: 1021 Name: case135 1022 Op: 'reduce [[1,2,10], [3,4,10]][] as [$i,$j] (0; . + $i * $j)' 1023 In: 'null' 1024 Out: '14' 1025 1026 - TestCase: 1027 Name: case136 1028 Op: '. as $dot|any($dot[];not)' 1029 In: '[1,2,3,4,true,false,1,2,3,4,5]' 1030 Out: 'true' 1031 1032 - TestCase: 1033 Name: case137 1034 Op: '. as $dot|any($dot[];not)' 1035 In: '[1,2,3,4,true]' 1036 Out: 'false' 1037 1038 - TestCase: 1039 Name: case138 1040 Op: '. as $dot|all($dot[];.)' 1041 In: '[1,2,3,4,true,false,1,2,3,4,5]' 1042 Out: 'false' 1043 1044 - TestCase: 1045 Name: case139 1046 Op: '. as $dot|all($dot[];.)' 1047 In: '[1,2,3,4,true]' 1048 Out: 'true' 1049 1050 - Comment: 1051 Str: '' 1052 1053 - Comment: 1054 Str: 'Paths' 1055 1056 - Comment: 1057 Str: '' 1058 1059 - TestCase: 1060 Name: case140 1061 Op: 'path(.foo[0,1])' 1062 In: 'null' 1063 Out: '["foo", 0]' 1064 1065 - TestCase: 1066 Name: case141 1067 Op: 'path(.[] | select(.>3))' 1068 In: '[1,5,3]' 1069 Out: '[1]' 1070 1071 - TestCase: 1072 Name: case142 1073 Op: 'path(.)' 1074 In: '42' 1075 Out: '[]' 1076 1077 - TestCase: 1078 Name: case143 1079 Op: 'try path(.a | map(select(.b == 0))) catch .' 1080 In: '{"a":[{"b":0}]}' 1081 Out: '"Invalid path expression with result [{\"b\":0}]"' 1082 1083 - TestCase: 1084 Name: case144 1085 Op: 'try path(.a | map(select(.b == 0)) | .[0]) catch .' 1086 In: '{"a":[{"b":0}]}' 1087 Out: '"Invalid path expression near attempt to access element 0 of [{\"b\":0}]"' 1088 1089 - TestCase: 1090 Name: case145 1091 Op: 'try path(.a | map(select(.b == 0)) | .c) catch .' 1092 In: '{"a":[{"b":0}]}' 1093 Out: '"Invalid path expression near attempt to access element \"c\" of [{\"b\":0}]"' 1094 1095 - TestCase: 1096 Name: case146 1097 Op: 'try path(.a | map(select(.b == 0)) | .[]) catch .' 1098 In: '{"a":[{"b":0}]}' 1099 Out: '"Invalid path expression near attempt to iterate through [{\"b\":0}]"' 1100 1101 - TestCase: 1102 Name: case147 1103 Op: 'path(.a[path(.b)[0]])' 1104 In: '{"a":{"b":0}}' 1105 Out: '["a","b"]' 1106 1107 - TestCase: 1108 Name: case148 1109 Op: '[paths]' 1110 In: '[1,[[],{"a":2}]]' 1111 Out: '[[0],[1],[1,0],[1,1],[1,1,"a"]]' 1112 1113 - TestCase: 1114 Name: case149 1115 Op: '[leaf_paths]' 1116 In: '[1,[[],{"a":2}]]' 1117 Out: '[[0],[1,1,"a"]]' 1118 1119 - TestCase: 1120 Name: case150 1121 Op: '["foo",1] as $p | getpath($p), setpath($p; 20), delpaths([$p])' 1122 In: '{"bar": 42, "foo": ["a", "b", "c", "d"]}' 1123 Out: '"b"' 1124 1125 - TestCase: 1126 Name: case151 1127 Op: 'map(getpath([2])), map(setpath([2]; 42)), map(delpaths([[2]]))' 1128 In: '[[0], [0,1], [0,1,2]]' 1129 Out: '[null, null, 2]' 1130 1131 - TestCase: 1132 Name: case152 1133 Op: 'map(delpaths([[0,"foo"]]))' 1134 In: '[[{"foo":2, "x":1}], [{"bar":2}]]' 1135 Out: '[[{"x":1}], [{"bar":2}]]' 1136 1137 - TestCase: 1138 Name: case153 1139 Op: '["foo",1] as $p | getpath($p), setpath($p; 20), delpaths([$p])' 1140 In: '{"bar":false}' 1141 Out: 'null' 1142 1143 - TestCase: 1144 Name: case154 1145 Op: 'delpaths([[-200]])' 1146 In: '[1,2,3]' 1147 Out: '[1,2,3]' 1148 1149 - TestCase: 1150 Name: case155 1151 Op: 'try delpaths(0) catch .' 1152 In: '{}' 1153 Out: '"Paths must be specified as an array"' 1154 1155 - TestCase: 1156 Name: case156 1157 Op: 'del(.), del(empty), del((.foo,.bar,.baz) | .[2,3,0]), del(.foo[0], .bar[0], .foo, .baz.bar[0].x)' 1158 In: '{"foo": [0,1,2,3,4], "bar": [0,1]}' 1159 Out: 'null' 1160 1161 - TestCase: 1162 Name: case157 1163 Op: 'del(.[1], .[-6], .[2], .[-3:9])' 1164 In: '[0, 1, 2, 3, 4, 5, 6, 7, 8, 9]' 1165 Out: '[0, 3, 5, 6, 9]' 1166 1167 - Comment: 1168 Str: '' 1169 1170 - Comment: 1171 Str: 'Assignment' 1172 1173 - Comment: 1174 Str: '' 1175 1176 - TestCase: 1177 Name: case158 1178 Op: '.message = "goodbye"' 1179 In: '{"message": "hello"}' 1180 Out: '{"message": "goodbye"}' 1181 1182 - TestCase: 1183 Name: case159 1184 Op: '.foo = .bar' 1185 In: '{"bar":42}' 1186 Out: '{"foo":42, "bar":42}' 1187 1188 - TestCase: 1189 Name: case160 1190 Op: '.foo |= .+1' 1191 In: '{"foo": 42}' 1192 Out: '{"foo": 43}' 1193 1194 - TestCase: 1195 Name: case161 1196 Op: '.[] += 2, .[] *= 2, .[] -= 2, .[] /= 2, .[] %=2' 1197 In: '[1,3,5]' 1198 Out: '[3,5,7]' 1199 1200 - TestCase: 1201 Name: case162 1202 Op: '[.[] % 7]' 1203 In: '[-7,-6,-5,-4,-3,-2,-1,0,1,2,3,4,5,6,7]' 1204 Out: '[0,-6,-5,-4,-3,-2,-1,0,1,2,3,4,5,6,0]' 1205 1206 - TestCase: 1207 Name: case163 1208 Op: '.foo += .foo' 1209 In: '{"foo":2}' 1210 Out: '{"foo":4}' 1211 1212 - TestCase: 1213 Name: case164 1214 Op: '.[0].a |= {"old":., "new":(.+1)}' 1215 In: '[{"a":1,"b":2}]' 1216 Out: '[{"a":{"old":1, "new":2},"b":2}]' 1217 1218 - TestCase: 1219 Name: case165 1220 Op: 'def inc(x): x |= .+1; inc(.[].a)' 1221 In: '[{"a":1,"b":2},{"a":2,"b":4},{"a":7,"b":8}]' 1222 Out: '[{"a":2,"b":2},{"a":3,"b":4},{"a":8,"b":8}]' 1223 1224 - TestCase: 1225 Name: case166 1226 Op: '.[2][3] = 1' 1227 In: '[4]' 1228 Out: '[4, null, [null, null, null, 1]]' 1229 1230 - TestCase: 1231 Name: case167 1232 Op: '.foo[2].bar = 1' 1233 In: '{"foo":[11], "bar":42}' 1234 Out: '{"foo":[11,null,{"bar":1}], "bar":42}' 1235 1236 - TestCase: 1237 Name: case168 1238 Op: 'try ((map(select(.a == 1))[].b) = 10) catch .' 1239 In: '[{"a":0},{"a":1}]' 1240 Out: '"Invalid path expression near attempt to iterate through [{\"a\":1}]"' 1241 1242 - TestCase: 1243 Name: case169 1244 Op: 'try ((map(select(.a == 1))[].a) |= .+1) catch .' 1245 In: '[{"a":0},{"a":1}]' 1246 Out: '"Invalid path expression near attempt to iterate through [{\"a\":1}]"' 1247 1248 - TestCase: 1249 Name: case170 1250 Op: 'def x: .[1,2]; x=10' 1251 In: '[0,1,2]' 1252 Out: '[0,10,10]' 1253 1254 - TestCase: 1255 Name: case171 1256 Op: 'try (def x: reverse; x=10) catch .' 1257 In: '[0,1,2]' 1258 Out: '"Invalid path expression with result [2,1,0]"' 1259 1260 - TestCase: 1261 Name: case172 1262 Op: '.[] = 1' 1263 In: '[1,null,Infinity,-Infinity,NaN,-NaN]' 1264 Out: '[1,1,1,1,1,1]' 1265 1266 - Comment: 1267 Str: '' 1268 1269 - Comment: 1270 Str: 'Conditionals' 1271 1272 - Comment: 1273 Str: '' 1274 1275 - TestCase: 1276 Name: case173 1277 Op: '[.[] | if .foo then "yep" else "nope" end]' 1278 In: '[{"foo":0},{"foo":1},{"foo":[]},{"foo":true},{"foo":false},{"foo":null},{"foo":"foo"},{}]' 1279 Out: '["yep","yep","yep","yep","nope","nope","yep","nope"]' 1280 1281 - TestCase: 1282 Name: case174 1283 Op: '[.[] | if .baz then "strange" elif .foo then "yep" else "nope" end]' 1284 In: '[{"foo":0},{"foo":1},{"foo":[]},{"foo":true},{"foo":false},{"foo":null},{"foo":"foo"},{}]' 1285 Out: '["yep","yep","yep","yep","nope","nope","yep","nope"]' 1286 1287 - TestCase: 1288 Name: case175 1289 Op: '[if 1,null,2 then 3 else 4 end]' 1290 In: 'null' 1291 Out: '[3,4,3]' 1292 1293 - TestCase: 1294 Name: case176 1295 Op: '[if empty then 3 else 4 end]' 1296 In: 'null' 1297 Out: '[]' 1298 1299 - TestCase: 1300 Name: case177 1301 Op: '[if 1 then 3,4 else 5 end]' 1302 In: 'null' 1303 Out: '[3,4]' 1304 1305 - TestCase: 1306 Name: case178 1307 Op: '[if null then 3 else 5,6 end]' 1308 In: 'null' 1309 Out: '[5,6]' 1310 1311 - TestCase: 1312 Name: case179 1313 Op: '[.[] | [.foo[] // .bar]]' 1314 In: '[{"foo":[1,2], "bar": 42}, {"foo":[1], "bar": null}, {"foo":[null,false,3], "bar": 18}, {"foo":[], "bar":42}, {"foo": [null,false,null], "bar": 41}]' 1315 Out: '[[1,2], [1], [3], [42], [41]]' 1316 1317 - TestCase: 1318 Name: case180 1319 Op: '.[] //= .[0]' 1320 In: '["hello",true,false,[false],null]' 1321 Out: '["hello",true,"hello",[false],"hello"]' 1322 1323 - TestCase: 1324 Name: case181 1325 Op: '.[] | [.[0] and .[1], .[0] or .[1]]' 1326 In: '[[true,[]], [false,1], [42,null], [null,false]]' 1327 Out: '[true,true]' 1328 1329 - TestCase: 1330 Name: case182 1331 Op: '[.[] | not]' 1332 In: '[1,0,false,null,true,"hello"]' 1333 Out: '[false,false,true,true,false,false]' 1334 1335 - Comment: 1336 Str: 'Check numeric comparison binops' 1337 1338 - TestCase: 1339 Name: case183 1340 Op: '[10 > 0, 10 > 10, 10 > 20, 10 < 0, 10 < 10, 10 < 20]' 1341 In: '{}' 1342 Out: '[true,false,false,false,false,true]' 1343 1344 - TestCase: 1345 Name: case184 1346 Op: '[10 >= 0, 10 >= 10, 10 >= 20, 10 <= 0, 10 <= 10, 10 <= 20]' 1347 In: '{}' 1348 Out: '[true,true,false,false,true,true]' 1349 1350 - Comment: 1351 Str: 'And some in/equality tests' 1352 1353 - TestCase: 1354 Name: case185 1355 Op: '[ 10 == 10, 10 != 10, 10 != 11, 10 == 11]' 1356 In: '{}' 1357 Out: '[true,false,true,false]' 1358 1359 - TestCase: 1360 Name: case186 1361 Op: '["hello" == "hello", "hello" != "hello", "hello" == "world", "hello" != "world" ]' 1362 In: '{}' 1363 Out: '[true,false,false,true]' 1364 1365 - TestCase: 1366 Name: case187 1367 Op: '[[1,2,3] == [1,2,3], [1,2,3] != [1,2,3], [1,2,3] == [4,5,6], [1,2,3] != [4,5,6]]' 1368 In: '{}' 1369 Out: '[true,false,false,true]' 1370 1371 - TestCase: 1372 Name: case188 1373 Op: '[{"foo":42} == {"foo":42},{"foo":42} != {"foo":42}, {"foo":42} != {"bar":42}, {"foo":42} == {"bar":42}]' 1374 In: '{}' 1375 Out: '[true,false,true,false]' 1376 1377 - Comment: 1378 Str: 'ugly complicated thing' 1379 1380 - TestCase: 1381 Name: case189 1382 Op: '[{"foo":[1,2,{"bar":18},"world"]} == {"foo":[1,2,{"bar":18},"world"]},{"foo":[1,2,{"bar":18},"world"]} == {"foo":[1,2,{"bar":19},"world"]}]' 1383 In: '{}' 1384 Out: '[true,false]' 1385 1386 - Comment: 1387 Str: 'containment operator' 1388 1389 - TestCase: 1390 Name: case190 1391 Op: '[("foo" | contains("foo")), ("foobar" | contains("foo")), ("foo" | contains("foobar"))]' 1392 In: '{}' 1393 Out: '[true, true, false]' 1394 1395 - Comment: 1396 Str: 'Try/catch and general `?` operator' 1397 1398 - TestCase: 1399 Name: case191 1400 Op: '[.[]|try if . == 0 then error("foo") elif . == 1 then .a elif . == 2 then empty else . end catch .]' 1401 In: '[0,1,2,3]' 1402 Out: '["foo","Cannot index number with string \"a\"",3]' 1403 1404 - TestCase: 1405 Name: case192 1406 Op: '[.[]|(.a, .a)?]' 1407 In: '[null,true,{"a":1}]' 1408 Out: '[null,null,1,1]' 1409 1410 - TestCase: 1411 Name: case193 1412 Op: '[[.[]|[.a,.a]]?]' 1413 In: '[null,true,{"a":1}]' 1414 Out: '[]' 1415 1416 - TestCase: 1417 Name: case194 1418 Op: 'try error("\($__loc__)") catch .' 1419 In: 'null' 1420 Out: '"{\"file\":\"<top-level>\",\"line\":1}"' 1421 1422 - Comment: 1423 Str: 'string operations' 1424 1425 - TestCase: 1426 Name: case195 1427 Op: '[.[]|startswith("foo")]' 1428 In: '["fo", "foo", "barfoo", "foobar", "barfoob"]' 1429 Out: '[false, true, false, true, false]' 1430 1431 - TestCase: 1432 Name: case196 1433 Op: '[.[]|endswith("foo")]' 1434 In: '["fo", "foo", "barfoo", "foobar", "barfoob"]' 1435 Out: '[false, true, true, false, false]' 1436 1437 - TestCase: 1438 Name: case197 1439 Op: '[.[] | split(", ")]' 1440 In: '["a,b, c, d, e,f",", a,b, c, d, e,f, "]' 1441 Out: '[["a,b","c","d","e,f"],["","a,b","c","d","e,f",""]]' 1442 1443 - TestCase: 1444 Name: case198 1445 Op: 'split("")' 1446 In: '"abc"' 1447 Out: '["a","b","c"]' 1448 1449 - TestCase: 1450 Name: case199 1451 Op: '[.[]|ltrimstr("foo")]' 1452 In: '["fo", "foo", "barfoo", "foobar", "afoo"]' 1453 Out: '["fo","","barfoo","bar","afoo"]' 1454 1455 - TestCase: 1456 Name: case200 1457 Op: '[.[]|rtrimstr("foo")]' 1458 In: '["fo", "foo", "barfoo", "foobar", "foob"]' 1459 Out: '["fo","","bar","foobar","foob"]' 1460 1461 - TestCase: 1462 Name: case201 1463 Op: '[(index(","), rindex(",")), indices(",")]' 1464 In: '"a,bc,def,ghij,klmno"' 1465 Out: '[1,13,[1,4,8,13]]' 1466 1467 - TestCase: 1468 Name: case202 1469 Op: 'indices(1)' 1470 In: '[0,1,1,2,3,4,1,5]' 1471 Out: '[1,2,6]' 1472 1473 - TestCase: 1474 Name: case203 1475 Op: 'indices([1,2])' 1476 In: '[0,1,2,3,1,4,2,5,1,2,6,7]' 1477 Out: '[1,8]' 1478 1479 - TestCase: 1480 Name: case204 1481 Op: 'indices([1,2])' 1482 In: '[1]' 1483 Out: '[]' 1484 1485 - TestCase: 1486 Name: case205 1487 Op: 'indices(", ")' 1488 In: '"a,b, cd,e, fgh, ijkl"' 1489 Out: '[3,9,14]' 1490 1491 - TestCase: 1492 Name: case206 1493 Op: '[.[]|split(",")]' 1494 In: '["a, bc, def, ghij, jklmn, a,b, c,d, e,f", "a,b,c,d, e,f,g,h"]' 1495 Out: '[["a"," bc"," def"," ghij"," jklmn"," a","b"," c","d"," e","f"],["a","b","c","d"," e","f","g","h"]]' 1496 1497 - TestCase: 1498 Name: case207 1499 Op: '[.[]|split(", ")]' 1500 In: '["a, bc, def, ghij, jklmn, a,b, c,d, e,f", "a,b,c,d, e,f,g,h"]' 1501 Out: '[["a","bc","def","ghij","jklmn","a,b","c,d","e,f"],["a,b,c,d","e,f,g,h"]]' 1502 1503 - TestCase: 1504 Name: case208 1505 Op: '[.[] * 3]' 1506 In: '["a", "ab", "abc"]' 1507 Out: '["aaa", "ababab", "abcabcabc"]' 1508 1509 - TestCase: 1510 Name: case209 1511 Op: '[.[] / ","]' 1512 In: '["a, bc, def, ghij, jklmn, a,b, c,d, e,f", "a,b,c,d, e,f,g,h"]' 1513 Out: '[["a"," bc"," def"," ghij"," jklmn"," a","b"," c","d"," e","f"],["a","b","c","d"," e","f","g","h"]]' 1514 1515 - TestCase: 1516 Name: case210 1517 Op: '[.[] / ", "]' 1518 In: '["a, bc, def, ghij, jklmn, a,b, c,d, e,f", "a,b,c,d, e,f,g,h"]' 1519 Out: '[["a","bc","def","ghij","jklmn","a,b","c,d","e,f"],["a,b,c,d","e,f,g,h"]]' 1520 1521 - TestCase: 1522 Name: case211 1523 Op: 'map(.[1] as $needle | .[0] | contains($needle))' 1524 In: '[[[],[]], [[1,2,3], [1,2]], [[1,2,3], [3,1]], [[1,2,3], [4]], [[1,2,3], [1,4]]]' 1525 Out: '[true, true, true, false, false]' 1526 1527 - TestCase: 1528 Name: case212 1529 Op: 'map(.[1] as $needle | .[0] | contains($needle))' 1530 In: '[[["foobar", "foobaz"], ["baz", "bar"]], [["foobar", "foobaz"], ["foo"]], [["foobar", "foobaz"], ["blap"]]]' 1531 Out: '[true, true, false]' 1532 1533 - TestCase: 1534 Name: case213 1535 Op: '[({foo: 12, bar:13} | contains({foo: 12})), ({foo: 12} | contains({})), ({foo: 12, bar:13} | contains({baz:14}))]' 1536 In: '{}' 1537 Out: '[true, true, false]' 1538 1539 - TestCase: 1540 Name: case214 1541 Op: '{foo: {baz: 12, blap: {bar: 13}}, bar: 14} | contains({bar: 14, foo: {blap: {}}})' 1542 In: '{}' 1543 Out: 'true' 1544 1545 - TestCase: 1546 Name: case215 1547 Op: '{foo: {baz: 12, blap: {bar: 13}}, bar: 14} | contains({bar: 14, foo: {blap: {bar: 14}}})' 1548 In: '{}' 1549 Out: 'false' 1550 1551 - TestCase: 1552 Name: case216 1553 Op: 'sort' 1554 In: '[42,[2,5,3,11],10,{"a":42,"b":2},{"a":42},true,2,[2,6],"hello",null,[2,5,6],{"a":[],"b":1},"abc","ab",[3,10],{},false,"abcd",null]' 1555 Out: '[null,null,false,true,2,10,42,"ab","abc","abcd","hello",[2,5,3,11],[2,5,6],[2,6],[3,10],{},{"a":42},{"a":42,"b":2},{"a":[],"b":1}]' 1556 1557 - TestCase: 1558 Name: case217 1559 Op: '(sort_by(.b) | sort_by(.a)), sort_by(.a, .b), sort_by(.b, .c), group_by(.b), group_by(.a + .b - .c == 2)' 1560 In: '[{"a": 1, "b": 4, "c": 14}, {"a": 4, "b": 1, "c": 3}, {"a": 1, "b": 4, "c": 3}, {"a": 0, "b": 2, "c": 43}]' 1561 Out: '[{"a": 0, "b": 2, "c": 43}, {"a": 1, "b": 4, "c": 14}, {"a": 1, "b": 4, "c": 3}, {"a": 4, "b": 1, "c": 3}]' 1562 1563 - TestCase: 1564 Name: case218 1565 Op: 'unique' 1566 In: '[1,2,5,3,5,3,1,3]' 1567 Out: '[1,2,3,5]' 1568 1569 - TestCase: 1570 Name: case219 1571 Op: 'unique' 1572 In: '[]' 1573 Out: '[]' 1574 1575 - TestCase: 1576 Name: case220 1577 Op: '[min, max, min_by(.[1]), max_by(.[1]), min_by(.[2]), max_by(.[2])]' 1578 In: '[[4,2,"a"],[3,1,"a"],[2,4,"a"],[1,3,"a"]]' 1579 Out: '[[1,3,"a"],[4,2,"a"],[3,1,"a"],[2,4,"a"],[4,2,"a"],[1,3,"a"]]' 1580 1581 - TestCase: 1582 Name: case221 1583 Op: '[min,max,min_by(.),max_by(.)]' 1584 In: '[]' 1585 Out: '[null,null,null,null]' 1586 1587 - TestCase: 1588 Name: case222 1589 Op: '.foo[.baz]' 1590 In: '{"foo":{"bar":4},"baz":"bar"}' 1591 Out: '4' 1592 1593 - TestCase: 1594 Name: case223 1595 Op: .[] | .error = "no, it's OK" 1596 In: '[{"error":true}]' 1597 Out: {"error": "no, it's OK"} 1598 1599 - TestCase: 1600 Name: case224 1601 Op: '[{a:1}] | .[] | .a=999' 1602 In: 'null' 1603 Out: '{"a": 999}' 1604 1605 - TestCase: 1606 Name: case225 1607 Op: 'to_entries' 1608 In: '{"a": 1, "b": 2}' 1609 Out: '[{"key":"a", "value":1}, {"key":"b", "value":2}]' 1610 1611 - TestCase: 1612 Name: case226 1613 Op: 'from_entries' 1614 In: '[{"key":"a", "value":1}, {"Key":"b", "Value":2}, {"name":"c", "value":3}, {"Name":"d", "Value":4}]' 1615 Out: '{"a": 1, "b": 2, "c": 3, "d": 4}' 1616 1617 - TestCase: 1618 Name: case227 1619 Op: 'with_entries(.key |= "KEY_" + .)' 1620 In: '{"a": 1, "b": 2}' 1621 Out: '{"KEY_a": 1, "KEY_b": 2}' 1622 1623 - TestCase: 1624 Name: case228 1625 Op: 'map(has("foo"))' 1626 In: '[{"foo": 42}, {}]' 1627 Out: '[true, false]' 1628 1629 - TestCase: 1630 Name: case229 1631 Op: 'map(has(2))' 1632 In: '[[0,1], ["a","b","c"]]' 1633 Out: '[false, true]' 1634 1635 - TestCase: 1636 Name: case230 1637 Op: 'keys' 1638 In: '[42,3,35]' 1639 Out: '[0,1,2]' 1640 1641 - TestCase: 1642 Name: case231 1643 Op: '[][.]' 1644 In: '1000000000000000000' 1645 Out: 'null' 1646 1647 - TestCase: 1648 Name: case232 1649 Op: 'map([1,2][0:.])' 1650 In: '[-1, 1, 2, 3, 1000000000000000000]' 1651 Out: '[[1], [1], [1,2], [1,2], [1,2]]' 1652 1653 - Comment: 1654 Str: 'Test recursive object merge' 1655 1656 - TestCase: 1657 Name: case233 1658 Op: '{"k": {"a": 1, "b": 2}} * .' 1659 In: '{"k": {"a": 0,"c": 3}}' 1660 Out: '{"k": {"a": 0, "b": 2, "c": 3}}' 1661 1662 - TestCase: 1663 Name: case234 1664 Op: '{"k": {"a": 1, "b": 2}, "hello": {"x": 1}} * .' 1665 In: '{"k": {"a": 0,"c": 3}, "hello": 1}' 1666 Out: '{"k": {"a": 0, "b": 2, "c": 3}, "hello": 1}' 1667 1668 - TestCase: 1669 Name: case235 1670 Op: '{"k": {"a": 1, "b": 2}, "hello": 1} * .' 1671 In: '{"k": {"a": 0,"c": 3}, "hello": {"x": 1}}' 1672 Out: '{"k": {"a": 0, "b": 2, "c": 3}, "hello": {"x": 1}}' 1673 1674 - TestCase: 1675 Name: case236 1676 Op: '{"a": {"b": 1}, "c": {"d": 2}, "e": 5} * .' 1677 In: '{"a": {"b": 2}, "c": {"d": 3, "f": 9}}' 1678 Out: '{"a": {"b": 2}, "c": {"d": 3, "f": 9}, "e": 5}' 1679 1680 - TestCase: 1681 Name: case237 1682 Op: '[.[]|arrays]' 1683 In: '[1,2,"foo",[],[3,[]],{},true,false,null]' 1684 Out: '[[],[3,[]]]' 1685 1686 - TestCase: 1687 Name: case238 1688 Op: '[.[]|objects]' 1689 In: '[1,2,"foo",[],[3,[]],{},true,false,null]' 1690 Out: '[{}]' 1691 1692 - TestCase: 1693 Name: case239 1694 Op: '[.[]|iterables]' 1695 In: '[1,2,"foo",[],[3,[]],{},true,false,null]' 1696 Out: '[[],[3,[]],{}]' 1697 1698 - TestCase: 1699 Name: case240 1700 Op: '[.[]|scalars]' 1701 In: '[1,2,"foo",[],[3,[]],{},true,false,null]' 1702 Out: '[1,2,"foo",true,false,null]' 1703 1704 - TestCase: 1705 Name: case241 1706 Op: '[.[]|values]' 1707 In: '[1,2,"foo",[],[3,[]],{},true,false,null]' 1708 Out: '[1,2,"foo",[],[3,[]],{},true,false]' 1709 1710 - TestCase: 1711 Name: case242 1712 Op: '[.[]|booleans]' 1713 In: '[1,2,"foo",[],[3,[]],{},true,false,null]' 1714 Out: '[true,false]' 1715 1716 - TestCase: 1717 Name: case243 1718 Op: '[.[]|nulls]' 1719 In: '[1,2,"foo",[],[3,[]],{},true,false,null]' 1720 Out: '[null]' 1721 1722 - TestCase: 1723 Name: case244 1724 Op: 'flatten' 1725 In: '[0, [1], [[2]], [[[3]]]]' 1726 Out: '[0, 1, 2, 3]' 1727 1728 - TestCase: 1729 Name: case245 1730 Op: 'flatten(0)' 1731 In: '[0, [1], [[2]], [[[3]]]]' 1732 Out: '[0, [1], [[2]], [[[3]]]]' 1733 1734 - TestCase: 1735 Name: case246 1736 Op: 'flatten(2)' 1737 In: '[0, [1], [[2]], [[[3]]]]' 1738 Out: '[0, 1, 2, [3]]' 1739 1740 - TestCase: 1741 Name: case247 1742 Op: 'flatten(2)' 1743 In: '[0, [1, [2]], [1, [[3], 2]]]' 1744 Out: '[0, 1, 2, 1, [3], 2]' 1745 1746 - TestCase: 1747 Name: case248 1748 Op: 'try flatten(-1) catch .' 1749 In: '[0, [1], [[2]], [[[3]]]]' 1750 Out: '"flatten depth must not be negative"' 1751 1752 - TestCase: 1753 Name: case249 1754 Op: 'transpose' 1755 In: '[[1], [2,3]]' 1756 Out: '[[1,2],[null,3]]' 1757 1758 - TestCase: 1759 Name: case250 1760 Op: 'ascii_upcase' 1761 In: '"useful but not for é"' 1762 Out: '"USEFUL BUT NOT FOR é"' 1763 1764 - TestCase: 1765 Name: case251 1766 Op: 'bsearch(4)' 1767 In: '[1,2,3]' 1768 Out: '-4' 1769 1770 - Comment: 1771 Str: 'strptime tests are in optional.test' 1772 1773 - TestCase: 1774 Name: case252 1775 Op: 'strftime("%Y-%m-%dT%H:%M:%SZ")' 1776 In: '[2015,2,5,23,51,47,4,63]' 1777 Out: '"2015-03-05T23:51:47Z"' 1778 1779 - TestCase: 1780 Name: case253 1781 Op: 'strftime("%A, %B %d, %Y")' 1782 In: '1435677542.822351' 1783 Out: '"Tuesday, June 30, 2015"' 1784 1785 - TestCase: 1786 Name: case254 1787 Op: 'gmtime' 1788 In: '1425599507' 1789 Out: '[2015,2,5,23,51,47,4,63]' 1790 1791 - Comment: 1792 Str: 'module system' 1793 1794 - TestCase: 1795 Name: case255 1796 Op: 'import "a" as foo; import "b" as bar; def fooa: foo::a; [fooa, bar::a, bar::b, foo::a]' 1797 In: 'null' 1798 Out: '["a","b","c","a"]' 1799 1800 - TestCase: 1801 Name: case256 1802 Op: 'import "c" as foo; [foo::a, foo::c]' 1803 In: 'null' 1804 Out: '[0,"acmehbah"]' 1805 1806 - TestCase: 1807 Name: case257 1808 Op: 'include "c"; [a, c]' 1809 In: 'null' 1810 Out: '[0,"acmehbah"]' 1811 1812 - TestCase: 1813 Name: case258 1814 Op: 'modulemeta' 1815 In: '"c"' 1816 Out: '{"whatever":null,"deps":[{"as":"foo","is_data":false,"relpath":"a"},{"search":"./","as":"d","is_data":false,"relpath":"d"},{"search":"./","as":"d2","is_data":false,"relpath":"d"},{"search":"./../lib/jq","as":"e","is_data":false,"relpath":"e"},{"search":"./../lib/jq","as":"f","is_data":false,"relpath":"f"},{"as":"d","is_data":true,"relpath":"data"}]}' 1817 1818 - TestCase: 1819 Name: case259 1820 Op: 'import "test_bind_order" as check; check::check' 1821 In: 'null' 1822 Out: 'true' 1823 1824 - TestCase: 1825 Name: case260 1826 Op: 'try -. catch .' 1827 In: '"very-long-string"' 1828 Out: '"string (\"very-long-...) cannot be negated"' 1829 1830 - TestCase: 1831 Name: case261 1832 Op: 'join(",")' 1833 In: '["1",2,true,false,3.4]' 1834 Out: '"1,2,true,false,3.4"' 1835 1836 - TestCase: 1837 Name: case262 1838 Op: '.[] | join(",")' 1839 In: '[[], [null], [null,null], [null,null,null]]' 1840 Out: '""' 1841 1842 - TestCase: 1843 Name: case263 1844 Op: '.[] | join(",")' 1845 In: '[["a",null], [null,"a"]]' 1846 Out: '"a,"' 1847 1848 - TestCase: 1849 Name: case264 1850 Op: 'try join(",") catch .' 1851 In: '["1","2",{"a":{"b":{"c":33}}}]' 1852 Out: '"string (\"1,2,\") and object ({\"a\":{\"b\":{...) cannot be added"' 1853 1854 - TestCase: 1855 Name: case265 1856 Op: 'try join(",") catch .' 1857 In: '["1","2",[3,4,5]]' 1858 Out: '"string (\"1,2,\") and array ([3,4,5]) cannot be added"' 1859 1860 - TestCase: 1861 Name: case266 1862 Op: '{if:0,and:1,or:2,then:3,else:4,elif:5,end:6,as:7,def:8,reduce:9,foreach:10,try:11,catch:12,label:13,import:14,include:15,module:16}' 1863 In: 'null' 1864 Out: '{"if":0,"and":1,"or":2,"then":3,"else":4,"elif":5,"end":6,"as":7,"def":8,"reduce":9,"foreach":10,"try":11,"catch":12,"label":13,"import":14,"include":15,"module":16}' 1865 1866 - TestCase: 1867 Name: case267 1868 Op: 'try (1/.) catch .' 1869 In: '0' 1870 Out: '"number (1) and number (0) cannot be divided because the divisor is zero"' 1871 1872 - TestCase: 1873 Name: case268 1874 Op: 'try (1%.) catch .' 1875 In: '0' 1876 Out: '"number (1) and number (0) cannot be divided (remainder) because the divisor is zero"' 1877 1878 - Comment: 1879 Str: 'Basic numbers tests: integers, powers of two' 1880 1881 - TestCase: 1882 Name: case269 1883 Op: '[range(-52;52;1)] as $powers | [$powers[]|pow(2;.)|log2] == $powers' 1884 In: 'null' 1885 Out: 'true' 1886 1887 - TestCase: 1888 Name: case270 1889 Op: '[range(-99/2;99/2;1)] as $orig | [$orig[]|pow(2;.)|log2] as $back | ($orig|keys)[]|. as $k | (($orig|.[$k])-($back|.[$k]))|if . < 0 then . * -1 else . end|select(.>.00005)' 1890 In: 'null' 1891 Out: '' 1892 1893 - TestCase: 1894 Name: case271 1895 Op: '(.[{}] = 0)?' 1896 In: 'null' 1897 Out: '' 1898