github.com/lmorg/murex@v0.0.0-20240217211045-e081c89cd4ef/builtins/core/structs/switch_test.go (about) 1 package structs_test 2 3 import ( 4 "testing" 5 6 _ "github.com/lmorg/murex/builtins" 7 "github.com/lmorg/murex/test" 8 ) 9 10 func TestSwitchCaseBlock1(t *testing.T) { 11 tests := []test.MurexTest{ 12 { 13 Block: ` 14 switch { 15 case { true } then { out: 1 } 16 case { false } then { out: 2 } 17 case { false } then { out: 3 } 18 }`, 19 Stdout: "1\n", 20 }, 21 { 22 Block: ` 23 switch { 24 case { true } then { out: 1 } 25 case { true } then { out: 2 } 26 case { false } then { out: 3 } 27 }`, 28 Stdout: "1\n", 29 }, 30 { 31 Block: ` 32 switch { 33 case { true } then { out: 1 } 34 case { true } then { out: 2 } 35 case { true } then { out: 3 } 36 }`, 37 Stdout: "1\n", 38 }, 39 { 40 Block: ` 41 switch { 42 case { true } then { out: 1 } 43 case { false } then { out: 2 } 44 case { false } then { out: 3 } 45 catch { out: 4 } 46 }`, 47 Stdout: "1\n", 48 }, 49 { 50 Block: ` 51 switch { 52 case { true } then { out: 1 } 53 case { true } then { out: 2 } 54 case { false } then { out: 3 } 55 catch { out: 4 } 56 }`, 57 Stdout: "1\n", 58 }, 59 { 60 Block: ` 61 switch { 62 case { true } then { out: 1 } 63 case { true } then { out: 2 } 64 case { true } then { out: 3 } 65 catch { out: 4 } 66 }`, 67 Stdout: "1\n", 68 }, 69 ///// 70 { 71 Block: ` 72 switch { 73 case { true } { out: 1 } 74 case { false } { out: 2 } 75 case { false } { out: 3 } 76 }`, 77 Stdout: "1\n", 78 }, 79 { 80 Block: ` 81 switch { 82 case { true } { out: 1 } 83 case { true } { out: 2 } 84 case { false } { out: 3 } 85 }`, 86 Stdout: "1\n", 87 }, 88 { 89 Block: ` 90 switch { 91 case { true } { out: 1 } 92 case { true } { out: 2 } 93 case { true } { out: 3 } 94 }`, 95 Stdout: "1\n", 96 }, 97 { 98 Block: ` 99 switch { 100 case { true } { out: 1 } 101 case { false } { out: 2 } 102 case { false } { out: 3 } 103 catch { out: 4 } 104 }`, 105 Stdout: "1\n", 106 }, 107 { 108 Block: ` 109 switch { 110 case { true } { out: 1 } 111 case { true } { out: 2 } 112 case { false } { out: 3 } 113 catch { out: 4 } 114 }`, 115 Stdout: "1\n", 116 }, 117 { 118 Block: ` 119 switch { 120 case { true } { out: 1 } 121 case { true } { out: 2 } 122 case { true } { out: 3 } 123 catch { out: 4 } 124 }`, 125 Stdout: "1\n", 126 }, 127 } 128 129 test.RunMurexTests(tests, t) 130 } 131 132 func TestSwitchCaseBlock2(t *testing.T) { 133 tests := []test.MurexTest{ 134 { 135 Block: ` 136 switch { 137 case { false } then { out: 1 } 138 case { true } then { out: 2 } 139 case { false } then { out: 3 } 140 }`, 141 Stdout: "2\n", 142 }, 143 { 144 Block: ` 145 switch { 146 case { false } then { out: 1 } 147 case { true } then { out: 2 } 148 case { true } then { out: 3 } 149 }`, 150 Stdout: "2\n", 151 }, 152 { 153 Block: ` 154 switch { 155 case { false } then { out: 1 } 156 case { true } then { out: 2 } 157 case { false } then { out: 3 } 158 catch { out: 4 } 159 }`, 160 Stdout: "2\n", 161 }, 162 { 163 Block: ` 164 switch { 165 case { false } then { out: 1 } 166 case { true } then { out: 2 } 167 case { true } then { out: 3 } 168 catch { out: 4 } 169 }`, 170 Stdout: "2\n", 171 }, 172 ///// 173 { 174 Block: ` 175 switch { 176 case { false } { out: 1 } 177 case { true } { out: 2 } 178 case { false } { out: 3 } 179 }`, 180 Stdout: "2\n", 181 }, 182 { 183 Block: ` 184 switch { 185 case { false } { out: 1 } 186 case { true } { out: 2 } 187 case { true } { out: 3 } 188 }`, 189 Stdout: "2\n", 190 }, 191 { 192 Block: ` 193 switch { 194 case { false } { out: 1 } 195 case { true } { out: 2 } 196 case { false } { out: 3 } 197 catch { out: 4 } 198 }`, 199 Stdout: "2\n", 200 }, 201 { 202 Block: ` 203 switch { 204 case { false } { out: 1 } 205 case { true } { out: 2 } 206 case { true } { out: 3 } 207 catch { out: 4 } 208 }`, 209 Stdout: "2\n", 210 }, 211 } 212 213 test.RunMurexTests(tests, t) 214 } 215 216 func TestSwitchCaseBlock3(t *testing.T) { 217 tests := []test.MurexTest{ 218 { 219 Block: ` 220 switch { 221 case { false } then { out: 1 } 222 case { false } then { out: 2 } 223 case { true } then { out: 3 } 224 }`, 225 Stdout: "3\n", 226 }, 227 { 228 Block: ` 229 switch { 230 case { false } then { out: 1 } 231 case { false } then { out: 2 } 232 case { true } then { out: 3 } 233 catch { out: 4 } 234 }`, 235 Stdout: "3\n", 236 }, 237 ///// 238 { 239 Block: ` 240 switch { 241 case { false } { out: 1 } 242 case { false } { out: 2 } 243 case { true } { out: 3 } 244 }`, 245 Stdout: "3\n", 246 }, 247 { 248 Block: ` 249 switch { 250 case { false } { out: 1 } 251 case { false } { out: 2 } 252 case { true } { out: 3 } 253 catch { out: 4 } 254 }`, 255 Stdout: "3\n", 256 }, 257 } 258 259 test.RunMurexTests(tests, t) 260 } 261 262 func TestSwitchCaseBlock4(t *testing.T) { 263 tests := []test.MurexTest{ 264 { 265 Block: ` 266 switch { 267 case { false } then { out: 1 } 268 case { false } then { out: 2 } 269 case { false } then { out: 3 } 270 }`, 271 Stdout: "", 272 ExitNum: 1, 273 }, 274 { 275 Block: ` 276 switch { 277 case { false } then { out: 1 } 278 case { false } then { out: 2 } 279 case { false } then { out: 3 } 280 catch { out: 4 } 281 }`, 282 Stdout: "4\n", 283 }, 284 ///// 285 { 286 Block: ` 287 switch { 288 case { false } { out: 1 } 289 case { false } { out: 2 } 290 case { false } { out: 3 } 291 }`, 292 Stdout: "", 293 ExitNum: 1, 294 }, 295 { 296 Block: ` 297 switch { 298 case { false } { out: 1 } 299 case { false } { out: 2 } 300 case { false } { out: 3 } 301 catch { out: 4 } 302 }`, 303 Stdout: "4\n", 304 }, 305 } 306 307 test.RunMurexTests(tests, t) 308 } 309 310 ///// 311 312 func TestSwitchIfBlock1(t *testing.T) { 313 tests := []test.MurexTest{ 314 { 315 Block: ` 316 switch { 317 if { true } then { out: 1 } 318 if { false } then { out: 2 } 319 if { false } then { out: 3 } 320 }`, 321 Stdout: "1\n", 322 ExitNum: 0, 323 }, 324 { 325 Block: ` 326 switch { 327 if { true } then { out: 1 } 328 if { true } then { out: 2 } 329 if { false } then { out: 3 } 330 }`, 331 Stdout: "1\n2\n", 332 ExitNum: 0, 333 }, 334 { 335 Block: ` 336 switch { 337 if { true } then { out: 1 } 338 if { true } then { out: 2 } 339 if { true } then { out: 3 } 340 }`, 341 Stdout: "1\n2\n3\n", 342 ExitNum: 0, 343 }, 344 { 345 Block: ` 346 switch { 347 if { true } then { out: 1 } 348 if { false } then { out: 2 } 349 if { false } then { out: 3 } 350 catch { out: 4 } 351 }`, 352 Stdout: "1\n", 353 }, 354 { 355 Block: ` 356 switch { 357 if { true } then { out: 1 } 358 if { true } then { out: 2 } 359 if { false } then { out: 3 } 360 catch { out: 4 } 361 }`, 362 Stdout: "1\n2\n", 363 }, 364 { 365 Block: ` 366 switch { 367 if { true } then { out: 1 } 368 if { true } then { out: 2 } 369 if { true } then { out: 3 } 370 catch { out: 4 } 371 }`, 372 Stdout: "1\n2\n3\n", 373 }, 374 ///// 375 { 376 Block: ` 377 switch { 378 if { true } { out: 1 } 379 if { false } { out: 2 } 380 if { false } { out: 3 } 381 }`, 382 Stdout: "1\n", 383 ExitNum: 0, 384 }, 385 { 386 Block: ` 387 switch { 388 if { true } { out: 1 } 389 if { true } { out: 2 } 390 if { false } { out: 3 } 391 }`, 392 Stdout: "1\n2\n", 393 ExitNum: 0, 394 }, 395 { 396 Block: ` 397 switch { 398 if { true } { out: 1 } 399 if { true } { out: 2 } 400 if { true } { out: 3 } 401 }`, 402 Stdout: "1\n2\n3\n", 403 ExitNum: 0, 404 }, 405 { 406 Block: ` 407 switch { 408 if { true } { out: 1 } 409 if { false } { out: 2 } 410 if { false } { out: 3 } 411 catch { out: 4 } 412 }`, 413 Stdout: "1\n", 414 }, 415 { 416 Block: ` 417 switch { 418 if { true } { out: 1 } 419 if { true } { out: 2 } 420 if { false } { out: 3 } 421 catch { out: 4 } 422 }`, 423 Stdout: "1\n2\n", 424 }, 425 { 426 Block: ` 427 switch { 428 if { true } { out: 1 } 429 if { true } { out: 2 } 430 if { true } { out: 3 } 431 catch { out: 4 } 432 }`, 433 Stdout: "1\n2\n3\n", 434 }, 435 } 436 437 test.RunMurexTests(tests, t) 438 } 439 440 func TestSwitchIfBlock2(t *testing.T) { 441 tests := []test.MurexTest{ 442 { 443 Block: ` 444 switch { 445 if { false } then { out: 1 } 446 if { true } then { out: 2 } 447 if { false } then { out: 3 } 448 }`, 449 Stdout: "2\n", 450 ExitNum: 0, 451 }, 452 { 453 Block: ` 454 switch { 455 if { false } then { out: 1 } 456 if { true } then { out: 2 } 457 if { true } then { out: 3 } 458 }`, 459 Stdout: "2\n3\n", 460 ExitNum: 0, 461 }, 462 { 463 Block: ` 464 switch { 465 if { false } then { out: 1 } 466 if { true } then { out: 2 } 467 if { false } then { out: 3 } 468 catch { out: 4 } 469 }`, 470 Stdout: "2\n", 471 }, 472 { 473 Block: ` 474 switch { 475 if { false } then { out: 1 } 476 if { true } then { out: 2 } 477 if { true } then { out: 3 } 478 catch { out: 4 } 479 }`, 480 Stdout: "2\n3\n", 481 }, 482 ///// 483 { 484 Block: ` 485 switch { 486 if { false } { out: 1 } 487 if { true } { out: 2 } 488 if { false } { out: 3 } 489 }`, 490 Stdout: "2\n", 491 ExitNum: 0, 492 }, 493 { 494 Block: ` 495 switch { 496 if { false } { out: 1 } 497 if { true } { out: 2 } 498 if { true } { out: 3 } 499 }`, 500 Stdout: "2\n3\n", 501 ExitNum: 0, 502 }, 503 { 504 Block: ` 505 switch { 506 if { false } { out: 1 } 507 if { true } { out: 2 } 508 if { false } { out: 3 } 509 catch { out: 4 } 510 }`, 511 Stdout: "2\n", 512 }, 513 { 514 Block: ` 515 switch { 516 if { false } { out: 1 } 517 if { true } { out: 2 } 518 if { true } { out: 3 } 519 catch { out: 4 } 520 }`, 521 Stdout: "2\n3\n", 522 }, 523 } 524 525 test.RunMurexTests(tests, t) 526 } 527 528 func TestSwitchIfBlock3(t *testing.T) { 529 tests := []test.MurexTest{ 530 { 531 Block: ` 532 switch { 533 if { false } then { out: 1 } 534 if { false } then { out: 2 } 535 if { true } then { out: 3 } 536 }`, 537 Stdout: "3\n", 538 ExitNum: 0, 539 }, 540 { 541 Block: ` 542 switch { 543 if { false } then { out: 1 } 544 if { false } then { out: 2 } 545 if { true } then { out: 3 } 546 catch { out: 4 } 547 }`, 548 Stdout: "3\n", 549 }, 550 ///// 551 { 552 Block: ` 553 switch { 554 if { false } { out: 1 } 555 if { false } { out: 2 } 556 if { true } { out: 3 } 557 }`, 558 Stdout: "3\n", 559 ExitNum: 0, 560 }, 561 { 562 Block: ` 563 switch { 564 if { false } { out: 1 } 565 if { false } { out: 2 } 566 if { true } { out: 3 } 567 catch { out: 4 } 568 }`, 569 Stdout: "3\n", 570 }, 571 } 572 573 test.RunMurexTests(tests, t) 574 } 575 576 func TestSwitchIfBlock4(t *testing.T) { 577 tests := []test.MurexTest{ 578 { 579 Block: ` 580 switch { 581 if { false } then { out: 1 } 582 if { false } then { out: 2 } 583 if { false } then { out: 3 } 584 }`, 585 Stdout: "", 586 ExitNum: 1, 587 }, 588 { 589 Block: ` 590 switch { 591 if { false } then { out: 1 } 592 if { false } then { out: 2 } 593 if { false } then { out: 3 } 594 catch { out: 4 } 595 }`, 596 Stdout: "4\n", 597 }, 598 ///// 599 { 600 Block: ` 601 switch { 602 if { false } { out: 1 } 603 if { false } { out: 2 } 604 if { false } { out: 3 } 605 }`, 606 Stdout: "", 607 ExitNum: 1, 608 }, 609 { 610 Block: ` 611 switch { 612 if { false } { out: 1 } 613 if { false } { out: 2 } 614 if { false } { out: 3 } 615 catch { out: 4 } 616 }`, 617 Stdout: "4\n", 618 }, 619 } 620 621 test.RunMurexTests(tests, t) 622 } 623 624 func TestSwitchCaseIfBlock(t *testing.T) { 625 tests := []test.MurexTest{ 626 { 627 Block: ` 628 switch { 629 if { false } then { out: 1 } 630 if { false } then { out: 2 } 631 case { false } then { out: 3 } 632 }`, 633 Stdout: "", 634 ExitNum: 1, 635 }, 636 { 637 Block: ` 638 switch { 639 if { false } then { out: 1 } 640 if { false } then { out: 2 } 641 case { false } then { out: 3 } 642 catch { out: 4 } 643 }`, 644 Stdout: "4\n", 645 }, 646 { 647 Block: ` 648 switch { 649 if { false } then { out: 1 } 650 if { true } then { out: 2 } 651 case { false } then { out: 3 } 652 catch { out: 4 } 653 }`, 654 Stdout: "2\n", 655 }, 656 { 657 Block: ` 658 switch { 659 if { false } then { out: 1 } 660 if { true } then { out: 2 } 661 case { true } then { out: 3 } 662 catch { out: 4 } 663 }`, 664 Stdout: "2\n3\n", 665 }, 666 { 667 Block: ` 668 switch { 669 if { false } then { out: 1 } 670 case { true } then { out: 2 } 671 if { true } then { out: 3 } 672 catch { out: 4 } 673 }`, 674 Stdout: "2\n", 675 }, 676 { 677 Block: ` 678 switch { 679 if { false } then { out: 1 } 680 case { false } then { out: 2 } 681 if { true } then { out: 3 } 682 catch { out: 4 } 683 }`, 684 Stdout: "3\n", 685 }, 686 ///// 687 { 688 Block: ` 689 switch { 690 if { false } { out: 1 } 691 if { false } { out: 2 } 692 case { false } { out: 3 } 693 }`, 694 Stdout: "", 695 ExitNum: 1, 696 }, 697 { 698 Block: ` 699 switch { 700 if { false } { out: 1 } 701 if { false } { out: 2 } 702 case { false } { out: 3 } 703 catch { out: 4 } 704 }`, 705 Stdout: "4\n", 706 }, 707 { 708 Block: ` 709 switch { 710 if { false } { out: 1 } 711 if { true } { out: 2 } 712 case { false } then { out: 3 } 713 catch { out: 4 } 714 }`, 715 Stdout: "2\n", 716 }, 717 { 718 Block: ` 719 switch { 720 if { false } { out: 1 } 721 if { true } { out: 2 } 722 case { true } { out: 3 } 723 catch { out: 4 } 724 }`, 725 Stdout: "2\n3\n", 726 }, 727 { 728 Block: ` 729 switch { 730 if { false } { out: 1 } 731 case { true } { out: 2 } 732 if { true } { out: 3 } 733 catch { out: 4 } 734 }`, 735 Stdout: "2\n", 736 }, 737 { 738 Block: ` 739 switch { 740 if { false } { out: 1 } 741 case { false } { out: 2 } 742 if { true } { out: 3 } 743 catch { out: 4 } 744 }`, 745 Stdout: "3\n", 746 }, 747 } 748 749 test.RunMurexTests(tests, t) 750 } 751 752 func TestSwitchByValCaseIfBlock1(t *testing.T) { 753 tests := []test.MurexTest{ 754 { 755 Block: ` 756 switch foobar { 757 if foo then { out: 1 } 758 if bar then { out: 2 } 759 if oof then { out: 3 } 760 }`, 761 Stdout: "", 762 ExitNum: 1, 763 }, 764 { 765 Block: ` 766 switch foobar { 767 if foo then { out: 1 } 768 if bar then { out: 2 } 769 case oof then { out: 3 } 770 }`, 771 Stdout: "", 772 ExitNum: 1, 773 }, 774 { 775 Block: ` 776 switch foobar { 777 if foo then { out: 1 } 778 case bar then { out: 2 } 779 if oof then { out: 3 } 780 }`, 781 Stdout: "", 782 ExitNum: 1, 783 }, 784 { 785 Block: ` 786 switch foobar { 787 case foo then { out: 1 } 788 if bar then { out: 2 } 789 if oof then { out: 3 } 790 }`, 791 Stdout: "", 792 ExitNum: 1, 793 }, 794 ///// 795 { 796 Block: ` 797 switch foobar { 798 if foo { out: 1 } 799 if bar { out: 2 } 800 if oof { out: 3 } 801 }`, 802 Stdout: "", 803 ExitNum: 1, 804 }, 805 { 806 Block: ` 807 switch foobar { 808 if foo { out: 1 } 809 if bar { out: 2 } 810 case oof { out: 3 } 811 }`, 812 Stdout: "", 813 ExitNum: 1, 814 }, 815 { 816 Block: ` 817 switch foobar { 818 if foo { out: 1 } 819 case bar { out: 2 } 820 if oof { out: 3 } 821 }`, 822 Stdout: "", 823 ExitNum: 1, 824 }, 825 { 826 Block: ` 827 switch foobar { 828 case foo { out: 1 } 829 if bar { out: 2 } 830 if oof { out: 3 } 831 }`, 832 Stdout: "", 833 ExitNum: 1, 834 }, 835 } 836 837 test.RunMurexTests(tests, t) 838 } 839 840 func TestSwitchByValCaseIfBlock2(t *testing.T) { 841 tests := []test.MurexTest{ 842 { 843 Block: ` 844 switch foobar { 845 if foo then { out: 1 } 846 if bar then { out: 2 } 847 if oof then { out: 3 } 848 catch { out: 4 } 849 }`, 850 Stdout: "4\n", 851 ExitNum: 0, 852 }, 853 { 854 Block: ` 855 switch foobar { 856 if foo then { out: 1 } 857 if bar then { out: 2 } 858 case oof then { out: 3 } 859 catch { out: 4 } 860 }`, 861 Stdout: "4\n", 862 ExitNum: 0, 863 }, 864 { 865 Block: ` 866 switch foobar { 867 if foo then { out: 1 } 868 case bar then { out: 2 } 869 if oof then { out: 3 } 870 catch { out: 4 } 871 }`, 872 Stdout: "4\n", 873 ExitNum: 0, 874 }, 875 { 876 Block: ` 877 switch foobar { 878 case foo then { out: 1 } 879 if bar then { out: 2 } 880 if oof then { out: 3 } 881 catch { out: 4 } 882 }`, 883 Stdout: "4\n", 884 ExitNum: 0, 885 }, 886 ///// 887 { 888 Block: ` 889 switch foobar { 890 if foo { out: 1 } 891 if bar { out: 2 } 892 if oof { out: 3 } 893 catch { out: 4 } 894 }`, 895 Stdout: "4\n", 896 ExitNum: 0, 897 }, 898 { 899 Block: ` 900 switch foobar { 901 if foo { out: 1 } 902 if bar { out: 2 } 903 case oof { out: 3 } 904 catch { out: 4 } 905 }`, 906 Stdout: "4\n", 907 ExitNum: 0, 908 }, 909 { 910 Block: ` 911 switch foobar { 912 if foo { out: 1 } 913 case bar { out: 2 } 914 if oof { out: 3 } 915 catch { out: 4 } 916 }`, 917 Stdout: "4\n", 918 ExitNum: 0, 919 }, 920 { 921 Block: ` 922 switch foobar { 923 case foo { out: 1 } 924 if bar { out: 2 } 925 if oof { out: 3 } 926 catch { out: 4 } 927 }`, 928 Stdout: "4\n", 929 ExitNum: 0, 930 }, 931 } 932 933 test.RunMurexTests(tests, t) 934 } 935 936 func TestSwitchByValCaseIfBlock3(t *testing.T) { 937 tests := []test.MurexTest{ 938 { 939 Block: ` 940 switch foobar { 941 if foo then { out: 1 } 942 if foobar then { out: 2 } 943 if oof then { out: 3 } 944 catch { out: 4 } 945 }`, 946 Stdout: "2\n", 947 ExitNum: 0, 948 }, 949 { 950 Block: ` 951 switch foobar { 952 if foo then { out: 1 } 953 if foobar then { out: 2 } 954 case oof then { out: 3 } 955 catch { out: 4 } 956 }`, 957 Stdout: "2\n", 958 ExitNum: 0, 959 }, 960 { 961 Block: ` 962 switch foobar { 963 if foo then { out: 1 } 964 case foobar then { out: 2 } 965 if foobar then { out: 3 } 966 catch { out: 4 } 967 }`, 968 Stdout: "2\n", 969 ExitNum: 0, 970 }, 971 { 972 Block: ` 973 switch foobar { 974 case foo then { out: 1 } 975 if foobar then { out: 2 } 976 if oof then { out: 3 } 977 catch { out: 4 } 978 }`, 979 Stdout: "2\n", 980 ExitNum: 0, 981 }, 982 ///// 983 { 984 Block: ` 985 switch foobar { 986 if foo { out: 1 } 987 if foobar { out: 2 } 988 if oof { out: 3 } 989 catch { out: 4 } 990 }`, 991 Stdout: "2\n", 992 ExitNum: 0, 993 }, 994 { 995 Block: ` 996 switch foobar { 997 if foo { out: 1 } 998 if foobar { out: 2 } 999 case oof { out: 3 } 1000 catch { out: 4 } 1001 }`, 1002 Stdout: "2\n", 1003 ExitNum: 0, 1004 }, 1005 { 1006 Block: ` 1007 switch foobar { 1008 if foo { out: 1 } 1009 case foobar { out: 2 } 1010 if foobar { out: 3 } 1011 catch { out: 4 } 1012 }`, 1013 Stdout: "2\n", 1014 ExitNum: 0, 1015 }, 1016 { 1017 Block: ` 1018 switch foobar { 1019 case foo { out: 1 } 1020 if foobar { out: 2 } 1021 if oof { out: 3 } 1022 catch { out: 4 } 1023 }`, 1024 Stdout: "2\n", 1025 ExitNum: 0, 1026 }, 1027 } 1028 1029 test.RunMurexTests(tests, t) 1030 } 1031 1032 func TestSwitchByValCaseIfBlock4(t *testing.T) { 1033 tests := []test.MurexTest{ 1034 { 1035 Block: ` 1036 switch foobar { 1037 if foo then { out: 1 } 1038 if { out: foobar } then { out: 2 } 1039 if oof then { out: 3 } 1040 catch { out: 4 } 1041 }`, 1042 Stdout: "2\n", 1043 ExitNum: 0, 1044 }, 1045 { 1046 Block: ` 1047 switch foobar { 1048 if foo then { out: 1 } 1049 if { out: foobar } then { out: 2 } 1050 case oof then { out: 3 } 1051 catch { out: 4 } 1052 }`, 1053 Stdout: "2\n", 1054 ExitNum: 0, 1055 }, 1056 { 1057 Block: ` 1058 switch foobar { 1059 if foo then { out: 1 } 1060 case { out: foobar } then { out: 2 } 1061 if foobar then { out: 3 } 1062 catch { out: 4 } 1063 }`, 1064 Stdout: "2\n", 1065 ExitNum: 0, 1066 }, 1067 { 1068 Block: ` 1069 switch foobar { 1070 case foo then { out: 1 } 1071 if { out: foobar } then { out: 2 } 1072 if oof then { out: 3 } 1073 catch { out: 4 } 1074 }`, 1075 Stdout: "2\n", 1076 ExitNum: 0, 1077 }, 1078 ///// 1079 { 1080 Block: ` 1081 switch foobar { 1082 if foo { out: 1 } 1083 if { out: foobar } { out: 2 } 1084 if oof { out: 3 } 1085 catch { out: 4 } 1086 }`, 1087 Stdout: "2\n", 1088 ExitNum: 0, 1089 }, 1090 { 1091 Block: ` 1092 switch foobar { 1093 if foo { out: 1 } 1094 if { out: foobar } { out: 2 } 1095 case oof { out: 3 } 1096 catch { out: 4 } 1097 }`, 1098 Stdout: "2\n", 1099 ExitNum: 0, 1100 }, 1101 { 1102 Block: ` 1103 switch foobar { 1104 if foo { out: 1 } 1105 case { out: foobar } { out: 2 } 1106 if foobar { out: 3 } 1107 catch { out: 4 } 1108 }`, 1109 Stdout: "2\n", 1110 ExitNum: 0, 1111 }, 1112 { 1113 Block: ` 1114 switch foobar { 1115 case foo { out: 1 } 1116 if { out: foobar } { out: 2 } 1117 if oof { out: 3 } 1118 catch { out: 4 } 1119 }`, 1120 Stdout: "2\n", 1121 ExitNum: 0, 1122 }, 1123 } 1124 1125 test.RunMurexTests(tests, t) 1126 } 1127 1128 func TestSwitchErrors(t *testing.T) { 1129 tests := []test.MurexTest{ 1130 { 1131 Block: `switch`, 1132 Stderr: `no parameters`, 1133 ExitNum: 1, 1134 }, 1135 { 1136 Block: `switch foobar`, 1137 Stderr: `not a valid code block`, 1138 ExitNum: 1, 1139 }, 1140 { 1141 Block: `switch foo bar`, 1142 Stderr: `not a valid code block`, 1143 ExitNum: 1, 1144 }, 1145 { 1146 Block: `switch foo bar baz`, 1147 Stderr: `too many`, 1148 ExitNum: 1, 1149 }, 1150 /*{ 1151 Block: `switch {"}`, 1152 Stderr: `missing closing quote`, 1153 ExitNum: 1, 1154 }, 1155 { 1156 Block: `switch foo {"}`, 1157 Stderr: `missing closing quote`, 1158 ExitNum: 1, 1159 },*/ 1160 { 1161 Block: `switch foo { foobar }`, 1162 Stderr: `not a valid statement`, 1163 ExitNum: 1, 1164 }, 1165 { 1166 Block: "switch foo { if {false} }", 1167 Stderr: `too few parameters`, 1168 ExitNum: 1, 1169 }, 1170 /*{ 1171 Block: "switch foo { if {)} { out yes } }", 1172 Stderr: `if conditional:\n\s+> syntax error at`, 1173 ExitNum: 1, 1174 },*/ 1175 /*{ 1176 Block: "switch foo { if {true} {)} }", 1177 Stderr: `if conditional:\n\s+> syntax error at`, 1178 ExitNum: 1, 1179 },*/ 1180 /*{ 1181 Block: "switch foo { case {)} { out yes } }", 1182 Stderr: `case conditional:\n\s+> syntax error at`, 1183 ExitNum: 1, 1184 },*/ 1185 /*{ 1186 Block: "switch foo { case {true} {)} }", 1187 Stderr: `if conditional:\n\s+> syntax error at`, 1188 ExitNum: 1, 1189 },*/ 1190 /*{ 1191 Block: "switch foo { catch {)} }", 1192 Stderr: `catch block:\n\s+> syntax error at`, 1193 ExitNum: 1, 1194 },*/ 1195 { // nothing matched but no error 1196 Block: `switch foo { if "bob" { out "yes" } }`, 1197 Stdout: `^$`, 1198 Stderr: `^$`, 1199 ExitNum: 1, 1200 }, 1201 /*{ // nothing matched but no error // TODO: investigate 1202 Block: `switch foo { if "bob" { out "yes" }; catch {} }`, 1203 Stdout: `^$`, 1204 Stderr: `^$`, 1205 ExitNum: 0, 1206 },*/ 1207 } 1208 1209 test.RunMurexTestsRx(tests, t) 1210 }