Skip to content
This repository has been archived by the owner on Aug 18, 2021. It is now read-only.

Commit

Permalink
Always use unpad (#535)
Browse files Browse the repository at this point in the history
  • Loading branch information
hzoo committed Nov 6, 2017
1 parent 295091d commit fa56d21
Showing 1 changed file with 118 additions and 149 deletions.
267 changes: 118 additions & 149 deletions test/babel-eslint.js
Expand Up @@ -61,6 +61,7 @@ function lookup(obj, keypath, backwardsDepth) {
}

function parseAndAssertSame(code) {
code = unpad(code);
var esAST = espree.parse(code, {
ecmaFeatures: {
// enable JSX parsing
Expand Down Expand Up @@ -177,30 +178,26 @@ describe("babylon-to-esprima", () => {
});

it("template also with braces #96", () => {
parseAndAssertSame(
unpad(`
export default function f1() {
function f2(foo) {
const bar = 3;
return \`\${foo} \${bar}\`;
}
return f2;
parseAndAssertSame(`
export default function f1() {
function f2(foo) {
const bar = 3;
return \`\${foo} \${bar}\`;
}
`)
);
return f2;
}
`);
});

it("template with destructuring #31", () => {
parseAndAssertSame(
unpad(`
module.exports = {
render() {
var {name} = this.props;
return Math.max(null, \`Name: \${name}, Name: \${name}\`);
}
};
`)
);
parseAndAssertSame(`
module.exports = {
render() {
var {name} = this.props;
return Math.max(null, \`Name: \${name}, Name: \${name}\`);
}
};
`);
});
});

Expand Down Expand Up @@ -301,40 +298,34 @@ describe("babylon-to-esprima", () => {
});

it("line comments", () => {
parseAndAssertSame(
unpad(`
// single comment
var foo = 15; // comment next to statement
// second comment after statement
`)
);
parseAndAssertSame(`
// single comment
var foo = 15; // comment next to statement
// second comment after statement
`);
});

it("block comments", () => {
parseAndAssertSame(
unpad(`
/* single comment */
var foo = 15; /* comment next to statement */
/*
* multiline
* comment
*/
`)
);
parseAndAssertSame(`
/* single comment */
var foo = 15; /* comment next to statement */
/*
* multiline
* comment
*/
`);
});

it("block comments #124", () => {
parseAndAssertSame(
unpad(`
React.createClass({
render() {
// return (
// <div />
// ); // <-- this is the line that is reported
}
});
`)
);
parseAndAssertSame(`
React.createClass({
render() {
// return (
// <div />
// ); // <-- this is the line that is reported
}
});
`);
});

it("null", () => {
Expand Down Expand Up @@ -374,43 +365,37 @@ describe("babylon-to-esprima", () => {
});

it("jsdoc", () => {
parseAndAssertSame(
unpad(`
/**
* @param {object} options
* @return {number}
*/
const test = function({ a, b, c }) {
return a + b + c;
};
module.exports = test;
`)
);
parseAndAssertSame(`
/**
* @param {object} options
* @return {number}
*/
const test = function({ a, b, c }) {
return a + b + c;
};
module.exports = test;
`);
});

it("empty block with comment", () => {
parseAndAssertSame(
unpad(`
function a () {
try {
b();
} catch (e) {
// asdf
}
parseAndAssertSame(`
function a () {
try {
b();
} catch (e) {
// asdf
}
`)
);
}
`);
});

describe("babel tests", () => {
it("MethodDefinition", () => {
parseAndAssertSame(
unpad(`
export default class A {
a() {}
}
`)
);
parseAndAssertSame(`
export default class A {
a() {}
}
`);
});

it("MethodDefinition 2", () => {
Expand All @@ -420,58 +405,50 @@ describe("babylon-to-esprima", () => {
});

it("ClassMethod", () => {
parseAndAssertSame(
unpad(`
class A {
constructor() {
}
parseAndAssertSame(`
class A {
constructor() {
}
`)
);
}
`);
});

it("ClassMethod multiple params", () => {
parseAndAssertSame(
unpad(`
class A {
constructor(a, b, c) {
}
parseAndAssertSame(`
class A {
constructor(a, b, c) {
}
`)
);
}
`);
});

it("ClassMethod multiline", () => {
parseAndAssertSame(
unpad(`
class A {
constructor (
a,
b,
c
)
parseAndAssertSame(`
class A {
constructor (
a,
b,
c
)
{
{
}
}
`)
);
}
`);
});

it("ClassMethod oneline", () => {
parseAndAssertSame("class A { constructor(a, b, c) {} }");
});

it("ObjectMethod", () => {
parseAndAssertSame(
unpad(`
var a = {
b(c) {
}
parseAndAssertSame(`
var a = {
b(c) {
}
`)
);
}
`);
});

it("do not allow import export everywhere", () => {
Expand All @@ -496,41 +473,35 @@ describe("babylon-to-esprima", () => {

it("getters and setters", () => {
parseAndAssertSame("class A { get x ( ) { ; } }");
parseAndAssertSame(
unpad(`
class A {
get x(
)
{
;
}
parseAndAssertSame(`
class A {
get x(
)
{
;
}
`)
);
}
`);
parseAndAssertSame("class A { set x (a) { ; } }");
parseAndAssertSame(
unpad(`
class A {
set x(a
)
{
;
}
parseAndAssertSame(`
class A {
set x(a
)
{
;
}
`)
);
parseAndAssertSame(
unpad(`
var B = {
get x () {
return this.ecks;
},
set x (ecks) {
this.ecks = ecks;
}
};
`)
);
}
`);
parseAndAssertSame(`
var B = {
get x () {
return this.ecks;
},
set x (ecks) {
this.ecks = ecks;
}
};
`);
});

it("RestOperator", () => {
Expand All @@ -546,13 +517,11 @@ describe("babylon-to-esprima", () => {
});

it("Async/Await", () => {
parseAndAssertSame(
unpad(`
async function a() {
await 1;
}
`)
);
parseAndAssertSame(`
async function a() {
await 1;
}
`);
});
});
});

0 comments on commit fa56d21

Please sign in to comment.