Skip to content
This repository has been archived by the owner on May 30, 2023. It is now read-only.

Commit

Permalink
Add some tests for ES2015 features (#15402)
Browse files Browse the repository at this point in the history
  • Loading branch information
ariya committed Dec 31, 2019
1 parent da8e293 commit 2b666c9
Show file tree
Hide file tree
Showing 7 changed files with 92 additions and 0 deletions.
5 changes: 5 additions & 0 deletions test/standards/javascript/arrow.js
Original file line number Diff line number Diff line change
@@ -0,0 +1,5 @@
test(function () {
var result = [2, 3, 5].map(x => x * x);
assert_equals(result.length, 3);
assert_equals(result.join(' '), '4 9 25');
}, "ES2015 arrow function");
34 changes: 34 additions & 0 deletions test/standards/javascript/class.js
Original file line number Diff line number Diff line change
@@ -0,0 +1,34 @@
test(function () {
class Vehicle { };
assert_type_of(Vehicle, 'function');
}, "ES2015 class declaration");

test(function () {
class Vehicle { constructor(n) { this.name = n } };
var v = new Vehicle('daily driver');
assert_type_of(Vehicle, 'function');
assert_type_of(Vehicle.constructor, 'function');
assert_type_of(v, 'object')
}, "ES2015 class constructor");


test(function () {
class Vehicle {
constructor(n) { this._name = n }
get name() { return this._name }
}
var v = new Vehicle('daily driver');
assert_type_of(v.name, 'string')
assert_equals(v.name, 'daily driver');
}, "ES2015 class getter");

test(function () {
class Vehicle {
get name() { return this._name }
set name(n) { this._name = n }
}
var v = new Vehicle();
v.name = 'daily driver';
assert_type_of(v.name, 'string')
assert_equals(v.name, 'daily driver');
}, "ES2015 class setter");
5 changes: 5 additions & 0 deletions test/standards/javascript/default.js
Original file line number Diff line number Diff line change
@@ -0,0 +1,5 @@
test(function () {
function inc(x, step = 1) { return x + step }
assert_equals(inc(4), 5);
assert_equals(inc(4, 3), 7);
}, "ES2015 default parameter value");
24 changes: 24 additions & 0 deletions test/standards/javascript/destructuring.js
Original file line number Diff line number Diff line change
@@ -0,0 +1,24 @@
test(function () {
var o = { d: 14, m: 3 };
var { d: foo, m: bar } = o;
assert_type_of(foo, 'number');
assert_type_of(bar, 'number');
assert_equals(foo, 14);
assert_equals(bar, 3);
}, "ES2015 object destructuring");

test(function () {
var d, m;
[d, m] = [14, 3];
assert_type_of(d, 'number');
assert_type_of(m, 'number');
assert_equals(d, 14);
assert_equals(m, 3);
}, "ES2015 array destructuring");

test(function () {
var x = 14, y = 3;
[x, y] = [y, x];
assert_equals(x, 3);
assert_equals(y, 14);
}, "ES2015 variable swap");
8 changes: 8 additions & 0 deletions test/standards/javascript/isarray.js
Original file line number Diff line number Diff line change
@@ -0,0 +1,8 @@
test(function () {
assert_type_of(Array.isArray, 'function');
assert_is_true(Array.isArray([]));
assert_is_true(Array.isArray([1]));
assert_is_true(Array.isArray([1, 2]));
assert_is_false(Array.isArray({}));
assert_is_false(Array.isArray(null));
}, "ES2015 Array.isArray");
8 changes: 8 additions & 0 deletions test/standards/javascript/let.js
Original file line number Diff line number Diff line change
@@ -0,0 +1,8 @@
test(function () {
let x = 4;
if (true) {
let x = 7;
assert_equals(x, 7);
}
assert_equals(x, 4);
}, "ES2015 block-scope let");
8 changes: 8 additions & 0 deletions test/standards/javascript/shorthand.js
Original file line number Diff line number Diff line change
@@ -0,0 +1,8 @@
test(function () {
var x = 14, y = 3;
var obj = { x, y };
assert_type_of(obj.x, 'number');
assert_type_of(obj.y, 'number');
assert_equals(obj.x, 14);
assert_equals(obj.y, 3);
}, "ES2015 object literal property shorthand");

0 comments on commit 2b666c9

Please sign in to comment.