github.com/lmorg/murex@v0.0.0-20240217211045-e081c89cd4ef/lang/expressions/parse_subshell_test.go (about) 1 package expressions_test 2 3 import ( 4 "testing" 5 6 _ "github.com/lmorg/murex/builtins" 7 "github.com/lmorg/murex/test" 8 ) 9 10 func TestParseSubShellScalar(t *testing.T) { 11 tests := []test.MurexTest{ 12 { 13 Block: `${out foobar}`, 14 Stdout: `foobar`, 15 }, 16 { 17 Block: `%[1 2 3 ${out foobar}]`, 18 Stdout: `[1,2,3,"foobar"]`, 19 }, 20 { 21 Block: `%[1 2 3 ${out foo bar}]`, 22 Stdout: `[1,2,3,"foo bar"]`, 23 }, 24 { 25 Block: `%{a: ${out foobar}}`, 26 Stdout: `{"a":"foobar"}`, 27 }, 28 { 29 Block: `%{a: ${out foo bar}}`, 30 Stdout: `{"a":"foo bar"}`, 31 }, 32 ///// 33 { 34 Block: `%[1 2 3 "${out foobar}"]`, 35 Stdout: `[1,2,3,"foobar"]`, 36 }, 37 { 38 Block: `%[1 2 3 "${out foo bar}"]`, 39 Stdout: `[1,2,3,"foo bar"]`, 40 }, 41 { 42 Block: `%{a: "${out foobar}"}`, 43 Stdout: `{"a":"foobar"}`, 44 }, 45 { 46 Block: `%{a: "${out foo bar}"}`, 47 Stdout: `{"a":"foo bar"}`, 48 }, 49 ///// 50 { 51 Block: `%[1 2 3 "-${out foobar}-"]`, 52 Stdout: `[1,2,3,"-foobar-"]`, 53 }, 54 { 55 Block: `%[1 2 3 "-${out foo bar}-"]`, 56 Stdout: `[1,2,3,"-foo bar-"]`, 57 }, 58 { 59 Block: `%{a: "-${out foobar}-"}`, 60 Stdout: `{"a":"-foobar-"}`, 61 }, 62 { 63 Block: `%{a: "-${out foo bar}-"}`, 64 Stdout: `{"a":"-foo bar-"}`, 65 }, 66 } 67 68 test.RunMurexTests(tests, t) 69 } 70 71 func TestParseSubShellScalarParam(t *testing.T) { 72 tests := []test.MurexTest{ 73 { 74 Block: `echo ${out foobar}`, 75 Stdout: "foobar\n", 76 }, 77 } 78 79 test.RunMurexTests(tests, t) 80 } 81 82 func TestParseSubShellArray(t *testing.T) { 83 tests := []test.MurexTest{ 84 { 85 Block: `@{ja: [1..3]}`, 86 Stdout: `[1,2,3]`, 87 }, 88 { 89 Block: `%[1 2 3 @{ja: [1..3]}]`, 90 Stdout: `[1,2,3,1,2,3]`, 91 }, 92 { 93 Block: `%[1 2 3 @{ja: [01..3]}]`, 94 Stdout: `[1,2,3,"01","02","03"]`, 95 }, 96 { 97 Block: `%{a: @{ja: [1..3]}}`, 98 Stdout: `{"a":[1,2,3]}`, 99 }, 100 { 101 Block: `%{a: @{ja: [01..3]}}`, 102 Stdout: `{"a":["01","02","03"]}`, 103 }, 104 ///// 105 { 106 Block: `%[1 2 3 "@{ja: [1..3]}"]`, 107 Stdout: `[1,2,3,"@{ja: [1..3]}"]`, 108 }, 109 { 110 Block: `%{a: "@{ja: [1..3]}"}`, 111 Stdout: `{"a":"@{ja: [1..3]}"}`, 112 }, 113 } 114 115 test.RunMurexTests(tests, t) 116 } 117 118 func TestParseSubShellArrayParams(t *testing.T) { 119 tests := []test.MurexTest{ 120 { 121 Block: `echo @{ja: [1..3]}`, 122 Stdout: "1 2 3\n", 123 }, 124 } 125 126 test.RunMurexTests(tests, t) 127 } 128 129 func TestParseSubShellEmptyArrayBugFix(t *testing.T) { 130 tests := []test.MurexTest{ 131 { 132 Block: ` 133 config: set proc strict-arrays false 134 echo: @{g: <!null> pseudo-random-string-that-will-not-be-matched-with-anything} 135 `, 136 Stdout: "\n", 137 }, 138 { 139 Block: ` 140 config: set proc strict-arrays false 141 bob = @{g: <!null> pseudo-random-string-that-will-not-be-matched-with-anything} 142 $bob 143 `, 144 Stdout: "[]", 145 }, 146 { 147 Block: ` 148 config: set proc strict-arrays false 149 bob = @{g: <!null> pseudo-random-string-that-will-not-be-matched-with-anything} 150 echo bob = $bob 151 `, 152 Stdout: "bob = []\n", 153 }, 154 { 155 Block: ` 156 config: set proc strict-arrays false 157 bob = @{g: <!null> pseudo-random-string-that-will-not-be-matched-with-anything} 158 echo bob = @bob 159 `, 160 Stdout: "bob =\n", 161 }, 162 } 163 164 test.RunMurexTests(tests, t) 165 } 166 167 func TestParseSubShellArrayJson(t *testing.T) { 168 tests := []test.MurexTest{ 169 { 170 Block: `echo @{tout json [1,2,3] }`, 171 Stdout: "1 2 3\n", 172 }, 173 } 174 175 test.RunMurexTests(tests, t) 176 } 177 178 func TestParseSubShellBugFixJsonStr(t *testing.T) { 179 tests := []test.MurexTest{ 180 { 181 Block: `TestParseSubShellBugFixJsonStr0 = %[1 2 3]; echo @{ $TestParseSubShellBugFixJsonStr0 }`, 182 Stdout: "1 2 3\n", 183 }, 184 { 185 Block: `TestParseSubShellBugFixJsonStr1 = %{a:1, b:2, c:[1 2 3]}; echo @{ $TestParseSubShellBugFixJsonStr1[c] }`, 186 Stdout: "1 2 3\n", 187 }, 188 } 189 190 test.RunMurexTests(tests, t) 191 }