• source navigation  • diff markup  • identifier search  • freetext search  • 

Sources/ucode/tests/custom/02_runtime/08_object_iteration

  1 Testing object iteration behavior.
  2 
  3 
  4 1. Testing that deleting properties during iteration is safe.
  5 
  6 -- Expect stdout --
  7 a
  8 w
  9 z
 10 -- End --
 11 
 12 -- Testcase --
 13 {%
 14         o1 = { a: 1, b: 2, c: 3 };
 15 
 16         for (k in o1) {
 17                 delete o1.a;
 18                 delete o1.b;
 19                 delete o1.c;
 20                 print(k, "\n");
 21         }
 22 
 23         o2 = { w: 1, x: 2, y: 3, z: 4 };
 24 
 25         for (k in o2) {
 26                 delete o2.x;
 27                 delete o2.y;
 28                 print(k, "\n");
 29         }
 30 %}
 31 -- End --
 32 
 33 
 34 2. Test that reordering object properties during iteration is safe.
 35 
 36 -- Expect stdout --
 37 c
 38 b
 39 c
 40 -- End --
 41 
 42 -- Testcase --
 43 {%
 44         o = { c: 1, b: 2, a: 3 };
 45 
 46         for (k in o) {
 47                 sort(o);
 48                 print(k, "\n");
 49         }
 50 %}
 51 -- End --

This page was automatically generated by LXR 0.3.1.  •  OpenWrt