Skip to content

Commit 497455e

Browse files
committed
added ES6 map and set tests
1 parent b29c3a8 commit 497455e

4 files changed

Lines changed: 390 additions & 0 deletions

File tree

Lines changed: 204 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,204 @@
1+
{ code: '// adapted from https://developer.mozilla.org/en-US/docs/Web/JavaScript/Reference/Global_Objects/Map\nvar myMap = new Map();\n\nvar keyString = "a string",\n keyObj = {},\n keyFunc = function () {};\n\n// setting the values\nmyMap.set(keyString, "value associated with \'a string\'");\nmyMap.set(keyObj, "value associated with keyObj");\nmyMap.set(keyFunc, "value associated with keyFunc");\n\nconsole.log(myMap.size === 3); // 3\n\n// getting the values\nconsole.log(myMap.get(keyString)); // "value associated with \'a string\'"\nconsole.log(myMap.get(keyObj)); // "value associated with keyObj"\nconsole.log(myMap.get(keyFunc)); // "value associated with keyFunc"\n\nconsole.log(myMap.get("a string")); // "value associated with \'a string\'"\n // because keyString === \'a string\'\nconsole.log(myMap.get({})); // undefined, because keyObj !== {}\nconsole.log(myMap.get(function() {})); // undefined, because keyFunc !== function () {}',
2+
trace:
3+
[ { stdout: '',
4+
func_name: '',
5+
stack_to_render: [],
6+
globals:
7+
{ myMap: [ 'JS_SPECIAL_VAL', 'undefined' ],
8+
keyString: [ 'JS_SPECIAL_VAL', 'undefined' ],
9+
keyObj: [ 'JS_SPECIAL_VAL', 'undefined' ],
10+
keyFunc: [ 'JS_SPECIAL_VAL', 'undefined' ] },
11+
ordered_globals: [ 'myMap', 'keyString', 'keyObj', 'keyFunc' ],
12+
line: 2,
13+
col: 0,
14+
event: 'step_line',
15+
heap: {} },
16+
{ stdout: '',
17+
func_name: '',
18+
stack_to_render: [],
19+
globals:
20+
{ myMap: [ 'REF', 1 ],
21+
keyString: [ 'JS_SPECIAL_VAL', 'undefined' ],
22+
keyObj: [ 'JS_SPECIAL_VAL', 'undefined' ],
23+
keyFunc: [ 'JS_SPECIAL_VAL', 'undefined' ] },
24+
ordered_globals: [ 'myMap', 'keyString', 'keyObj', 'keyFunc' ],
25+
line: 4,
26+
col: 0,
27+
event: 'step_line',
28+
heap: { '1': [ 'INSTANCE_PPRINT', 'object', '[object Map]' ] } },
29+
{ stdout: '',
30+
func_name: '',
31+
stack_to_render: [],
32+
globals:
33+
{ myMap: [ 'REF', 1 ],
34+
keyString: 'a string',
35+
keyObj: [ 'REF', 2 ],
36+
keyFunc: [ 'REF', 3 ] },
37+
ordered_globals: [ 'myMap', 'keyString', 'keyObj', 'keyFunc' ],
38+
line: 9,
39+
col: 0,
40+
event: 'step_line',
41+
heap:
42+
{ '1': [ 'INSTANCE_PPRINT', 'object', '[object Map]' ],
43+
'2': [ 'INSTANCE', '' ],
44+
'3': [ 'JS_FUNCTION', '', 'function () {}', null, null ] } },
45+
{ stdout: '',
46+
func_name: '',
47+
stack_to_render: [],
48+
globals:
49+
{ myMap: [ 'REF', 1 ],
50+
keyString: 'a string',
51+
keyObj: [ 'REF', 2 ],
52+
keyFunc: [ 'REF', 3 ] },
53+
ordered_globals: [ 'myMap', 'keyString', 'keyObj', 'keyFunc' ],
54+
line: 10,
55+
col: 0,
56+
event: 'step_line',
57+
heap:
58+
{ '1': [ 'INSTANCE_PPRINT', 'object', '[object Map]' ],
59+
'2': [ 'INSTANCE', '' ],
60+
'3': [ 'JS_FUNCTION', '', 'function () {}', null, null ] } },
61+
{ stdout: '',
62+
func_name: '',
63+
stack_to_render: [],
64+
globals:
65+
{ myMap: [ 'REF', 1 ],
66+
keyString: 'a string',
67+
keyObj: [ 'REF', 2 ],
68+
keyFunc: [ 'REF', 3 ] },
69+
ordered_globals: [ 'myMap', 'keyString', 'keyObj', 'keyFunc' ],
70+
line: 11,
71+
col: 0,
72+
event: 'step_line',
73+
heap:
74+
{ '1': [ 'INSTANCE_PPRINT', 'object', '[object Map]' ],
75+
'2': [ 'INSTANCE', '' ],
76+
'3': [ 'JS_FUNCTION', '', 'function () {}', null, null ] } },
77+
{ stdout: '',
78+
func_name: '',
79+
stack_to_render: [],
80+
globals:
81+
{ myMap: [ 'REF', 1 ],
82+
keyString: 'a string',
83+
keyObj: [ 'REF', 2 ],
84+
keyFunc: [ 'REF', 3 ] },
85+
ordered_globals: [ 'myMap', 'keyString', 'keyObj', 'keyFunc' ],
86+
line: 13,
87+
col: 0,
88+
event: 'step_line',
89+
heap:
90+
{ '1': [ 'INSTANCE_PPRINT', 'object', '[object Map]' ],
91+
'2': [ 'INSTANCE', '' ],
92+
'3': [ 'JS_FUNCTION', '', 'function () {}', null, null ] } },
93+
{ stdout: 'true\n',
94+
func_name: '',
95+
stack_to_render: [],
96+
globals:
97+
{ myMap: [ 'REF', 1 ],
98+
keyString: 'a string',
99+
keyObj: [ 'REF', 2 ],
100+
keyFunc: [ 'REF', 3 ] },
101+
ordered_globals: [ 'myMap', 'keyString', 'keyObj', 'keyFunc' ],
102+
line: 16,
103+
col: 0,
104+
event: 'step_line',
105+
heap:
106+
{ '1': [ 'INSTANCE_PPRINT', 'object', '[object Map]' ],
107+
'2': [ 'INSTANCE', '' ],
108+
'3': [ 'JS_FUNCTION', '', 'function () {}', null, null ] } },
109+
{ stdout: 'true\nvalue associated with \'a string\'\n',
110+
func_name: '',
111+
stack_to_render: [],
112+
globals:
113+
{ myMap: [ 'REF', 1 ],
114+
keyString: 'a string',
115+
keyObj: [ 'REF', 2 ],
116+
keyFunc: [ 'REF', 3 ] },
117+
ordered_globals: [ 'myMap', 'keyString', 'keyObj', 'keyFunc' ],
118+
line: 17,
119+
col: 0,
120+
event: 'step_line',
121+
heap:
122+
{ '1': [ 'INSTANCE_PPRINT', 'object', '[object Map]' ],
123+
'2': [ 'INSTANCE', '' ],
124+
'3': [ 'JS_FUNCTION', '', 'function () {}', null, null ] } },
125+
{ stdout: 'true\nvalue associated with \'a string\'\nvalue associated with keyObj\n',
126+
func_name: '',
127+
stack_to_render: [],
128+
globals:
129+
{ myMap: [ 'REF', 1 ],
130+
keyString: 'a string',
131+
keyObj: [ 'REF', 2 ],
132+
keyFunc: [ 'REF', 3 ] },
133+
ordered_globals: [ 'myMap', 'keyString', 'keyObj', 'keyFunc' ],
134+
line: 18,
135+
col: 0,
136+
event: 'step_line',
137+
heap:
138+
{ '1': [ 'INSTANCE_PPRINT', 'object', '[object Map]' ],
139+
'2': [ 'INSTANCE', '' ],
140+
'3': [ 'JS_FUNCTION', '', 'function () {}', null, null ] } },
141+
{ stdout: 'true\nvalue associated with \'a string\'\nvalue associated with keyObj\nvalue associated with keyFunc\n',
142+
func_name: '',
143+
stack_to_render: [],
144+
globals:
145+
{ myMap: [ 'REF', 1 ],
146+
keyString: 'a string',
147+
keyObj: [ 'REF', 2 ],
148+
keyFunc: [ 'REF', 3 ] },
149+
ordered_globals: [ 'myMap', 'keyString', 'keyObj', 'keyFunc' ],
150+
line: 20,
151+
col: 0,
152+
event: 'step_line',
153+
heap:
154+
{ '1': [ 'INSTANCE_PPRINT', 'object', '[object Map]' ],
155+
'2': [ 'INSTANCE', '' ],
156+
'3': [ 'JS_FUNCTION', '', 'function () {}', null, null ] } },
157+
{ stdout: 'true\nvalue associated with \'a string\'\nvalue associated with keyObj\nvalue associated with keyFunc\nvalue associated with \'a string\'\n',
158+
func_name: '',
159+
stack_to_render: [],
160+
globals:
161+
{ myMap: [ 'REF', 1 ],
162+
keyString: 'a string',
163+
keyObj: [ 'REF', 2 ],
164+
keyFunc: [ 'REF', 3 ] },
165+
ordered_globals: [ 'myMap', 'keyString', 'keyObj', 'keyFunc' ],
166+
line: 22,
167+
col: 0,
168+
event: 'step_line',
169+
heap:
170+
{ '1': [ 'INSTANCE_PPRINT', 'object', '[object Map]' ],
171+
'2': [ 'INSTANCE', '' ],
172+
'3': [ 'JS_FUNCTION', '', 'function () {}', null, null ] } },
173+
{ stdout: 'true\nvalue associated with \'a string\'\nvalue associated with keyObj\nvalue associated with keyFunc\nvalue associated with \'a string\'\nundefined\n',
174+
func_name: '',
175+
stack_to_render: [],
176+
globals:
177+
{ myMap: [ 'REF', 1 ],
178+
keyString: 'a string',
179+
keyObj: [ 'REF', 2 ],
180+
keyFunc: [ 'REF', 3 ] },
181+
ordered_globals: [ 'myMap', 'keyString', 'keyObj', 'keyFunc' ],
182+
line: 23,
183+
col: 0,
184+
event: 'step_line',
185+
heap:
186+
{ '1': [ 'INSTANCE_PPRINT', 'object', '[object Map]' ],
187+
'2': [ 'INSTANCE', '' ],
188+
'3': [ 'JS_FUNCTION', '', 'function () {}', null, null ] } },
189+
{ stdout: 'true\nvalue associated with \'a string\'\nvalue associated with keyObj\nvalue associated with keyFunc\nvalue associated with \'a string\'\nundefined\nundefined\n',
190+
func_name: '',
191+
stack_to_render: [],
192+
globals:
193+
{ myMap: [ 'REF', 1 ],
194+
keyString: 'a string',
195+
keyObj: [ 'REF', 2 ],
196+
keyFunc: [ 'REF', 3 ] },
197+
ordered_globals: [ 'myMap', 'keyString', 'keyObj', 'keyFunc' ],
198+
line: 23,
199+
col: 87,
200+
event: 'step_line',
201+
heap:
202+
{ '1': [ 'INSTANCE_PPRINT', 'object', '[object Map]' ],
203+
'2': [ 'INSTANCE', '' ],
204+
'3': [ 'JS_FUNCTION', '', 'function () {}', null, null ] } } ] }
Lines changed: 23 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,23 @@
1+
// adapted from https://developer.mozilla.org/en-US/docs/Web/JavaScript/Reference/Global_Objects/Map
2+
var myMap = new Map();
3+
4+
var keyString = "a string",
5+
keyObj = {},
6+
keyFunc = function () {};
7+
8+
// setting the values
9+
myMap.set(keyString, "value associated with 'a string'");
10+
myMap.set(keyObj, "value associated with keyObj");
11+
myMap.set(keyFunc, "value associated with keyFunc");
12+
13+
console.log(myMap.size === 3); // 3
14+
15+
// getting the values
16+
console.log(myMap.get(keyString)); // "value associated with 'a string'"
17+
console.log(myMap.get(keyObj)); // "value associated with keyObj"
18+
console.log(myMap.get(keyFunc)); // "value associated with keyFunc"
19+
20+
console.log(myMap.get("a string")); // "value associated with 'a string'"
21+
// because keyString === 'a string'
22+
console.log(myMap.get({})); // undefined, because keyObj !== {}
23+
console.log(myMap.get(function() {})); // undefined, because keyFunc !== function () {}
Lines changed: 153 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,153 @@
1+
{ code: '// adapted from http://es6-features.org/#SetDataStructure\nlet s = new Set();\ns.add("hello").add("goodbye");\ns.add("hello");\ns.add("foo");\ns.delete("foo");\nconsole.log(s.size === 2);\nconsole.log(s.has("hello") === true);\nfor (let key of s.values()) // insertion order\n console.log(key);',
2+
trace:
3+
[ { stdout: '',
4+
func_name: '',
5+
stack_to_render: [],
6+
globals: {},
7+
ordered_globals: [],
8+
line: 2,
9+
col: 0,
10+
event: 'step_line',
11+
heap: {} },
12+
{ stdout: '',
13+
func_name: '',
14+
stack_to_render: [],
15+
globals: { s: [ 'REF', 1 ] },
16+
ordered_globals: [ 's' ],
17+
line: 3,
18+
col: 0,
19+
event: 'step_line',
20+
heap: { '1': [ 'INSTANCE_PPRINT', 'object', '[object Set]' ] } },
21+
{ stdout: '',
22+
func_name: '',
23+
stack_to_render: [],
24+
globals: { s: [ 'REF', 1 ] },
25+
ordered_globals: [ 's' ],
26+
line: 4,
27+
col: 0,
28+
event: 'step_line',
29+
heap: { '1': [ 'INSTANCE_PPRINT', 'object', '[object Set]' ] } },
30+
{ stdout: '',
31+
func_name: '',
32+
stack_to_render: [],
33+
globals: { s: [ 'REF', 1 ] },
34+
ordered_globals: [ 's' ],
35+
line: 5,
36+
col: 0,
37+
event: 'step_line',
38+
heap: { '1': [ 'INSTANCE_PPRINT', 'object', '[object Set]' ] } },
39+
{ stdout: '',
40+
func_name: '',
41+
stack_to_render: [],
42+
globals: { s: [ 'REF', 1 ] },
43+
ordered_globals: [ 's' ],
44+
line: 6,
45+
col: 0,
46+
event: 'step_line',
47+
heap: { '1': [ 'INSTANCE_PPRINT', 'object', '[object Set]' ] } },
48+
{ stdout: '',
49+
func_name: '',
50+
stack_to_render: [],
51+
globals: { s: [ 'REF', 1 ] },
52+
ordered_globals: [ 's' ],
53+
line: 7,
54+
col: 0,
55+
event: 'step_line',
56+
heap: { '1': [ 'INSTANCE_PPRINT', 'object', '[object Set]' ] } },
57+
{ stdout: 'true\n',
58+
func_name: '',
59+
stack_to_render: [],
60+
globals: { s: [ 'REF', 1 ] },
61+
ordered_globals: [ 's' ],
62+
line: 8,
63+
col: 0,
64+
event: 'step_line',
65+
heap: { '1': [ 'INSTANCE_PPRINT', 'object', '[object Set]' ] } },
66+
{ stdout: 'true\ntrue\n',
67+
func_name: '',
68+
stack_to_render: [],
69+
globals:
70+
{ s: [ 'REF', 1 ],
71+
'key (block 1)': [ 'JS_SPECIAL_VAL', 'undefined' ] },
72+
ordered_globals: [ 's', 'key (block 1)' ],
73+
line: 9,
74+
col: 18,
75+
event: 'step_line',
76+
heap: { '1': [ 'INSTANCE_PPRINT', 'object', '[object Set]' ] } },
77+
{ stdout: 'true\ntrue\n',
78+
func_name: '',
79+
stack_to_render: [],
80+
globals:
81+
{ s: [ 'REF', 1 ],
82+
'key (block 1)': [ 'JS_SPECIAL_VAL', 'undefined' ] },
83+
ordered_globals: [ 's', 'key (block 1)' ],
84+
line: 9,
85+
col: 16,
86+
event: 'step_line',
87+
heap: { '1': [ 'INSTANCE_PPRINT', 'object', '[object Set]' ] } },
88+
{ stdout: 'true\ntrue\n',
89+
func_name: '',
90+
stack_to_render: [],
91+
globals:
92+
{ s: [ 'REF', 1 ],
93+
'key (block 1)': [ 'JS_SPECIAL_VAL', 'undefined' ] },
94+
ordered_globals: [ 's', 'key (block 1)' ],
95+
line: 9,
96+
col: 17,
97+
event: 'step_line',
98+
heap: { '1': [ 'INSTANCE_PPRINT', 'object', '[object Set]' ] } },
99+
{ stdout: 'true\ntrue\n',
100+
func_name: '',
101+
stack_to_render: [],
102+
globals:
103+
{ s: [ 'REF', 1 ],
104+
'key (block 1)': [ 'JS_SPECIAL_VAL', 'undefined' ],
105+
'key (block 2)': 'hello' },
106+
ordered_globals: [ 's', 'key (block 1)', 'key (block 2)' ],
107+
line: 10,
108+
col: 4,
109+
event: 'step_line',
110+
heap: { '1': [ 'INSTANCE_PPRINT', 'object', '[object Set]' ] } },
111+
{ stdout: 'true\ntrue\nhello\n',
112+
func_name: '',
113+
stack_to_render: [],
114+
globals:
115+
{ s: [ 'REF', 1 ],
116+
'key (block 1)': [ 'JS_SPECIAL_VAL', 'undefined' ] },
117+
ordered_globals: [ 's', 'key (block 1)' ],
118+
line: 9,
119+
col: 17,
120+
event: 'step_line',
121+
heap: { '1': [ 'INSTANCE_PPRINT', 'object', '[object Set]' ] } },
122+
{ stdout: 'true\ntrue\nhello\n',
123+
func_name: '',
124+
stack_to_render: [],
125+
globals:
126+
{ s: [ 'REF', 1 ],
127+
'key (block 1)': [ 'JS_SPECIAL_VAL', 'undefined' ],
128+
'key (block 2)': 'goodbye' },
129+
ordered_globals: [ 's', 'key (block 1)', 'key (block 2)' ],
130+
line: 10,
131+
col: 4,
132+
event: 'step_line',
133+
heap: { '1': [ 'INSTANCE_PPRINT', 'object', '[object Set]' ] } },
134+
{ stdout: 'true\ntrue\nhello\ngoodbye\n',
135+
func_name: '',
136+
stack_to_render: [],
137+
globals:
138+
{ s: [ 'REF', 1 ],
139+
'key (block 1)': [ 'JS_SPECIAL_VAL', 'undefined' ] },
140+
ordered_globals: [ 's', 'key (block 1)' ],
141+
line: 9,
142+
col: 17,
143+
event: 'step_line',
144+
heap: { '1': [ 'INSTANCE_PPRINT', 'object', '[object Set]' ] } },
145+
{ stdout: 'true\ntrue\nhello\ngoodbye\n',
146+
func_name: '',
147+
stack_to_render: [],
148+
globals: { s: [ 'REF', 1 ] },
149+
ordered_globals: [ 's' ],
150+
line: 10,
151+
col: 21,
152+
event: 'step_line',
153+
heap: { '1': [ 'INSTANCE_PPRINT', 'object', '[object Set]' ] } } ] }
Lines changed: 10 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,10 @@
1+
// adapted from http://es6-features.org/#SetDataStructure
2+
let s = new Set();
3+
s.add("hello").add("goodbye");
4+
s.add("hello");
5+
s.add("foo");
6+
s.delete("foo");
7+
console.log(s.size === 2);
8+
console.log(s.has("hello") === true);
9+
for (let key of s.values()) // insertion order
10+
console.log(key);

0 commit comments

Comments
 (0)