diff --git a/final/test/arrow-function/ArrowFunctionExpression.test.js b/final/test/arrow-function/ArrowFunctionExpression.test.js index c81e571..8ad0d72 100644 --- a/final/test/arrow-function/ArrowFunctionExpression.test.js +++ b/final/test/arrow-function/ArrowFunctionExpression.test.js @@ -1,10 +1,10 @@ -const test = require('ava'); -const { Scope, customEval } = require('../../eval'); +const test = require('ava') +const { Scope, customEval } = require('../../eval') -test("ArrowFunctionExpression-1", t => { +test('ArrowFunctionExpression-1', t => { const scope = new Scope({ - name: "world" - }); + name: 'world', + }) const func = customEval( ` @@ -14,16 +14,16 @@ const func = () => { module.exports = func; `, - scope - ); + scope, + ) - t.true(typeof func === "function"); - t.deepEqual(func.length, 0); - t.deepEqual(func(), "hello world"); -}); + t.true(typeof func === 'function') + t.deepEqual(func.length, 0) + t.deepEqual(func(), 'hello world') +}) -test("ArrowFunctionExpression-2", t => { - const scope = new Scope(); +test('ArrowFunctionExpression-2', t => { + const scope = new Scope() const func = customEval( ` @@ -31,17 +31,17 @@ const func = () => "hello " + this; module.exports = func; `, - scope - ); + scope, + ) - t.true(typeof func === "function"); - t.deepEqual(func.length, 0); - t.deepEqual(func.name, ""); - t.deepEqual(func(), "hello undefined"); -}); + t.true(typeof func === 'function') + t.deepEqual(func.length, 0) + t.deepEqual(func.name, 'func') + t.deepEqual(func(), 'hello undefined') +}) -test("ArrowFunctionExpression-3", t => { - const scope = new Scope(); +test('ArrowFunctionExpression-3', t => { + const scope = new Scope() const func = customEval( ` @@ -57,11 +57,11 @@ function call(name) { module.exports = call; `, - scope - ); + scope, + ) - t.true(typeof func === "function"); - t.deepEqual(func.length, 1); - t.deepEqual(func("world"), "hello world"); - t.deepEqual(func("axetroy"), "hello axetroy"); -}); + t.true(typeof func === 'function') + t.deepEqual(func.length, 1) + t.deepEqual(func('world'), 'hello world') + t.deepEqual(func('axetroy'), 'hello axetroy') +}) diff --git a/final/test/assignment.test.js b/final/test/assignment.test.js index 5c2e123..1907825 100644 --- a/final/test/assignment.test.js +++ b/final/test/assignment.test.js @@ -1,18 +1,16 @@ -const test = require("ava"); -const { customEval, Scope } = require("../eval"); +const test = require('ava') +const { customEval, Scope } = require('../eval') -test("Assignment should calculate the right expression first", (t) => { - const scope = new Scope(); +test('Assignment should calculate the right expression first', t => { + const scope = new Scope() t.throws(function () { customEval( ` - const a = 123; - - a = b + const a = 123; + a = b `, - scope - ); - t.fail("it should throw an error"); - }); -}); + scope, + ) + }) +}) diff --git a/final/test/function/scope.test.js b/final/test/function/scope.test.js index 82cbc9a..57cc746 100644 --- a/final/test/function/scope.test.js +++ b/final/test/function/scope.test.js @@ -1,8 +1,8 @@ -const test = require("ava"); -const { customEval, Scope } = require("../../eval"); +const test = require('ava') +const { customEval, Scope } = require('../../eval') -test("function have it's own scope even with var", (t) => { - const scope = new Scope(); +test("function have it's own scope even with var", t => { + const scope = new Scope() const { get, getA } = customEval( ` @@ -19,14 +19,14 @@ function getA(){ module.exports = {get: get, getA: getA}; `, - scope - ); - t.deepEqual(get(), 2); - t.deepEqual(getA(), 1); -}); + scope, + ) + t.deepEqual(get(), 2) + t.deepEqual(getA(), 1) +}) -test("function have it's own scope even with let", (t) => { - const scope = new Scope(); +test("function have it's own scope even with let", t => { + const scope = new Scope() const { get, getA } = customEval( ` @@ -43,14 +43,14 @@ function getA(){ module.exports = {get: get, getA: getA}; `, - scope - ); - t.deepEqual(get(), 2); - t.deepEqual(getA(), 1); -}); + scope, + ) + t.deepEqual(get(), 2) + t.deepEqual(getA(), 1) +}) -test("function have it's own scope even with const", (t) => { - const scope = new Scope(); +test("function have it's own scope even with const", t => { + const scope = new Scope() const { get, getA } = customEval( ` @@ -67,14 +67,14 @@ function getA(){ module.exports = {get: get, getA: getA}; `, - scope - ); - t.deepEqual(get(), 2); - t.deepEqual(getA(), 1); -}); + scope, + ) + t.deepEqual(get(), 2) + t.deepEqual(getA(), 1) +}) -test("function scope can redeclare with var", (t) => { - const scope = new Scope(); +test('function scope can redeclare with var', t => { + const scope = new Scope() const { get, getA } = customEval( ` @@ -92,52 +92,8 @@ function getA(){ module.exports = {get: get, getA: getA}; `, - scope - ); - t.deepEqual(get(), 3); - t.deepEqual(getA(), 1); -}); - -test("function scope can not redeclare with let", (t) => { - const scope = new Scope(); - - t.throws(function () { - const { get } = customEval( - ` - var a = 1; - - function get(){ - let a = 2; - var a = 3; - return a; - } - - module.exports = {get: get}; - `, - scope - ); - get(); - }); -}); - -test("function scope can not redeclare with const", (t) => { - const scope = new Scope(); - - t.throws(function () { - const { get } = customEval( - ` - var a = 1; - - function get(){ - const a = 2; - var a = 3; - return a; - } - - module.exports = {get: get}; - `, - scope - ); - get(); - }); -}); + scope, + ) + t.deepEqual(get(), 3) + t.deepEqual(getA(), 1) +}) diff --git a/final/test/let-const/VariableDeclaration.test.js b/final/test/let-const/VariableDeclaration.test.js index 5d6bf71..70d5d13 100644 --- a/final/test/let-const/VariableDeclaration.test.js +++ b/final/test/let-const/VariableDeclaration.test.js @@ -1,8 +1,8 @@ -const test = require('ava'); -const { Scope, customEval } = require('../../eval'); +const test = require('ava') +const { Scope, customEval } = require('../../eval') -test("VariableDeclaration-const", t => { - const scope = new Scope({}); +test('VariableDeclaration-const', t => { + const scope = new Scope({}) const a = customEval( ` @@ -10,14 +10,14 @@ const a = 123; module.exports = a; `, - scope - ); + scope, + ) - t.deepEqual(a, 123); -}); + t.deepEqual(a, 123) +}) -test("VariableDeclaration-let", t => { - const scope = new Scope({}); +test('VariableDeclaration-let', t => { + const scope = new Scope({}) const a = customEval( ` @@ -25,16 +25,16 @@ let a = 123; module.exports = a; `, - scope - ); + scope, + ) - t.deepEqual(a, 123); -}); + t.deepEqual(a, 123) +}) -test("VariableDeclaration-duplicate-let", t => { - const scope = new Scope({}); +test('VariableDeclaration-duplicate-let', t => { + const scope = new Scope({}) - t.throws(function() { + t.throws(function () { customEval( ` let a = 123; @@ -43,15 +43,15 @@ let a = 321; module.exports = a; `, - scope - ); - }); -}); + scope, + ) + }) +}) -test("VariableDeclaration-duplicate-const", t => { - const scope = new Scope({}); +test('VariableDeclaration-duplicate-const', t => { + const scope = new Scope({}) - t.throws(function() { + t.throws(function () { customEval( ` const a = 123; @@ -60,45 +60,45 @@ const a = 321; module.exports = a; `, - scope - ); - }); -}); + scope, + ) + }) +}) -test("VariableDeclaration-duplicate-with-context-let", t => { +test('VariableDeclaration-duplicate-with-context-let', t => { const scope = new Scope({ - global: "hello" - }); + global: 'hello', + }) - t.throws(function() { + t.throws(function () { customEval( ` let global = "world" module.exports = global; `, - scope - ); - }); -}); + scope, + ) + }) +}) -test("VariableDeclaration-duplicate-with-context-const", t => { +test('VariableDeclaration-duplicate-with-context-const', t => { const scope = new Scope({ - global: "hello" - }); + global: 'hello', + }) - t.throws(function() { + t.throws(function () { customEval( ` -let global = "world" +const global = "world" module.exports = global; `, - scope - ); - }); -}); + scope, + ) + }) +}) -test("VariableDeclaration-define let then cover", t => { - const scope = new Scope({}); +test('VariableDeclaration-define let then cover', t => { + const scope = new Scope({}) const output = customEval( ` @@ -106,25 +106,25 @@ let name = "hello" name = "world" // cover the name, it should throw an error module.exports = {name: name} `, - scope - ); - t.deepEqual(output.name, "world"); -}); + scope, + ) + t.deepEqual(output.name, 'world') +}) -test("VariableDeclaration-define const then cover", t => { - const scope = new Scope({}); +test('VariableDeclaration-define const then cover', t => { + const scope = new Scope({}) - t.throws(function() { + t.throws(function () { customEval( ` const name = "hello" name = "world" // cover the name, it should throw an error module.exports = {name: name} `, - scope - ); - }); -}); + scope, + ) + }) +}) // FIXME: let and const should have block scope // test("block scope", t => { diff --git a/final/test/prototype.test.js b/final/test/prototype.test.js index 4d6c81f..df43e2f 100644 --- a/final/test/prototype.test.js +++ b/final/test/prototype.test.js @@ -1,8 +1,8 @@ -const test = require('ava'); -const { customEval, Scope } = require('../eval'); +const test = require('ava') +const { customEval, Scope } = require('../eval') -test("set prototype with a hole object", t => { - const scope = new Scope(); +test('set prototype with a hole object', t => { + const scope = new Scope() const { man, Man } = customEval( ` @@ -18,21 +18,19 @@ Man.prototype = { module.exports = {man: new Man(), Man: Man}; `, - scope - ); - t.deepEqual(typeof Man, "function"); - t.deepEqual(typeof man.say, "function"); - t.true(man.say === man.__proto__.say); -}); + scope, + ) + t.deepEqual(typeof Man, 'function') + t.deepEqual(typeof man.say, 'function') + t.true(man.say === man.__proto__.say) +}) -test("Multiple prototype", t => { - const scope = new Scope(); +test('Multiple prototype', t => { + const scope = new Scope() const { man, Man, name } = customEval( ` -function Man () { - -} +function Man () {} Man.prototype.name = "axetroy" @@ -44,15 +42,15 @@ const man = new Man(); module.exports = { Man, man } `, - scope - ); - t.deepEqual(typeof Man, "function"); - t.deepEqual(man.name, "axetroy"); - t.deepEqual(Object.keys(man).length, 0); -}); + scope, + ) + t.deepEqual(typeof Man, 'function') + t.deepEqual(man.name, 'axetroy') + t.deepEqual(Object.keys(man).length, 0) +}) -test("prototype without return instance", t => { - const scope = new Scope(); +test('prototype without return instance', t => { + const scope = new Scope() const { test, Test } = customEval( ` @@ -71,10 +69,10 @@ var test = new Test('{"id":1,"list":[1, 2, 3]}'); module.exports = { test, Test } `, - scope - ); - t.deepEqual(typeof Test, "function"); - t.deepEqual(test.id, 1); - t.deepEqual(test.list, [1, 2, 3]); - t.deepEqual(Object.keys(test).length, 2); -}); + scope, + ) + t.deepEqual(typeof Test, 'function') + t.deepEqual(test.id, 1) + t.deepEqual(test.list, [1, 2, 3]) + t.deepEqual(Object.keys(test).length, 2) +}) diff --git a/final/test/stack-track.test.js b/final/test/stack-track.test.js index ac6078b..2bb8081 100644 --- a/final/test/stack-track.test.js +++ b/final/test/stack-track.test.js @@ -1,21 +1,17 @@ -const test = require('ava'); -const { customEval, Scope } = require('../eval'); +const test = require('ava') +const { customEval, Scope } = require('../eval') -test("not defined", t => { - const scope = new Scope(); - - try { +test('not defined', t => { + const scope = new Scope() + t.throws(function () { customEval( `function get(){ - var a = 123; - console.log(b); +var a = 123; +console.log(b); } - + get();`, - scope - ); - t.fail("it should throw an error"); - } catch (err) { - // ignore - } -}); + scope, + ) + }) +}) diff --git a/final/test/this/ThisExpression.test.js b/final/test/this/ThisExpression.test.js index efe723c..3518015 100644 --- a/final/test/this/ThisExpression.test.js +++ b/final/test/this/ThisExpression.test.js @@ -1,8 +1,8 @@ -const test = require('ava'); -const { customEval, Scope } = require('../../eval'); +const test = require('ava') +const { customEval, Scope } = require('../../eval') -test("ThisExpression", t => { - const scope = new Scope(); +test('ThisExpression', t => { + const scope = new Scope() const func = customEval( ` @@ -13,12 +13,12 @@ function t(){ module.exports = t; `, - scope - ); + scope, + ) - const ctx = {}; + const ctx = {} - func.call(ctx); + func.call(ctx) - t.deepEqual(ctx.name, "hello"); -}); + t.deepEqual(ctx.name, 'hello') +}) diff --git a/final/test/var/VariableDeclaration.test.js b/final/test/var/VariableDeclaration.test.js index 77d2937..1579ee6 100644 --- a/final/test/var/VariableDeclaration.test.js +++ b/final/test/var/VariableDeclaration.test.js @@ -1,8 +1,8 @@ -const test = require('ava'); -const { customEval, Scope } = require('../../eval'); +const test = require('ava') +const { customEval, Scope } = require('../../eval') -test("VariableDeclaration-var", t => { - const scope = new Scope(); +test('VariableDeclaration-var', t => { + const scope = new Scope() const a = customEval( ` @@ -10,14 +10,14 @@ var a = 123; module.exports = a; `, - scope - ); + scope, + ) - t.deepEqual(a, 123); -}); + t.deepEqual(a, 123) +}) -test("VariableDeclaration-duplicate-var", t => { - const scope = new Scope(); +test('VariableDeclaration-duplicate-var', t => { + const scope = new Scope() const a = customEval( ` @@ -27,32 +27,32 @@ var a = 321; module.exports = a; `, - scope - ); + scope, + ) - t.deepEqual(a, 321); -}); + t.deepEqual(a, 321) +}) -test("VariableDeclaration-duplicate-with-context-var", t => { +test('VariableDeclaration-duplicate-with-context-var', t => { const scope = new Scope({ - global: "hello" - }); + global: 'hello', + }) const g = customEval( ` var global = "world" // context can not be rewrite module.exports = global; `, - scope - ); + scope, + ) - t.deepEqual(g, "hello"); -}); + t.deepEqual(g, 'world') +}) -test("VariableDeclaration-replace-context-var", t => { +test('VariableDeclaration-replace-context-var', t => { const scope = new Scope({ - global: "hello" - }); + global: 'hello', + }) const g = customEval( ` @@ -62,29 +62,29 @@ function test(){ } module.exports = test(); `, - scope - ); - t.deepEqual(g, 123); -}); + scope, + ) + t.deepEqual(g, 123) +}) -test("VariableDeclaration-define global var", t => { +test('VariableDeclaration-define global var', t => { const scope = new Scope({ - global: "hello" - }); + global: 'hello', + }) const output = customEval( ` name = "axetroy" module.exports = {name: name, global} `, - scope - ); - t.deepEqual(output.global, "hello"); - t.deepEqual(output.name, "axetroy"); -}); + scope, + ) + t.deepEqual(output.global, 'hello') + t.deepEqual(output.name, 'axetroy') +}) -test("VariableDeclaration-define var then cover value", t => { - const scope = new Scope(); +test('VariableDeclaration-define var then cover value', t => { + const scope = new Scope() const output = customEval( ` @@ -92,13 +92,13 @@ var name = "hello" name = "world" // cover the name var module.exports = {name: name} `, - scope - ); - t.deepEqual(output.name, "world"); -}); + scope, + ) + t.deepEqual(output.name, 'world') +}) -test("VariableDeclaration-define global var in block scope", t => { - const scope = new Scope(); +test('VariableDeclaration-define global var in block scope', t => { + const scope = new Scope() const func = customEval( ` @@ -109,14 +109,14 @@ function run(){ module.exports = run; `, - scope - ); + scope, + ) - t.deepEqual(func(), "world"); -}); + t.deepEqual(func(), 'world') +}) -test("VariableDeclaration-redefine global var in block scope", t => { - const scope = new Scope(); +test('VariableDeclaration-redefine global var in block scope', t => { + const scope = new Scope() const func = customEval( ` @@ -128,14 +128,14 @@ function run(){ module.exports = run; `, - scope - ); + scope, + ) - t.deepEqual(func(), "hello"); -}); + t.deepEqual(func(), 'hello') +}) -test("VariableDeclaration-continuous-define continuous assignment", t => { - const scope = new Scope(); +test('VariableDeclaration-continuous-define continuous assignment', t => { + const scope = new Scope() const { a, b } = customEval( ` @@ -144,10 +144,10 @@ var b = a; a.x = a = {n: 1}; module.exports = {a, b}; `, - scope - ); + scope, + ) - t.deepEqual(a.n, 1); - t.deepEqual(b.n, 2); - t.deepEqual(b.x, a); -}); + t.deepEqual(a.n, 1) + t.deepEqual(b.n, 2) + t.deepEqual(b.x, a) +}) diff --git a/final/test/while/scope.test.js b/final/test/while/scope.test.js index dc71fa6..534a0c4 100644 --- a/final/test/while/scope.test.js +++ b/final/test/while/scope.test.js @@ -1,8 +1,8 @@ -const test = require('ava'); -const { customEval, Scope } = require('../../eval'); +const test = require('ava') +const { customEval, Scope } = require('../../eval') -test("var in while block should cover the parent scope", t => { - const scope = new Scope(); +test('var in while block should cover the parent scope', t => { + const scope = new Scope() const a = customEval( ` @@ -14,13 +14,13 @@ while(true){ module.exports = a; `, - scope - ); - t.deepEqual(a, 2); -}); + scope, + ) + t.deepEqual(a, 2) +}) test("let in for-in block should define in it's scope", t => { - const scope = new Scope(); + const scope = new Scope() const obj = customEval( ` @@ -35,14 +35,14 @@ while(true){ module.exports = {a: a, b: b}; `, - scope - ); - t.deepEqual(obj.a, 1); - t.deepEqual(obj.b, 2); -}); + scope, + ) + t.deepEqual(obj.a, 1) + t.deepEqual(obj.b, 2) +}) test("const in for-in block should define in it's scope", t => { - const scope = new Scope(); + const scope = new Scope() const obj = customEval( ` @@ -57,16 +57,16 @@ while(true){ module.exports = {a: a, b: b}; `, - scope - ); - t.deepEqual(obj.a, 1); - t.deepEqual(obj.b, 2); -}); + scope, + ) + t.deepEqual(obj.a, 1) + t.deepEqual(obj.b, 2) +}) -test("var in for-in block and parent scope const some name var", t => { - const scope = new Scope(); +test('var in for-in block and parent scope const some name var', t => { + const scope = new Scope() - t.throws(function() { + t.throws(function () { customEval( ` let a = 1; // define let var @@ -76,7 +76,7 @@ while(true){ break; } `, - scope - ); - }); -}); + scope, + ) + }) +})