Skip to content
Open
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
58 changes: 29 additions & 29 deletions final/test/arrow-function/ArrowFunctionExpression.test.js
Original file line number Diff line number Diff line change
@@ -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(
`
Expand All @@ -14,34 +14,34 @@ 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(
`
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(
`
Expand All @@ -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')
})
22 changes: 10 additions & 12 deletions final/test/assignment.test.js
Original file line number Diff line number Diff line change
@@ -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,
)
})
})
104 changes: 30 additions & 74 deletions final/test/function/scope.test.js
Original file line number Diff line number Diff line change
@@ -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(
`
Expand All @@ -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(
`
Expand All @@ -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(
`
Expand All @@ -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(
`
Expand All @@ -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)
})
Loading