This repository has been archived by the owner on May 30, 2023. It is now read-only.
-
Notifications
You must be signed in to change notification settings - Fork 5.7k
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
Add some tests for ES2015 features (#15402)
- Loading branch information
Showing
7 changed files
with
92 additions
and
0 deletions.
There are no files selected for viewing
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
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"); |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
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"); |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
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"); |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
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"); |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
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"); |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
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"); |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
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"); |