Test the Iterate strategy: !S::Suite contents: - Iterate over a range: !S::Iterate over: !range 0...4 with: each iter: it test: Test on turn <>: !S::Assert test: | assert_equal('<>', '<>') assert_equal('<>', '<>') - Iterate over a range of Error: !S::Iterate over: !range 0...4 with: each iter: it test: Test on turn <>: !S::Error weight: -1 - Nested iterations: !S::Iterate over: !range 0..2 iter: ita test: Sub iteration <>: !S::Iterate over: !range 0..1 iter: itb test: Iteration (<>, <>): !S::Pass {} - Setup a ruby extension for tests: !S::Block test: | module ::Enumerable def uttk_test_iterate_each ( *a, &b ) uttk_each { |a| b[*(a.to_a)] } end end true - Many iterators can be used: !S::Suite symbols: results: [] contents: - Feed the result list: !S::Iterate over: [it, [ita, itb, itc, itd, ite]] with: uttk_test_iterate_each iter: pit test: Iterate with this iterator <<*pit>>: !S::Iterate over: !ruby | [0..4, 2..2, 'a'..'c'] with: uttk_test_iterate_each iter: <<*pit>> test: Many iterators <<<>:i>>: !S::Block test: | @symtbl[:results] << '<<<>:i>>, <<*<>>>, ' + '"<<<>>>", "<<<>:1>>", "<<<>>>"' - Check the results contents: !S::Assert symbols: ref_results: - '0, [0, 1, 2, 3, 4], "0", "1", "<<<>>>"' - '1, [2], "2", "1", "<<<>>>"' # the 2nd "1" is undef - '2, ["a", "b", "c"], "a", "b", "<<<>>>"' - '0, [0, 1, 2, 3, 4], "0", "1", "2"' - '1, [2], "2", "1", "2"' - '2, ["a", "b", "c"], "a", "b", "c"' test: | assert_equal(@symtbl[:ref_results], @symtbl[:results]) - Iterate can deal with many structures: !S::Suite symbols: results: [] attributes: !S::Iterate iter: it test: Iterate over many structures <>: !S::Block test: | @symtbl[:results] << '<<*it>>' contents: - Iterate over arrays: over: [1, 3, 7, 1042] - Iterate over ranges: over: !ruby "'p'..'r'" # FIXME !range - Iterate over a filelist: over: !filelist <>/../fixtures/ball/*-mini-lib.tar.* - Iterate over a pathlist: over: !pathlist <>/../fixtures/ball/(*)-mini-lib.tar.* - Iterate over a hash: over: foo: bar bar: baz qux: foo - Iterate over a Ruby value: over: !ruby | [2] * 3 - Check the results contents: !S::Assert symbols: ref_results: - "[1]" - "[3]" - "[7]" - "[1042]" - "[\"p\"]" - "[\"q\"]" - "[\"r\"]" - !re ".*/fixtures/ball/joe_i-mini-lib\.tar\.bz2" - !re ".*/fixtures/ball/qux_j-mini-lib\.tar\.bz2" - !re ".*/fixtures/ball/foo_s-mini-lib\.tar\.bz2" - !re ".*/fixtures/ball/bar_p-mini-lib\.tar\.bz2" - !re ".*/fixtures/ball/joe_i-mini-lib\.tar\.bz2" - !re ".*/fixtures/ball/qux_j-mini-lib\.tar\.bz2" - !re ".*/fixtures/ball/foo_s-mini-lib\.tar\.bz2" - !re ".*/fixtures/ball/bar_p-mini-lib\.tar\.bz2" - !re "\[:(foo|qux|bar), \"(bar|foo|baz)\"\]" - !re "\[:(foo|qux|bar), \"(bar|foo|baz)\"\]" - !re "\[:(foo|qux|bar), \"(bar|foo|baz)\"\]" - "[2]" - "[2]" - "[2]" test: | for ref, my in @symtbl[:ref_results].zip @symtbl[:results] do case ref when Regexp assert_match(ref, my) else assert_equal(ref, my) end end