diff options
Diffstat (limited to 'tests/custom/02_runtime/08_object_iteration')
-rw-r--r-- | tests/custom/02_runtime/08_object_iteration | 51 |
1 files changed, 51 insertions, 0 deletions
diff --git a/tests/custom/02_runtime/08_object_iteration b/tests/custom/02_runtime/08_object_iteration new file mode 100644 index 0000000..2e58cdf --- /dev/null +++ b/tests/custom/02_runtime/08_object_iteration @@ -0,0 +1,51 @@ +Testing object iteration behavior. + + +1. Testing that deleting properties during iteration is safe. + +-- Expect stdout -- +a +w +z +-- End -- + +-- Testcase -- +{% + o1 = { a: 1, b: 2, c: 3 }; + + for (k in o1) { + delete o1.a; + delete o1.b; + delete o1.c; + print(k, "\n"); + } + + o2 = { w: 1, x: 2, y: 3, z: 4 }; + + for (k in o2) { + delete o2.x; + delete o2.y; + print(k, "\n"); + } +%} +-- End -- + + +2. Test that reordering object properties during iteration is safe. + +-- Expect stdout -- +c +b +c +-- End -- + +-- Testcase -- +{% + o = { c: 1, b: 2, a: 3 }; + + for (k in o) { + sort(o); + print(k, "\n"); + } +%} +-- End -- |