github.com/lmorg/murex@v0.0.0-20240217211045-e081c89cd4ef/lang/variables_dot_test.go (about) 1 package lang_test 2 3 import ( 4 "testing" 5 6 "github.com/lmorg/murex/test" 7 ) 8 9 func TestVarGlobal(t *testing.T) { 10 tests := []test.MurexTest{ 11 { 12 Block: ` 13 $GLOBAL.MurexTestVarGlobal00 = "fggfhsrt345u567jyujmdfgbfghbn" 14 $MurexTestVarGlobal00 15 `, 16 Stdout: "fggfhsrt345u567jyujmdfgbfghbn", 17 }, 18 { 19 Block: ` 20 set GLOBAL.MurexTestVarGlobal01 = "sdfp23io4j3409asLKJHD2E9OP8I2340kjhlkj" 21 $MurexTestVarGlobal01 22 `, 23 Stdout: "sdfp23io4j3409asLKJHD2E9OP8I2340kjhlkj", 24 }, 25 { 26 Block: ` 27 $GLOBAL.MurexTestVarGlobal02 = "abc" 28 $MurexTestVarGlobal02 -> debug -> [[ /data-type/murex ]] 29 `, 30 Stdout: "str", 31 }, 32 { 33 Block: ` 34 $GLOBAL.MurexTestVarGlobal03 = 123 35 $MurexTestVarGlobal03 -> debug -> [[ /data-type/murex ]] 36 `, 37 Stdout: "num", 38 }, 39 } 40 41 test.RunMurexTests(tests, t) 42 } 43 44 func TestVarEnv(t *testing.T) { 45 tests := []test.MurexTest{ 46 { 47 Block: ` 48 $ENV.MurexTestVarEnv00 = "lskdjflsakdjfoiwjef;oweijflsd;kjfweo;ij" 49 env -> regexp m/MurexTestVarEnv00/ 50 `, 51 Stdout: "MurexTestVarEnv00=lskdjflsakdjfoiwjef;oweijflsd;kjfweo;ij\n", 52 }, 53 { 54 Block: ` 55 set ENV.MurexTestVarEnv01 = "ertyrtysdf;sldk;flkp;o342--04ik" 56 env -> regexp m/MurexTestVarEnv01/ 57 `, 58 Stdout: "MurexTestVarEnv01=ertyrtysdf;sldk;flkp;o342--04ik\n", 59 }, 60 { 61 Block: ` 62 $ENV.MurexTestVarEnv02 = "abc" 63 $MurexTestVarEnv02 -> debug -> [[ /data-type/murex ]] 64 `, 65 Stdout: "str", 66 }, 67 { 68 Block: ` 69 $ENV.MurexTestVarEnv03 = 123 70 $MurexTestVarEnv03 -> debug -> [[ /data-type/murex ]] 71 `, 72 Stdout: "str", 73 }, 74 } 75 76 test.RunMurexTests(tests, t) 77 } 78 79 func TestVarDotType(t *testing.T) { 80 tests := []test.MurexTest{ 81 { 82 Block: ` 83 $TestVarDotType00 = %{a:1, b:2, c:3} 84 $TestVarDotType00 -> debug -> [[ /data-type/murex ]] 85 `, 86 Stdout: "^json$", 87 }, 88 { 89 Block: ` 90 $TestVarDotType01 = %{a:1, b:2, c:3} 91 $TestVarDotType01.b -> debug -> [[ /data-type/murex ]] 92 `, 93 Stdout: "^num$", 94 }, 95 { 96 Block: ` 97 $TestVarDotType02 = %{1:a, 2:b, 3:c} 98 $TestVarDotType02.2 -> debug -> [[ /data-type/murex ]] 99 $TestVarDotType02.2 = 10 100 $TestVarDotType02.2 -> debug -> [[ /data-type/murex ]] 101 `, 102 Stdout: "^strstr$", 103 }, 104 { 105 Block: ` 106 $TestVarDotType03 = %{a:1, b:2, c:3} 107 $TestVarDotType03.b -> debug -> [[ /data-type/murex ]] 108 $TestVarDotType03.b = "abc" 109 $TestVarDotType03.b -> debug -> [[ /data-type/murex ]] 110 `, 111 Stdout: "^numnum$", 112 Stderr: "cannot convert 'abc' to a floating point number", 113 }, 114 { 115 Block: ` 116 $TestVarDotType04 = %{1:a, 2:b, 3:c, 4: [1, 2, 3]} 117 $TestVarDotType04.4 -> debug -> [[ /data-type/murex ]] 118 $TestVarDotType04.5 = 10 119 $TestVarDotType04.5 -> debug -> [[ /data-type/murex ]] 120 `, 121 Stdout: "^jsonnum$", 122 }, 123 } 124 125 test.RunMurexTestsRx(tests, t) 126 }