diff options
Diffstat (limited to '')
-rw-r--r-- | test cases/common/60 foreach/meson.build | 53 | ||||
-rw-r--r-- | test cases/common/60 foreach/prog1.c | 6 | ||||
-rw-r--r-- | test cases/common/60 foreach/prog2.c | 6 | ||||
-rw-r--r-- | test cases/common/60 foreach/prog3.c | 6 | ||||
-rw-r--r-- | test cases/common/60 foreach/test.json | 10 |
5 files changed, 81 insertions, 0 deletions
diff --git a/test cases/common/60 foreach/meson.build b/test cases/common/60 foreach/meson.build new file mode 100644 index 0000000..af60e0f --- /dev/null +++ b/test cases/common/60 foreach/meson.build @@ -0,0 +1,53 @@ +project('foreach', 'c') + +tests = [['test1', 'prog1', 'prog1.c'], + ['test2', 'prog2', 'prog2.c', 'fallback'], + ['test3', 'prog3', 'prog3.c', 'urgh']] + +assert(tests[0].get(3, 'fallbck') == 'fallbck', 'array #1 fallback did not match') +assert(tests[1].get(3, 'failbk') == 'fallback', 'array #2 value did not match') +assert(tests[2].get(3, 'urgh') == 'urgh', 'array #3 value did not match') + +foreach i : tests + test(i.get(0), executable(i.get(1), i.get(2), install : true)) + + # Ensure that changing the tests variable does not + # affect ongoing iteration in the foreach loop. + # + # Being able to do that would make Meson Turing complete and + # we definitely don't want that. + tests = ['test4', 'prog4', 'prog4.c'] +endforeach + +items = ['a', 'continue', 'b', 'break', 'c'] +result = [] +foreach i : items + if i == 'continue' + continue + elif i == 'break' + break + endif + result += i +endforeach + +assert(result == ['a', 'b'], 'Continue or break in foreach failed') + +items = [] +iter = range(2) +foreach i : iter + items += i +endforeach +assert(items == [0, 1]) +assert(iter[1] == 1) + +items = [] +foreach i : range(1, 2) + items += i +endforeach +assert(items == [1]) + +items = [] +foreach i : range(1, 10, 2) + items += i +endforeach +assert(items == [1, 3, 5, 7, 9]) diff --git a/test cases/common/60 foreach/prog1.c b/test cases/common/60 foreach/prog1.c new file mode 100644 index 0000000..339dc49 --- /dev/null +++ b/test cases/common/60 foreach/prog1.c @@ -0,0 +1,6 @@ +#include<stdio.h> + +int main(void) { + printf("This is test #1.\n"); + return 0; +} diff --git a/test cases/common/60 foreach/prog2.c b/test cases/common/60 foreach/prog2.c new file mode 100644 index 0000000..c213288 --- /dev/null +++ b/test cases/common/60 foreach/prog2.c @@ -0,0 +1,6 @@ +#include<stdio.h> + +int main(void) { + printf("This is test #2.\n"); + return 0; +} diff --git a/test cases/common/60 foreach/prog3.c b/test cases/common/60 foreach/prog3.c new file mode 100644 index 0000000..905a530 --- /dev/null +++ b/test cases/common/60 foreach/prog3.c @@ -0,0 +1,6 @@ +#include<stdio.h> + +int main(void) { + printf("This is test #3.\n"); + return 0; +} diff --git a/test cases/common/60 foreach/test.json b/test cases/common/60 foreach/test.json new file mode 100644 index 0000000..2fc952d --- /dev/null +++ b/test cases/common/60 foreach/test.json @@ -0,0 +1,10 @@ +{ + "installed": [ + {"type": "exe", "file": "usr/bin/prog1"}, + {"type": "pdb", "file": "usr/bin/prog1"}, + {"type": "exe", "file": "usr/bin/prog2"}, + {"type": "pdb", "file": "usr/bin/prog2"}, + {"type": "exe", "file": "usr/bin/prog3"}, + {"type": "pdb", "file": "usr/bin/prog3"} + ] +} |