Repository: jerryscript-project/jerryscript
File: tests/unit-core/test-container.c (C)

Code before:
            "  }\n"
            "}\n");

  run_eval ("var entries_check_array = [1, 3.14, 2, true, 3, 'foo'];\n"
            "var values_check_array = [3.14, true, 'foo'];\n"
            "var keys_check_array = [1, 2, 3,];\n"
            "var obj = { x:3, y:'foo'};\n"
            "var b_int = 1n;\n"
            "var object_check_array = [1, obj];\n");

  run_eval ("var map = new Map();\n"
            "map.set(1,3.14);\n"
            "map.set(2,true);\n"
            "map.set(3,'foo');\n"
            "var set = new Set();\n"
            "set.add(3.14);\n"
            "set.add(true);\n"
            "set.add('foo');\n"
            "var obj_map = new Map();\n"
            "obj_map.set(1, obj);\n");

  run_eval ("var result = create_array_from_container (map, true);\n"
            "test_values (result, entries_check_array);");

  run_eval ("var result = create_array_from_container (set, false);\n"
            "test_values (result, values_check_array);");

  run_eval ("var result = create_array_from_container (map.entries(), true);\n"
            "test_values (result, entries_check_array);");

  run_eval ("var result = create_array_from_container (map.keys(), false);\n"
            "test_values (result, keys_check_array);");

  run_eval ("var result = create_array_from_container (map.values(), false);\n"
            "test_values (result, values_check_array);");

  run_eval ("var result = create_array_from_container (obj_map, true)\n"
            "test_values (result, object_check_array);");

  run_eval ("var map = new Map();\n"
            "map.set(1,1);\n"
            "var iter = map.entries();\n"
            "iter.next();\n"
            "var result = create_array_from_container (iter, false);\n"
            "assert (result.length == 0);");

  run_eval ("var iter = null;\n"
            "var result = create_array_from_container (iter, false);\n"
            "assert (result === undefined);");

  run_eval_error ("var iter = 3;\n"

Review comment (suggestion):
Even if there are repeats, I would put the arrays here:
`test_values (result, [3.14, true, 'foo']);`
More readable.

Code after:
            "  }\n"
            "}\n");

  run_eval ("var map = new Map();\n"
            "map.set(1, 3.14);\n"
            "map.set(2, true);\n"
            "map.set(3, 'foo');\n"
            "var set = new Set();\n"
            "set.add(3.14);\n"
            "set.add(true);\n"
            "set.add('foo');\n"
            "var obj = { x:3, y:'foo'};\n"
            "var b_int = 1n;\n"
            "var obj_bint_map = new Map();\n"
            "obj_bint_map.set(1, obj);\n"
            "obj_bint_map.set(2, b_int);\n");

  run_eval ("var result = create_array_from_container(map, true);\n"
            "test_values(result, [1, 3.14, 2, true, 3, 'foo']);");

  run_eval ("var result = create_array_from_container(set, false);\n"
            "test_values(result, [3.14, true, 'foo']);");

  run_eval ("var result = create_array_from_container(map.entries(), true);\n"
            "test_values(result, [1, 3.14, 2, true, 3, 'foo']);");

  run_eval ("var result = create_array_from_container(map.keys(), false);\n"
            "test_values(result, [1, 2, 3,]);");

  run_eval ("var result = create_array_from_container(map.values(), false);\n"
            "test_values(result, [3.14, true, 'foo']);");

  run_eval ("var result = create_array_from_container(obj_bint_map, true)\n"
            "test_values(result, [1, obj, 2, b_int]);");

  run_eval ("var map = new Map();\n"
            "map.set(1, 1);\n"
            "var iter = map.entries();\n"
            "iter.next();\n"
            "var result = create_array_from_container(iter, true);\n"
            "assert(Array.isArray(result));\n"
            "assert(result.length == 0);");

  run_eval ("var ws = new WeakSet();\n"
            "var foo = {};\n"
            "var bar = {};\n"
            "ws.add(foo);\n"
            "ws.add(bar);\n"
            "var result = create_array_from_container(ws, false);\n"
            "test_values(result, [foo, bar]);\n");