Skip to content

Commit

Permalink
add loose test cases
Browse files Browse the repository at this point in the history
  • Loading branch information
JLHwung committed May 27, 2020
1 parent 744003f commit 13a109e
Show file tree
Hide file tree
Showing 6 changed files with 159 additions and 0 deletions.
@@ -0,0 +1,45 @@
class Foo {
constructor() {
this.x = 1;
this.self = this;
}
m() { return this.x; };
getSelf() { return this }

test() {
const Foo = this;
const o = { Foo: Foo };
const deep = { very: { o } };
function fn() {
return o;
}
function fnDeep() {
return deep;
}

expect((Foo?.["m"])()).toEqual(1);
expect((Foo?.["m"])().toString).toEqual(1..toString);
expect((Foo?.["m"])().toString()).toEqual('1');

expect((o?.Foo.m)()).toEqual(1);
expect((o?.Foo.m)().toString).toEqual(1..toString);
expect((o?.Foo.m)().toString()).toEqual('1');

expect((((o.Foo?.self.getSelf)())?.m)()).toEqual(1);
expect((((o.Foo.self?.getSelf)())?.m)()).toEqual(1);
}

testNull() {
const o = null;

expect(() => { (o?.Foo.m)() }).toThrow();
expect(() => { (o?.Foo.m)().toString }).toThrow();
expect(() => { (o?.Foo.m)().toString() }).toThrow();

expect(() => { (((o.Foo?.self.getSelf)())?.m)() }).toThrow();
expect(() => { (((o.Foo.self?.getSelf)())?.m)() }).toThrow();
}
}

(new Foo).test();
(new Foo).testNull();
@@ -0,0 +1,6 @@
{
"plugins": [["proposal-optional-chaining", { "loose": true }]],
"parserOpts": {
"createParenthesizedExpressions": true
}
}
@@ -0,0 +1,45 @@
class Foo {
constructor() {
this.x = 1;
this.self = this;
}
m() { return this.x; };
getSelf() { return this }

test() {
const Foo = this;
const o = { Foo: Foo };
const deep = { very: { o } };
function fn() {
return o;
}
function fnDeep() {
return deep;
}

expect((Foo?.["m"])()).toEqual(1);
expect((Foo?.["m"])().toString).toEqual(1..toString);
expect((Foo?.["m"])().toString()).toEqual('1');

expect((o?.Foo.m)()).toEqual(1);
expect((o?.Foo.m)().toString).toEqual(1..toString);
expect((o?.Foo.m)().toString()).toEqual('1');

expect((((o.Foo?.self.getSelf)())?.m)()).toEqual(1);
expect((((o.Foo.self?.getSelf)())?.m)()).toEqual(1);
}

testNull() {
const o = null;

expect(() => { (o?.Foo.m)() }).toThrow();
expect(() => { (o?.Foo.m)().toString }).toThrow();
expect(() => { (o?.Foo.m)().toString() }).toThrow();

expect(() => { (((o.Foo?.self.getSelf)())?.m)() }).toThrow();
expect(() => { (((o.Foo.self?.getSelf)())?.m)() }).toThrow();
}
}

(new Foo).test();
(new Foo).testNull();
@@ -0,0 +1,26 @@
class Foo {
constructor() {
this.x = 1;
this.self = this;
}
m() { return this.x; };
getSelf() { return this }

test() {
const Foo = this;
const o = { Foo: Foo };

(Foo?.["m"])();
(Foo?.["m"])().toString;
(Foo?.["m"])().toString();

(o?.Foo.m)();
(o?.Foo.m)().toString;
(o?.Foo.m)().toString();

(((o.Foo?.self.getSelf)())?.m)();
(((o.Foo.self?.getSelf)())?.m)();
}
}

(new Foo).test();
@@ -0,0 +1,3 @@
{
"plugins": [["proposal-optional-chaining", { "loose": true }]]
}
@@ -0,0 +1,34 @@
class Foo {
constructor() {
this.x = 1;
this.self = this;
}

m() {
return this.x;
}

getSelf() {
return this;
}

test() {
var _o$Foo$self$getSelf, _o$Foo, _o$Foo$self$getSelf2, _o$Foo$self;

const Foo = this;
const o = {
Foo: Foo
};
(Foo == null ? void 0 : Foo["m"].bind(Foo))();
(Foo == null ? void 0 : Foo["m"].bind(Foo))().toString;
(Foo == null ? void 0 : Foo["m"].bind(Foo))().toString();
(o == null ? void 0 : o.Foo.m.bind(o.Foo))();
(o == null ? void 0 : o.Foo.m.bind(o.Foo))().toString;
(o == null ? void 0 : o.Foo.m.bind(o.Foo))().toString();
((_o$Foo$self$getSelf = ((_o$Foo = o.Foo) == null ? void 0 : _o$Foo.self.getSelf.bind(_o$Foo.self))()) == null ? void 0 : _o$Foo$self$getSelf.m.bind(_o$Foo$self$getSelf))();
((_o$Foo$self$getSelf2 = ((_o$Foo$self = o.Foo.self) == null ? void 0 : _o$Foo$self.getSelf.bind(_o$Foo$self))()) == null ? void 0 : _o$Foo$self$getSelf2.m.bind(_o$Foo$self$getSelf2))();
}

}

new Foo().test();

0 comments on commit 13a109e

Please sign in to comment.