github.com/lmorg/murex@v0.0.0-20240217211045-e081c89cd4ef/builtins/core/mkarray/array_test.go (about) 1 package mkarray 2 3 import ( 4 "testing" 5 6 _ "github.com/lmorg/murex/builtins/types/json" 7 _ "github.com/lmorg/murex/builtins/types/string" 8 _ "github.com/lmorg/murex/lang/expressions" 9 "github.com/lmorg/murex/test" 10 ) 11 12 func TestArrayOct(t *testing.T) { 13 tests := []test.MurexTest{ 14 // Octal defined by x 15 { 16 Block: `a: [1..10x8]`, 17 Stdout: "1\n2\n3\n4\n5\n6\n7\n10\n", 18 }, 19 { 20 Block: `a: [01..10x8]`, 21 Stdout: "01\n02\n03\n04\n05\n06\n07\n10\n", 22 }, 23 { 24 Block: `a: [001..10x8]`, 25 Stdout: "001\n002\n003\n004\n005\n006\n007\n010\n", 26 }, 27 // Octal defined by period 28 { 29 Block: `a: [1..10.8]`, 30 Stdout: "1\n2\n3\n4\n5\n6\n7\n10\n", 31 }, 32 { 33 Block: `a: [01..10.8]`, 34 Stdout: "01\n02\n03\n04\n05\n06\n07\n10\n", 35 }, 36 { 37 Block: `a: [001..10.8]`, 38 Stdout: "001\n002\n003\n004\n005\n006\n007\n010\n", 39 }, 40 } 41 42 test.RunMurexTests(tests, t) 43 } 44 45 func TestArrayDec(t *testing.T) { 46 tests := []test.MurexTest{ 47 // Decimal 48 { 49 Block: `a: [1..10]`, 50 Stdout: "1\n2\n3\n4\n5\n6\n7\n8\n9\n10\n", 51 }, 52 { 53 Block: `a: [01..10]`, 54 Stdout: "01\n02\n03\n04\n05\n06\n07\n08\n09\n10\n", 55 }, 56 { 57 Block: `a: [001..10]`, 58 Stdout: "001\n002\n003\n004\n005\n006\n007\n008\n009\n010\n", 59 }, 60 // Decimal defined by x 61 { 62 Block: `a: [1..10x10]`, 63 Stdout: "1\n2\n3\n4\n5\n6\n7\n8\n9\n10\n", 64 }, 65 { 66 Block: `a: [01..10x10]`, 67 Stdout: "01\n02\n03\n04\n05\n06\n07\n08\n09\n10\n", 68 }, 69 { 70 Block: `a: [001..10x10]`, 71 Stdout: "001\n002\n003\n004\n005\n006\n007\n008\n009\n010\n", 72 }, 73 // Decimal defined by period 74 { 75 Block: `a: [1..10.10]`, 76 Stdout: "1\n2\n3\n4\n5\n6\n7\n8\n9\n10\n", 77 }, 78 { 79 Block: `a: [01..10.10]`, 80 Stdout: "01\n02\n03\n04\n05\n06\n07\n08\n09\n10\n", 81 }, 82 { 83 Block: `a: [001..10.10]`, 84 Stdout: "001\n002\n003\n004\n005\n006\n007\n008\n009\n010\n", 85 }, 86 } 87 88 test.RunMurexTests(tests, t) 89 } 90 91 func TestArrayDecTyped(t *testing.T) { 92 tests := []test.MurexTest{ 93 // Decimal, typed 94 { 95 Block: `ta: json [0..10]`, 96 Stdout: "[0,1,2,3,4,5,6,7,8,9,10]", 97 }, 98 { 99 Block: `ta: json [1,3..5,7]`, 100 Stdout: "[1,3,4,5,7]", 101 }, 102 { 103 Block: `ta: json [01,3..5,7]`, 104 Stdout: `["01","3","4","5","7"]`, 105 }, 106 { 107 Block: `ta: json [1,03..5,7]`, 108 Stdout: `["1","03","04","05","7"]`, 109 }, 110 { 111 Block: `ta: json [1,3..5,07]`, 112 Stdout: `["1","3","4","5","07"]`, 113 }, 114 { 115 Block: `ta: json [01..10]`, 116 Stdout: `["01","02","03","04","05","06","07","08","09","10"]`, 117 }, 118 { 119 Block: `ta: json [00..10]`, 120 Stdout: `["00","01","02","03","04","05","06","07","08","09","10"]`, 121 }, 122 { 123 Block: `ja: [0..10]`, 124 Stdout: "[0,1,2,3,4,5,6,7,8,9,10]", 125 }, 126 { 127 Block: `ja: [01..10]`, 128 Stdout: `["01","02","03","04","05","06","07","08","09","10"]`, 129 }, 130 { 131 Block: `ja: [00..10]`, 132 Stdout: `["00","01","02","03","04","05","06","07","08","09","10"]`, 133 }, 134 ///// 135 { 136 Block: `ta: json [10..0]`, 137 Stdout: "[10,9,8,7,6,5,4,3,2,1,0]", 138 }, 139 { 140 Block: `ta: json [10..01]`, 141 Stdout: `["10","09","08","07","06","05","04","03","02","01"]`, 142 }, 143 { 144 Block: `ta: json [10..00]`, 145 Stdout: `["10","09","08","07","06","05","04","03","02","01","00"]`, 146 }, 147 { 148 Block: `ja: [10..0]`, 149 Stdout: "[10,9,8,7,6,5,4,3,2,1,0]", 150 }, 151 { 152 Block: `ja: [10..01]`, 153 Stdout: `["10","09","08","07","06","05","04","03","02","01"]`, 154 }, 155 { 156 Block: `ja: [10..00]`, 157 Stdout: `["10","09","08","07","06","05","04","03","02","01","00"]`, 158 }, 159 } 160 161 test.RunMurexTests(tests, t) 162 } 163 164 func TestArrayJson(t *testing.T) { 165 tests := []test.MurexTest{ 166 // Decimal, typed 167 { 168 Block: `ja: [0..10]`, 169 Stdout: "[0,1,2,3,4,5,6,7,8,9,10]", 170 }, 171 { 172 Block: `ja: [1,3..5,7]`, 173 Stdout: "[1,3,4,5,7]", 174 }, 175 { 176 Block: `ja: [01,3..5,7]`, 177 Stdout: `["01","3","4","5","7"]`, 178 }, 179 { 180 Block: `ja: [1,03..5,7]`, 181 Stdout: `["1","03","04","05","7"]`, 182 }, 183 { 184 Block: `ja: [1,3..5,07]`, 185 Stdout: `["1","3","4","5","07"]`, 186 }, 187 { 188 Block: `ja: [01..10]`, 189 Stdout: `["01","02","03","04","05","06","07","08","09","10"]`, 190 }, 191 } 192 193 test.RunMurexTests(tests, t) 194 } 195 196 func TestArrayHex(t *testing.T) { 197 tests := []test.MurexTest{ 198 // Hexadecimal defined by x 199 { 200 Block: `a: [1..10x16]`, 201 Stdout: "1\n2\n3\n4\n5\n6\n7\n8\n9\na\nb\nc\nd\ne\nf\n10\n", 202 }, 203 { 204 Block: `a: [01..10x16]`, 205 Stdout: "01\n02\n03\n04\n05\n06\n07\n08\n09\n0a\n0b\n0c\n0d\n0e\n0f\n10\n", 206 }, 207 { 208 Block: `a: [001..10x16]`, 209 Stdout: "001\n002\n003\n004\n005\n006\n007\n008\n009\n00a\n00b\n00c\n00d\n00e\n00f\n010\n", 210 }, 211 // Hexadecimal defined by period 212 { 213 Block: `a: [1..10.16]`, 214 Stdout: "1\n2\n3\n4\n5\n6\n7\n8\n9\na\nb\nc\nd\ne\nf\n10\n", 215 }, 216 { 217 Block: `a: [01..10.16]`, 218 Stdout: "01\n02\n03\n04\n05\n06\n07\n08\n09\n0a\n0b\n0c\n0d\n0e\n0f\n10\n", 219 }, 220 { 221 Block: `a: [001..10.16]`, 222 Stdout: "001\n002\n003\n004\n005\n006\n007\n008\n009\n00a\n00b\n00c\n00d\n00e\n00f\n010\n", 223 }, 224 } 225 226 test.RunMurexTests(tests, t) 227 } 228 229 func TestArrayBugFix489(t *testing.T) { 230 tests := []test.MurexTest{ 231 { 232 Block: `a: [1..3`, 233 Stderr: "missing closing square bracket", 234 ExitNum: 1, 235 }, 236 { 237 Block: `a: [1..`, 238 Stderr: "missing closing square bracket", 239 ExitNum: 1, 240 }, 241 { 242 Block: `a: [..3`, 243 Stderr: "missing closing square bracket", 244 ExitNum: 1, 245 }, 246 { 247 Block: `a: [..`, 248 Stderr: "missing closing square bracket", 249 ExitNum: 1, 250 }, 251 ///// 252 { 253 Block: `a: [mon..fri`, 254 Stderr: "missing closing square bracket", 255 ExitNum: 1, 256 }, 257 { 258 Block: `a: [mon..`, 259 Stderr: "missing closing square bracket", 260 ExitNum: 1, 261 }, 262 { 263 Block: `a: [..fri`, 264 Stderr: "missing closing square bracket", 265 ExitNum: 1, 266 }, 267 ///// 268 { 269 Block: `a: [ 1 .. 2`, 270 Stderr: "missing closing square bracket", 271 ExitNum: 1, 272 }, 273 } 274 275 test.RunMurexTestsRx(tests, t) 276 }