Skip to content

Commit

Permalink
add test cases
Browse files Browse the repository at this point in the history
  • Loading branch information
JLHwung committed May 9, 2024
1 parent ae098b6 commit 7102208
Show file tree
Hide file tree
Showing 3 changed files with 126 additions and 0 deletions.
Expand Up @@ -15,6 +15,24 @@
expect(receivedNewTarget).toBe(B);
}

{
let receivedNewTarget;
function decFactory(target) {
receivedNewTarget = target;
return x => x;
}
function B() {
@decFactory(new.target)
class C {
#p;
}
}

new B();

expect(receivedNewTarget).toBe(B);
}

{
function noop() {}
let receivedNewTarget;
Expand Down Expand Up @@ -52,3 +70,17 @@

expect(receivedNewTarget).toBe(B);
}

{
let C;
const newC = class {};
function B () {
C = @(new.target)
class {
#p;
}
}

Reflect.construct(B, [], function () { return newC })
expect(C).toBe(newC);
}
Expand Up @@ -16,6 +16,25 @@
expect(receivedName).toBe("B");
}

{
let receivedName;
function decFactory(name) {
receivedName = name;
return x => x;
}
class B {
static m() {
@decFactory(this.name)
class C {
#p;
}
}
}

B.m();
expect(receivedName).toBe("B");
}

{
let receivedLength;
function decFactory(length) {
Expand Down Expand Up @@ -59,3 +78,18 @@
B.m();
expect(receivedLength).toBe(2);
}

{
let C;
const newC = class {};
const B = () => newC;
B.m = function () {
C = @(this)
class {
#p;
}
}

B.m();
expect(C).toBe(newC);
}
Expand Up @@ -100,3 +100,63 @@ const noop = () => {};
expect([...log].join()).toBe("0,1,2,3,4,5,6,7,8,9,10,11");
expect(Foo).toHaveProperty("accessor");
}

{
const id = function* (x) {
yield x;
}
const log = {
*[Symbol.iterator]() {
@(yield 0, noop)
@(yield 1, noop)
class Foo {
method() {}
static method() {}
field;
static field;
get getter() {
return;
}
static get getter() {
return;
}
set setter(x) {}
static set setter(x) {}
accessor accessor;
static accessor accessor;
}
},
};
expect([...log].join()).toBe("0,1");
}

{
let C;
const iter = (function* iterFactory() {
C =
@(yield)
@(yield)
class C {
method() {}
static method() {}
field;
static field;
get getter() {
return;
}
static get getter() {
return;
}
set setter(x) {}
static set setter(x) {}
accessor accessor;
static accessor accessor;
};
})();
const C1 = class {},
C2 = class {};
iter.next();
iter.next(() => C1);
iter.next(() => C2);
expect(C).toBe(C1);
}

0 comments on commit 7102208

Please sign in to comment.