diff --git a/rocktest/rocktest/scenario/loop.go b/rocktest/rocktest/scenario/loop.go new file mode 100644 index 0000000..34df8f4 --- /dev/null +++ b/rocktest/rocktest/scenario/loop.go @@ -0,0 +1,29 @@ +package scenario + +func (module *Module) Loop(params map[string]interface{}, scenario *Scenario) error { + + paramsEx, err := scenario.ExpandMap(params) + if err != nil { + return err + } + + from, _ := scenario.GetNumber(paramsEx, "from", 0) + inc, _ := scenario.GetNumber(paramsEx, "inc", 1) + counter, _ := scenario.GetString(paramsEx, "counter", "i") + to, err := scenario.GetNumber(paramsEx, "to", nil) + if err != nil { + return err + } + + steps, _ := scenario.GetList(params, "steps", nil) + if err != nil { + return err + } + + for i := from; i < to; i += inc { + scenario.PutContext(counter, i) + scenario.RunSteps(steps) + } + + return nil +} diff --git a/rocktest/rocktest/test/yaml/loop_test.go b/rocktest/rocktest/test/yaml/loop_test.go new file mode 100644 index 0000000..ed68a1c --- /dev/null +++ b/rocktest/rocktest/test/yaml/loop_test.go @@ -0,0 +1,9 @@ +package yamlTest + +import ( + "testing" +) + +func TestLoop1(t *testing.T) { + shouldPass(t, "loop/loop.yaml") +} diff --git a/rocktest/rocktest/test/yaml/scen/loop/loop.yaml b/rocktest/rocktest/test/yaml/scen/loop/loop.yaml new file mode 100644 index 0000000..a006be1 --- /dev/null +++ b/rocktest/rocktest/test/yaml/scen/loop/loop.yaml @@ -0,0 +1,21 @@ +- title: Loop test + +- var: concat = - + +- loop: + params: + from: 0 + to: 10 + inc: 2 + counter: i + steps: + - display: ${i} + - display: AVANT ${concat} + - var: concat = ${concat}${i} + - display: APRES ${concat} + - dump: + +- assert.equals: + params: + expected: "-02468" + actual: ${concat}