dry up classes
This commit is contained in:
@@ -1,51 +0,0 @@
|
||||
var transform = require("../lib/6to5/transform");
|
||||
var assert = require("assert");
|
||||
|
||||
suite("classes", function () {
|
||||
test("no calling super properties", function () {
|
||||
assert.throws(function () {
|
||||
transform.test([
|
||||
"class Test extends Foo {",
|
||||
" constructor() {",
|
||||
" super.test.whatever();",
|
||||
" }",
|
||||
"}"
|
||||
]);
|
||||
}, /cannot access super properties/);
|
||||
});
|
||||
|
||||
test("no accessing super properties", function () {
|
||||
assert.throws(function () {
|
||||
transform.test([
|
||||
"class Test extends Foo {",
|
||||
" constructor() {",
|
||||
" super.test.whatever;",
|
||||
" }",
|
||||
"}"
|
||||
]);
|
||||
}, /cannot access super properties/);
|
||||
});
|
||||
|
||||
test("accessing super without having one", function () {
|
||||
assert.throws(function () {
|
||||
transform.test([
|
||||
"class Test {",
|
||||
" constructor() {",
|
||||
" super();",
|
||||
" }",
|
||||
"}"
|
||||
]);
|
||||
}, /cannot access super as this class has none/);
|
||||
});
|
||||
|
||||
test("defining constructor as a mutator", function () {
|
||||
assert.throws(function () {
|
||||
transform.test([
|
||||
"class Test {",
|
||||
" get constructor() {",
|
||||
" }",
|
||||
"}"
|
||||
]);
|
||||
}, /unknown kind for constructor method/);
|
||||
});
|
||||
});
|
||||
@@ -1,14 +0,0 @@
|
||||
var transform = require("../lib/6to5/transform");
|
||||
var assert = require("assert");
|
||||
|
||||
suite("errors", function () {
|
||||
test("syntax", function () {
|
||||
assert.throws(function () {
|
||||
transform.test([
|
||||
"arr.map(function () {",
|
||||
" return $@!@#;",
|
||||
"});"
|
||||
]);
|
||||
}, /Error: test: Line 2: Unexpected token ILLEGAL/);
|
||||
});
|
||||
});
|
||||
@@ -1,5 +0,0 @@
|
||||
var arr = [
|
||||
1,
|
||||
2,
|
||||
3
|
||||
];
|
||||
7
test/fixtures/block-binding/program/expected.js
vendored
Normal file
7
test/fixtures/block-binding/program/expected.js
vendored
Normal file
@@ -0,0 +1,7 @@
|
||||
(function () {
|
||||
var arr = [
|
||||
1,
|
||||
2,
|
||||
3
|
||||
];
|
||||
})();
|
||||
5
test/fixtures/classes/accessing-super-without-having-one/actual.js
vendored
Normal file
5
test/fixtures/classes/accessing-super-without-having-one/actual.js
vendored
Normal file
@@ -0,0 +1,5 @@
|
||||
class Test {
|
||||
constructor() {
|
||||
super();
|
||||
}
|
||||
}
|
||||
3
test/fixtures/classes/accessing-super-without-having-one/options.json
vendored
Normal file
3
test/fixtures/classes/accessing-super-without-having-one/options.json
vendored
Normal file
@@ -0,0 +1,3 @@
|
||||
{
|
||||
"throws": "cannot access super as this class has none"
|
||||
}
|
||||
4
test/fixtures/classes/defining-constructor-as-a-mutator/actual.js
vendored
Normal file
4
test/fixtures/classes/defining-constructor-as-a-mutator/actual.js
vendored
Normal file
@@ -0,0 +1,4 @@
|
||||
class Test {
|
||||
get constructor() {
|
||||
}
|
||||
}
|
||||
3
test/fixtures/classes/defining-constructor-as-a-mutator/options.json
vendored
Normal file
3
test/fixtures/classes/defining-constructor-as-a-mutator/options.json
vendored
Normal file
@@ -0,0 +1,3 @@
|
||||
{
|
||||
"throws": "unknown kind for constructor method"
|
||||
}
|
||||
5
test/fixtures/classes/no-accessing-super-properties/actual.js
vendored
Normal file
5
test/fixtures/classes/no-accessing-super-properties/actual.js
vendored
Normal file
@@ -0,0 +1,5 @@
|
||||
class Test extends Foo {
|
||||
constructor() {
|
||||
super.test.whatever;
|
||||
}
|
||||
}
|
||||
3
test/fixtures/classes/no-accessing-super-properties/options.json
vendored
Normal file
3
test/fixtures/classes/no-accessing-super-properties/options.json
vendored
Normal file
@@ -0,0 +1,3 @@
|
||||
{
|
||||
"throws": "cannot access super properties"
|
||||
}
|
||||
5
test/fixtures/classes/no-calling-super-properties/actual.js
vendored
Normal file
5
test/fixtures/classes/no-calling-super-properties/actual.js
vendored
Normal file
@@ -0,0 +1,5 @@
|
||||
class Test extends Foo {
|
||||
constructor() {
|
||||
super.test.whatever();
|
||||
}
|
||||
}
|
||||
3
test/fixtures/classes/no-calling-super-properties/options.json
vendored
Normal file
3
test/fixtures/classes/no-calling-super-properties/options.json
vendored
Normal file
@@ -0,0 +1,3 @@
|
||||
{
|
||||
"throws": "cannot access super properties"
|
||||
}
|
||||
5
test/fixtures/computed-property-names/method/actual.js
vendored
Normal file
5
test/fixtures/computed-property-names/method/actual.js
vendored
Normal file
@@ -0,0 +1,5 @@
|
||||
var obj = {
|
||||
[foobar]() {
|
||||
return "foobar"
|
||||
}
|
||||
};
|
||||
6
test/fixtures/computed-property-names/method/expected.js
vendored
Normal file
6
test/fixtures/computed-property-names/method/expected.js
vendored
Normal file
@@ -0,0 +1,6 @@
|
||||
var obj = function (obj) {
|
||||
obj[foobar] = function () {
|
||||
return 'foobar';
|
||||
};
|
||||
return obj;
|
||||
}({});
|
||||
4
test/fixtures/constants/block-statement/actual.js
vendored
Normal file
4
test/fixtures/constants/block-statement/actual.js
vendored
Normal file
@@ -0,0 +1,4 @@
|
||||
for (let i in arr) {
|
||||
const MULTIPLIER = 5;
|
||||
console.log(arr[i] * MULTIPLIER);
|
||||
}
|
||||
8
test/fixtures/constants/block-statement/expected.js
vendored
Normal file
8
test/fixtures/constants/block-statement/expected.js
vendored
Normal file
@@ -0,0 +1,8 @@
|
||||
(function () {
|
||||
for (var i in arr) {
|
||||
(function () {
|
||||
var MULTIPLIER = 5;
|
||||
console.log(arr[i] * MULTIPLIER);
|
||||
}());
|
||||
}
|
||||
}());
|
||||
3
test/fixtures/constants/no-assignment/actual.js
vendored
Normal file
3
test/fixtures/constants/no-assignment/actual.js
vendored
Normal file
@@ -0,0 +1,3 @@
|
||||
const MULTIPLIER = 5;
|
||||
|
||||
MULTIPLIER = "overwrite";
|
||||
3
test/fixtures/constants/no-assignment/options.json
vendored
Normal file
3
test/fixtures/constants/no-assignment/options.json
vendored
Normal file
@@ -0,0 +1,3 @@
|
||||
{
|
||||
"throws": "MULTIPLIER is read-only"
|
||||
}
|
||||
3
test/fixtures/constants/no-declaration/actual.js
vendored
Normal file
3
test/fixtures/constants/no-declaration/actual.js
vendored
Normal file
@@ -0,0 +1,3 @@
|
||||
const MULTIPLIER = 5;
|
||||
|
||||
var MULTIPLIER = "overwrite";
|
||||
3
test/fixtures/constants/no-declaration/options.json
vendored
Normal file
3
test/fixtures/constants/no-declaration/options.json
vendored
Normal file
@@ -0,0 +1,3 @@
|
||||
{
|
||||
"throws": "MULTIPLIER is read-only"
|
||||
}
|
||||
5
test/fixtures/constants/program/actual.js
vendored
Normal file
5
test/fixtures/constants/program/actual.js
vendored
Normal file
@@ -0,0 +1,5 @@
|
||||
const MULTIPLIER = 5;
|
||||
|
||||
for (var i in arr) {
|
||||
console.log(arr[i] * MULTIPLIER);
|
||||
}
|
||||
6
test/fixtures/constants/program/expected.js
vendored
Normal file
6
test/fixtures/constants/program/expected.js
vendored
Normal file
@@ -0,0 +1,6 @@
|
||||
(function () {
|
||||
var MULTIPLIER = 5;
|
||||
for (var i in arr) {
|
||||
console.log(arr[i] * MULTIPLIER);
|
||||
}
|
||||
}());
|
||||
3
test/fixtures/errors/syntax/actual.js
vendored
Normal file
3
test/fixtures/errors/syntax/actual.js
vendored
Normal file
@@ -0,0 +1,3 @@
|
||||
arr.map(function () {
|
||||
return $@!@#;
|
||||
});
|
||||
3
test/fixtures/errors/syntax/options.json
vendored
Normal file
3
test/fixtures/errors/syntax/options.json
vendored
Normal file
@@ -0,0 +1,3 @@
|
||||
{
|
||||
"throws": "Line 2: Unexpected token ILLEGAL"
|
||||
}
|
||||
1
test/fixtures/spread/method-call-array-literal/actual.js
vendored
Normal file
1
test/fixtures/spread/method-call-array-literal/actual.js
vendored
Normal file
@@ -0,0 +1 @@
|
||||
f(...[1, 2, 3]);
|
||||
1
test/fixtures/spread/method-call-array-literal/expected.js
vendored
Normal file
1
test/fixtures/spread/method-call-array-literal/expected.js
vendored
Normal file
@@ -0,0 +1 @@
|
||||
f.apply(null, [1, 2, 3]);
|
||||
@@ -7,6 +7,14 @@ var humanise = function (val) {
|
||||
return val.replace(/-/g, " ");
|
||||
};
|
||||
|
||||
var readFile = function (filename) {
|
||||
if (fs.existsSync(filename)) {
|
||||
return fs.readFileSync(filename);
|
||||
} else {
|
||||
return "";
|
||||
}
|
||||
};
|
||||
|
||||
var fixturesDir = __dirname + "/fixtures";
|
||||
|
||||
_.each(fs.readdirSync(fixturesDir), function (suiteName) {
|
||||
@@ -24,14 +32,26 @@ _.each(fs.readdirSync(fixturesDir), function (suiteName) {
|
||||
test(humanise(taskName), function () {
|
||||
var actualLoc = taskDir + "/actual.js";
|
||||
|
||||
var actual = fs.readFileSync(actualLoc, "utf8");
|
||||
var expect = fs.readFileSync(taskDir + "/expected.js", "utf8");
|
||||
var actual = readFile(actualLoc);
|
||||
var expect = readFile(taskDir + "/expected.js");
|
||||
|
||||
var taskOptsLoc = taskDir + "/options.json";
|
||||
var taskOpts = _.merge({ filename: actualLoc }, _.cloneDeep(suiteOpts));
|
||||
if (fs.existsSync(taskOptsLoc)) _.merge(taskOpts, require(taskOptsLoc));
|
||||
|
||||
transform.test(actual, expect, taskOpts);
|
||||
var test = function () {
|
||||
transform.test(actual, expect, taskOpts);
|
||||
};
|
||||
|
||||
var throwMsg = taskOpts.throws;
|
||||
if (throwMsg) {
|
||||
// internal api doesn't have this option but it's best not to pollute
|
||||
// the options object with useless options
|
||||
delete taskOpts.throws;
|
||||
assert.throws(test, new RegExp(throwMsg));
|
||||
} else {
|
||||
test();
|
||||
}
|
||||
});
|
||||
});
|
||||
});
|
||||
|
||||
Reference in New Issue
Block a user