github.com/lmorg/murex@v0.0.0-20240217211045-e081c89cd4ef/builtins/core/structs/foreach_test.go (about) 1 package structs_test 2 3 import ( 4 "testing" 5 6 _ "github.com/lmorg/murex/builtins" 7 "github.com/lmorg/murex/lang/types" 8 "github.com/lmorg/murex/test" 9 ) 10 11 func TestForEach(t *testing.T) { 12 tests := []test.MurexTest{ 13 { 14 Block: `a: [Monday..Friday] -> foreach day { out "$day is the best day" }`, 15 Stdout: "Monday is the best day\nTuesday is the best day\nWednesday is the best day\nThursday is the best day\nFriday is the best day\n", 16 }, 17 { 18 Block: `a: [Monday..Friday] -> foreach day { out "$day is the best day" }`, 19 Stdout: "Monday is the best day\nTuesday is the best day\nWednesday is the best day\nThursday is the best day\nFriday is the best day\n", 20 }, 21 { 22 Block: `a: [Mon..Fri] -> foreach { -> suffix "day" }`, 23 Stdout: "Monday\nTueday\nWedday\nThuday\nFriday\n", 24 }, 25 { 26 Block: `ja: [Mon..Fri] -> foreach { -> suffix "day" }`, 27 Stdout: "Monday\nTueday\nWedday\nThuday\nFriday\n", 28 }, 29 { 30 Block: `a: [Mon..Fri] -> foreach --jmap day { $day } { out $day"day" }`, 31 Stdout: `{"Fri":"Friday","Mon":"Monday","Thu":"Thuday","Tue":"Tueday","Wed":"Wedday"}`, 32 }, 33 { 34 Block: `ja: [Mon..Fri] -> foreach --jmap day { $day } { out $day"day" }`, 35 Stdout: `{"Fri":"Friday","Mon":"Monday","Thu":"Thuday","Tue":"Tueday","Wed":"Wedday"}`, 36 }, 37 { 38 Block: `a: [Mon..Fri] -> foreach { out nothing } -> debug -> [[ /Data-Type/Murex ]]`, 39 Stdout: types.String, 40 }, 41 { 42 Block: `ja: [Mon..Fri] -> foreach { out nothing } -> debug -> [[ /Data-Type/Murex ]]`, 43 Stdout: types.JsonLines, 44 }, 45 { 46 Block: `a: [Mon..Fri] -> foreach { null } -> debug -> [[ /Data-Type/Murex ]]`, 47 Stdout: types.String, 48 }, 49 { 50 Block: `ja: [Mon..Fri] -> foreach { null } -> debug -> [[ /Data-Type/Murex ]]`, 51 Stdout: types.JsonLines, 52 }, 53 } 54 55 test.RunMurexTests(tests, t) 56 }