github.com/lmorg/murex@v0.0.0-20240217211045-e081c89cd4ef/lang/variables_mx_test.go (about) 1 package lang_test 2 3 import ( 4 "testing" 5 6 "github.com/lmorg/murex/test" 7 ) 8 9 // https://github.com/lmorg/murex/issues/138 10 func TestVariableMxLocal(t *testing.T) { 11 mxt := test.MurexTest{ 12 Block: ` 13 function TestVariableMxLocal2 { 14 set TestVariableMxLocal=redefined 15 } 16 function TestVariableMxLocal1 { 17 set TestVariableMxLocal=original 18 TestVariableMxLocal2 19 $TestVariableMxLocal 20 } 21 TestVariableMxLocal1`, 22 23 Stdout: `original`, 24 } 25 26 test.RunMurexTests([]test.MurexTest{mxt}, t) 27 } 28 29 func TestVariableMxGlobal(t *testing.T) { 30 mxt := test.MurexTest{ 31 Block: ` 32 function TestVariableMxGlobal2 { 33 global TestVariableMxGlobal=redefined 34 } 35 function TestVariableMxGlobal1 { 36 global TestVariableMxGlobal=original 37 TestVariableMxGlobal2 38 $TestVariableMxGlobal 39 } 40 TestVariableMxGlobal1`, 41 42 Stdout: `redefined`, 43 } 44 45 test.RunMurexTests([]test.MurexTest{mxt}, t) 46 } 47 48 func TestVariableMxLocalGlobal(t *testing.T) { 49 mxt := test.MurexTest{ 50 Block: ` 51 function TestVariableMxLocalGlobal2 { 52 global t=redefined 53 } 54 function TestVariableMxLocalGlobal1 { 55 set TestVariableMxLocalGlobal=original 56 TestVariableMxLocalGlobal2 57 $TestVariableMxLocalGlobal 58 } 59 TestVariableMxLocalGlobal1`, 60 61 Stdout: `original`, 62 } 63 64 test.RunMurexTests([]test.MurexTest{mxt}, t) 65 } 66 67 func TestVariableMxGlobalLocal(t *testing.T) { 68 mxt := test.MurexTest{ 69 Block: ` 70 function test2 { 71 set t=redefined 72 } 73 function test1 { 74 global t=original 75 test2 76 $t 77 } 78 test1`, 79 80 Stdout: `original`, 81 } 82 83 test.RunMurexTests([]test.MurexTest{mxt}, t) 84 } 85 86 /*func TestVariableMxForLoop(t *testing.T) { 87 mxt := test.MurexTest{ 88 Block: ` 89 function TestVariableMxForLoop2 { 90 for (TestVariableMxForLoop=0; TestVariableMxForLoop<5; TestVariableMxForLoop++) { 91 $TestVariableMxForLoop 92 } 93 echo $TestVariableMxForLoop 94 } 95 function TestVariableMxForLoop1 { 96 TestVariableMxForLoop2 97 echo $TestVariableMxForLoop 98 } 99 TestVariableMxForLoop1`, 100 101 Stdout: "01234\n\n", 102 } 103 104 test.RunMurexTests([]test.MurexTest{mxt}, t) 105 }*/ 106 107 /*func TestVariableMxForLoopGlobal(t *testing.T) { 108 mxt := test.MurexTest{ 109 Block: ` 110 function TestVariableMxForLoopGlobal2 { 111 for (TestVariableMxForLoopGlobal=0; TestVariableMxForLoopGlobal<5; TestVariableMxForLoopGlobal++) { 112 $TestVariableMxForLoopGlobal 113 } 114 echo $TestVariableMxForLoopGlobal 115 } 116 function TestVariableMxForLoopGlobal1 { 117 global TestVariableMxForLoopGlobal=-1 118 TestVariableMxForLoopGlobal2 119 echo $TestVariableMxForLoopGlobal 120 } 121 TestVariableMxForLoopGlobal1`, 122 123 Stdout: "012345\n5\n", 124 } 125 126 test.RunMurexTests([]test.MurexTest{mxt}, t) 127 }*/ 128 129 /*func TestVariableMxForLoopLocal(t *testing.T) { 130 mxt := test.MurexTest{ 131 Block: ` 132 function TestVariableMxForLoopLocal2 { 133 for (TestVariableMxForLoopLocal=0; TestVariableMxForLoopLocal<5; TestVariableMxForLoopLocal++) { 134 $TestVariableMxForLoopLocal 135 } 136 echo $TestVariableMxForLoopLocal 137 } 138 function TestVariableMxForLoopLocal1 { 139 set TestVariableMxForLoopLocal=-1 140 TestVariableMxForLoopLocal2 141 echo $TestVariableMxForLoopLocal 142 } 143 TestVariableMxForLoopLocal1`, 144 145 Stdout: "01234\n-1\n", 146 } 147 148 test.RunMurexTests([]test.MurexTest{mxt}, t) 149 } 150 */