Skip to content

Commit

Permalink
Tests WIP 1
Browse files Browse the repository at this point in the history
  • Loading branch information
overlookmotel committed Nov 16, 2023
1 parent f48daa4 commit 93fa12d
Showing 1 changed file with 222 additions and 0 deletions.
222 changes: 222 additions & 0 deletions test/eval.test.js
Original file line number Diff line number Diff line change
Expand Up @@ -175,6 +175,228 @@ describe('eval', () => {
}
});
});

describe('`super`', () => {
describe('in object literal method', () => {
describe('with no prefix num change', () => {
itSerializesEqual('at top level of eval', {
in() {
const obj = {
meth() {
return eval('super.meth()');
},
__proto__: {
meth() { return 123; }
}
};
return obj.meth();
},
out: '123'
});

itSerializesEqual('within arrow function', {
in() {
const obj = {
meth() {
return eval('() => super.meth()');
},
__proto__: {
meth() { return 123; }
}
};
return obj.meth()();
},
out: '123'
});
});

describe('with prefix num change', () => {
itSerializesEqual('at top level of eval', {
in() {
const obj = {
meth() {
return eval('let livepack_tracker; super.meth()');
},
__proto__: {
meth() { return 123; }
}
};
return obj.meth();
},
out: '123'
});

itSerializesEqual('within arrow function', {
in() {
const obj = {
meth() {
return eval('let livepack_tracker; () => super.meth()');
},
__proto__: {
meth() { return 123; }
}
};
return obj.meth()();
},
out: '123'
});
});
});

describe('in class method', () => {
/* eslint-disable class-methods-use-this */
describe('with no prefix num change', () => {
itSerializesEqual('at top level of eval', {
in() {
class S {
meth() { return 123; }
}
class C extends S {
meth() {
return eval('super.meth()');
}
}
const obj = new C();
return obj.meth();
},
out: '123'
});

itSerializesEqual('within arrow function', {
in() {
class S {
meth() { return 123; }
}
class C extends S {
meth() {
return eval('() => super.meth()');
}
}
const obj = new C();
return obj.meth()();
},
out: '123'
});
});

describe('with prefix num change', () => {
itSerializesEqual('at top level of eval', {
in() {
class S {
meth() { return 123; }
}
class C extends S {
meth() {
return eval('let livepack_tracker; super.meth()');
}
}
const obj = new C();
return obj.meth();
},
out: '123'
});

itSerializesEqual('within arrow function', {
in() {
class S {
meth() { return 123; }
}
class C extends S {
meth() {
return eval('let livepack_tracker; () => super.meth()');
}
}
const obj = new C();
return obj.meth()();
},
out: '123'
});
});
/* eslint-enable class-methods-use-this */
});

describe('in class constructor', () => {
/* eslint-disable class-methods-use-this, constructor-super, no-this-before-super */
describe('with no prefix num change', () => {
itSerializesEqual('at top level of eval', {
in() {
class S {
constructor() { this.x = 456; }
meth() { return 123; }
}
class C extends S {
constructor() {
eval('super()');
eval('this.n = super.meth();');
}
}
const obj = new C();
return [obj.n, obj.x];
},
out: '[123,456]'
});

itSerializesEqual('within arrow function', {
in() {
class S {
constructor() { this.x = 456; }
meth() { return 123; }
}
class C extends S {
constructor() {
const callSuper = eval('() => super()');
callSuper();
this.f = eval('() => super.meth()');
}
}
const obj = new C();
return [obj.f(), obj.x];
},
out: '[123,456]'
});
});

describe('with prefix num change', () => {
itSerializesEqual('at top level of eval', {
in() {
class S {
constructor() { this.x = 456; }
meth() { return 123; }
}
class C extends S {
constructor() {
eval('let livepack_tracker; super()');
eval('let livepack1_tracker; this.n = super.meth()');
}
}
const obj = new C();
return [obj.n, obj.x];
},
out: '[123,456]'
});

itSerializesEqual('within arrow function', {
in() {
class S {
constructor() { this.x = 456; }
meth() { return 123; }
}
class C extends S {
constructor() {
const callSuper = eval('let livepack_tracker; () => super()');
callSuper();
this.f = eval('let livepack1_tracker; () => super.meth()');
}
}
const obj = new C();
return [obj.f(), obj.x];
},
out: '[123,456]'
});
});
/* eslint-enable class-methods-use-this, constructor-super, no-this-before-super */
});
});
});

describe('functions', () => {
Expand Down

0 comments on commit 93fa12d

Please sign in to comment.