Adding test
This commit is contained in:
parent
6b3fc7f310
commit
3662c7b9cc
76
tests/baselines/reference/optionalMethods.js
Normal file
76
tests/baselines/reference/optionalMethods.js
Normal file
|
@ -0,0 +1,76 @@
|
|||
//// [optionalMethods.ts]
|
||||
|
||||
interface Foo {
|
||||
a: number;
|
||||
b?: number;
|
||||
f(): number;
|
||||
g?(): number;
|
||||
}
|
||||
|
||||
function test1(x: Foo) {
|
||||
x.a;
|
||||
x.b;
|
||||
x.f;
|
||||
x.g;
|
||||
let f1 = x.f();
|
||||
let g1 = x.g && x.g();
|
||||
let g2 = x.g ? x.g() : 0;
|
||||
}
|
||||
|
||||
class Bar {
|
||||
a: number;
|
||||
b?: number;
|
||||
f() {
|
||||
return 1;
|
||||
}
|
||||
g?(): number; // Body of optional method can be omitted
|
||||
h?() {
|
||||
return 2;
|
||||
}
|
||||
}
|
||||
|
||||
function test2(x: Bar) {
|
||||
x.a;
|
||||
x.b;
|
||||
x.f;
|
||||
x.g;
|
||||
let f1 = x.f();
|
||||
let g1 = x.g && x.g();
|
||||
let g2 = x.g ? x.g() : 0;
|
||||
let h1 = x.h && x.h();
|
||||
let h2 = x.h ? x.h() : 0;
|
||||
}
|
||||
|
||||
|
||||
//// [optionalMethods.js]
|
||||
function test1(x) {
|
||||
x.a;
|
||||
x.b;
|
||||
x.f;
|
||||
x.g;
|
||||
var f1 = x.f();
|
||||
var g1 = x.g && x.g();
|
||||
var g2 = x.g ? x.g() : 0;
|
||||
}
|
||||
var Bar = (function () {
|
||||
function Bar() {
|
||||
}
|
||||
Bar.prototype.f = function () {
|
||||
return 1;
|
||||
};
|
||||
Bar.prototype.h = function () {
|
||||
return 2;
|
||||
};
|
||||
return Bar;
|
||||
}());
|
||||
function test2(x) {
|
||||
x.a;
|
||||
x.b;
|
||||
x.f;
|
||||
x.g;
|
||||
var f1 = x.f();
|
||||
var g1 = x.g && x.g();
|
||||
var g2 = x.g ? x.g() : 0;
|
||||
var h1 = x.h && x.h();
|
||||
var h2 = x.h ? x.h() : 0;
|
||||
}
|
160
tests/baselines/reference/optionalMethods.symbols
Normal file
160
tests/baselines/reference/optionalMethods.symbols
Normal file
|
@ -0,0 +1,160 @@
|
|||
=== tests/cases/conformance/types/namedTypes/optionalMethods.ts ===
|
||||
|
||||
interface Foo {
|
||||
>Foo : Symbol(Foo, Decl(optionalMethods.ts, 0, 0))
|
||||
|
||||
a: number;
|
||||
>a : Symbol(Foo.a, Decl(optionalMethods.ts, 1, 15))
|
||||
|
||||
b?: number;
|
||||
>b : Symbol(Foo.b, Decl(optionalMethods.ts, 2, 14))
|
||||
|
||||
f(): number;
|
||||
>f : Symbol(Foo.f, Decl(optionalMethods.ts, 3, 15))
|
||||
|
||||
g?(): number;
|
||||
>g : Symbol(Foo.g, Decl(optionalMethods.ts, 4, 16))
|
||||
}
|
||||
|
||||
function test1(x: Foo) {
|
||||
>test1 : Symbol(test1, Decl(optionalMethods.ts, 6, 1))
|
||||
>x : Symbol(x, Decl(optionalMethods.ts, 8, 15))
|
||||
>Foo : Symbol(Foo, Decl(optionalMethods.ts, 0, 0))
|
||||
|
||||
x.a;
|
||||
>x.a : Symbol(Foo.a, Decl(optionalMethods.ts, 1, 15))
|
||||
>x : Symbol(x, Decl(optionalMethods.ts, 8, 15))
|
||||
>a : Symbol(Foo.a, Decl(optionalMethods.ts, 1, 15))
|
||||
|
||||
x.b;
|
||||
>x.b : Symbol(Foo.b, Decl(optionalMethods.ts, 2, 14))
|
||||
>x : Symbol(x, Decl(optionalMethods.ts, 8, 15))
|
||||
>b : Symbol(Foo.b, Decl(optionalMethods.ts, 2, 14))
|
||||
|
||||
x.f;
|
||||
>x.f : Symbol(Foo.f, Decl(optionalMethods.ts, 3, 15))
|
||||
>x : Symbol(x, Decl(optionalMethods.ts, 8, 15))
|
||||
>f : Symbol(Foo.f, Decl(optionalMethods.ts, 3, 15))
|
||||
|
||||
x.g;
|
||||
>x.g : Symbol(Foo.g, Decl(optionalMethods.ts, 4, 16))
|
||||
>x : Symbol(x, Decl(optionalMethods.ts, 8, 15))
|
||||
>g : Symbol(Foo.g, Decl(optionalMethods.ts, 4, 16))
|
||||
|
||||
let f1 = x.f();
|
||||
>f1 : Symbol(f1, Decl(optionalMethods.ts, 13, 7))
|
||||
>x.f : Symbol(Foo.f, Decl(optionalMethods.ts, 3, 15))
|
||||
>x : Symbol(x, Decl(optionalMethods.ts, 8, 15))
|
||||
>f : Symbol(Foo.f, Decl(optionalMethods.ts, 3, 15))
|
||||
|
||||
let g1 = x.g && x.g();
|
||||
>g1 : Symbol(g1, Decl(optionalMethods.ts, 14, 7))
|
||||
>x.g : Symbol(Foo.g, Decl(optionalMethods.ts, 4, 16))
|
||||
>x : Symbol(x, Decl(optionalMethods.ts, 8, 15))
|
||||
>g : Symbol(Foo.g, Decl(optionalMethods.ts, 4, 16))
|
||||
>x.g : Symbol(Foo.g, Decl(optionalMethods.ts, 4, 16))
|
||||
>x : Symbol(x, Decl(optionalMethods.ts, 8, 15))
|
||||
>g : Symbol(Foo.g, Decl(optionalMethods.ts, 4, 16))
|
||||
|
||||
let g2 = x.g ? x.g() : 0;
|
||||
>g2 : Symbol(g2, Decl(optionalMethods.ts, 15, 7))
|
||||
>x.g : Symbol(Foo.g, Decl(optionalMethods.ts, 4, 16))
|
||||
>x : Symbol(x, Decl(optionalMethods.ts, 8, 15))
|
||||
>g : Symbol(Foo.g, Decl(optionalMethods.ts, 4, 16))
|
||||
>x.g : Symbol(Foo.g, Decl(optionalMethods.ts, 4, 16))
|
||||
>x : Symbol(x, Decl(optionalMethods.ts, 8, 15))
|
||||
>g : Symbol(Foo.g, Decl(optionalMethods.ts, 4, 16))
|
||||
}
|
||||
|
||||
class Bar {
|
||||
>Bar : Symbol(Bar, Decl(optionalMethods.ts, 16, 1))
|
||||
|
||||
a: number;
|
||||
>a : Symbol(Bar.a, Decl(optionalMethods.ts, 18, 11))
|
||||
|
||||
b?: number;
|
||||
>b : Symbol(Bar.b, Decl(optionalMethods.ts, 19, 14))
|
||||
|
||||
f() {
|
||||
>f : Symbol(Bar.f, Decl(optionalMethods.ts, 20, 15))
|
||||
|
||||
return 1;
|
||||
}
|
||||
g?(): number; // Body of optional method can be omitted
|
||||
>g : Symbol(Bar.g, Decl(optionalMethods.ts, 23, 5))
|
||||
|
||||
h?() {
|
||||
>h : Symbol(Bar.h, Decl(optionalMethods.ts, 24, 17))
|
||||
|
||||
return 2;
|
||||
}
|
||||
}
|
||||
|
||||
function test2(x: Bar) {
|
||||
>test2 : Symbol(test2, Decl(optionalMethods.ts, 28, 1))
|
||||
>x : Symbol(x, Decl(optionalMethods.ts, 30, 15))
|
||||
>Bar : Symbol(Bar, Decl(optionalMethods.ts, 16, 1))
|
||||
|
||||
x.a;
|
||||
>x.a : Symbol(Bar.a, Decl(optionalMethods.ts, 18, 11))
|
||||
>x : Symbol(x, Decl(optionalMethods.ts, 30, 15))
|
||||
>a : Symbol(Bar.a, Decl(optionalMethods.ts, 18, 11))
|
||||
|
||||
x.b;
|
||||
>x.b : Symbol(Bar.b, Decl(optionalMethods.ts, 19, 14))
|
||||
>x : Symbol(x, Decl(optionalMethods.ts, 30, 15))
|
||||
>b : Symbol(Bar.b, Decl(optionalMethods.ts, 19, 14))
|
||||
|
||||
x.f;
|
||||
>x.f : Symbol(Bar.f, Decl(optionalMethods.ts, 20, 15))
|
||||
>x : Symbol(x, Decl(optionalMethods.ts, 30, 15))
|
||||
>f : Symbol(Bar.f, Decl(optionalMethods.ts, 20, 15))
|
||||
|
||||
x.g;
|
||||
>x.g : Symbol(Bar.g, Decl(optionalMethods.ts, 23, 5))
|
||||
>x : Symbol(x, Decl(optionalMethods.ts, 30, 15))
|
||||
>g : Symbol(Bar.g, Decl(optionalMethods.ts, 23, 5))
|
||||
|
||||
let f1 = x.f();
|
||||
>f1 : Symbol(f1, Decl(optionalMethods.ts, 35, 7))
|
||||
>x.f : Symbol(Bar.f, Decl(optionalMethods.ts, 20, 15))
|
||||
>x : Symbol(x, Decl(optionalMethods.ts, 30, 15))
|
||||
>f : Symbol(Bar.f, Decl(optionalMethods.ts, 20, 15))
|
||||
|
||||
let g1 = x.g && x.g();
|
||||
>g1 : Symbol(g1, Decl(optionalMethods.ts, 36, 7))
|
||||
>x.g : Symbol(Bar.g, Decl(optionalMethods.ts, 23, 5))
|
||||
>x : Symbol(x, Decl(optionalMethods.ts, 30, 15))
|
||||
>g : Symbol(Bar.g, Decl(optionalMethods.ts, 23, 5))
|
||||
>x.g : Symbol(Bar.g, Decl(optionalMethods.ts, 23, 5))
|
||||
>x : Symbol(x, Decl(optionalMethods.ts, 30, 15))
|
||||
>g : Symbol(Bar.g, Decl(optionalMethods.ts, 23, 5))
|
||||
|
||||
let g2 = x.g ? x.g() : 0;
|
||||
>g2 : Symbol(g2, Decl(optionalMethods.ts, 37, 7))
|
||||
>x.g : Symbol(Bar.g, Decl(optionalMethods.ts, 23, 5))
|
||||
>x : Symbol(x, Decl(optionalMethods.ts, 30, 15))
|
||||
>g : Symbol(Bar.g, Decl(optionalMethods.ts, 23, 5))
|
||||
>x.g : Symbol(Bar.g, Decl(optionalMethods.ts, 23, 5))
|
||||
>x : Symbol(x, Decl(optionalMethods.ts, 30, 15))
|
||||
>g : Symbol(Bar.g, Decl(optionalMethods.ts, 23, 5))
|
||||
|
||||
let h1 = x.h && x.h();
|
||||
>h1 : Symbol(h1, Decl(optionalMethods.ts, 38, 7))
|
||||
>x.h : Symbol(Bar.h, Decl(optionalMethods.ts, 24, 17))
|
||||
>x : Symbol(x, Decl(optionalMethods.ts, 30, 15))
|
||||
>h : Symbol(Bar.h, Decl(optionalMethods.ts, 24, 17))
|
||||
>x.h : Symbol(Bar.h, Decl(optionalMethods.ts, 24, 17))
|
||||
>x : Symbol(x, Decl(optionalMethods.ts, 30, 15))
|
||||
>h : Symbol(Bar.h, Decl(optionalMethods.ts, 24, 17))
|
||||
|
||||
let h2 = x.h ? x.h() : 0;
|
||||
>h2 : Symbol(h2, Decl(optionalMethods.ts, 39, 7))
|
||||
>x.h : Symbol(Bar.h, Decl(optionalMethods.ts, 24, 17))
|
||||
>x : Symbol(x, Decl(optionalMethods.ts, 30, 15))
|
||||
>h : Symbol(Bar.h, Decl(optionalMethods.ts, 24, 17))
|
||||
>x.h : Symbol(Bar.h, Decl(optionalMethods.ts, 24, 17))
|
||||
>x : Symbol(x, Decl(optionalMethods.ts, 30, 15))
|
||||
>h : Symbol(Bar.h, Decl(optionalMethods.ts, 24, 17))
|
||||
}
|
||||
|
179
tests/baselines/reference/optionalMethods.types
Normal file
179
tests/baselines/reference/optionalMethods.types
Normal file
|
@ -0,0 +1,179 @@
|
|||
=== tests/cases/conformance/types/namedTypes/optionalMethods.ts ===
|
||||
|
||||
interface Foo {
|
||||
>Foo : Foo
|
||||
|
||||
a: number;
|
||||
>a : number
|
||||
|
||||
b?: number;
|
||||
>b : number | undefined
|
||||
|
||||
f(): number;
|
||||
>f : () => number
|
||||
|
||||
g?(): number;
|
||||
>g : (() => number) | undefined
|
||||
}
|
||||
|
||||
function test1(x: Foo) {
|
||||
>test1 : (x: Foo) => void
|
||||
>x : Foo
|
||||
>Foo : Foo
|
||||
|
||||
x.a;
|
||||
>x.a : number
|
||||
>x : Foo
|
||||
>a : number
|
||||
|
||||
x.b;
|
||||
>x.b : number | undefined
|
||||
>x : Foo
|
||||
>b : number | undefined
|
||||
|
||||
x.f;
|
||||
>x.f : () => number
|
||||
>x : Foo
|
||||
>f : () => number
|
||||
|
||||
x.g;
|
||||
>x.g : (() => number) | undefined
|
||||
>x : Foo
|
||||
>g : (() => number) | undefined
|
||||
|
||||
let f1 = x.f();
|
||||
>f1 : number
|
||||
>x.f() : number
|
||||
>x.f : () => number
|
||||
>x : Foo
|
||||
>f : () => number
|
||||
|
||||
let g1 = x.g && x.g();
|
||||
>g1 : number | undefined
|
||||
>x.g && x.g() : number | undefined
|
||||
>x.g : (() => number) | undefined
|
||||
>x : Foo
|
||||
>g : (() => number) | undefined
|
||||
>x.g() : number
|
||||
>x.g : () => number
|
||||
>x : Foo
|
||||
>g : () => number
|
||||
|
||||
let g2 = x.g ? x.g() : 0;
|
||||
>g2 : number
|
||||
>x.g ? x.g() : 0 : number
|
||||
>x.g : (() => number) | undefined
|
||||
>x : Foo
|
||||
>g : (() => number) | undefined
|
||||
>x.g() : number
|
||||
>x.g : () => number
|
||||
>x : Foo
|
||||
>g : () => number
|
||||
>0 : number
|
||||
}
|
||||
|
||||
class Bar {
|
||||
>Bar : Bar
|
||||
|
||||
a: number;
|
||||
>a : number
|
||||
|
||||
b?: number;
|
||||
>b : number | undefined
|
||||
|
||||
f() {
|
||||
>f : () => number
|
||||
|
||||
return 1;
|
||||
>1 : number
|
||||
}
|
||||
g?(): number; // Body of optional method can be omitted
|
||||
>g : (() => number) | undefined
|
||||
|
||||
h?() {
|
||||
>h : (() => number) | undefined
|
||||
|
||||
return 2;
|
||||
>2 : number
|
||||
}
|
||||
}
|
||||
|
||||
function test2(x: Bar) {
|
||||
>test2 : (x: Bar) => void
|
||||
>x : Bar
|
||||
>Bar : Bar
|
||||
|
||||
x.a;
|
||||
>x.a : number
|
||||
>x : Bar
|
||||
>a : number
|
||||
|
||||
x.b;
|
||||
>x.b : number | undefined
|
||||
>x : Bar
|
||||
>b : number | undefined
|
||||
|
||||
x.f;
|
||||
>x.f : () => number
|
||||
>x : Bar
|
||||
>f : () => number
|
||||
|
||||
x.g;
|
||||
>x.g : (() => number) | undefined
|
||||
>x : Bar
|
||||
>g : (() => number) | undefined
|
||||
|
||||
let f1 = x.f();
|
||||
>f1 : number
|
||||
>x.f() : number
|
||||
>x.f : () => number
|
||||
>x : Bar
|
||||
>f : () => number
|
||||
|
||||
let g1 = x.g && x.g();
|
||||
>g1 : number | undefined
|
||||
>x.g && x.g() : number | undefined
|
||||
>x.g : (() => number) | undefined
|
||||
>x : Bar
|
||||
>g : (() => number) | undefined
|
||||
>x.g() : number
|
||||
>x.g : () => number
|
||||
>x : Bar
|
||||
>g : () => number
|
||||
|
||||
let g2 = x.g ? x.g() : 0;
|
||||
>g2 : number
|
||||
>x.g ? x.g() : 0 : number
|
||||
>x.g : (() => number) | undefined
|
||||
>x : Bar
|
||||
>g : (() => number) | undefined
|
||||
>x.g() : number
|
||||
>x.g : () => number
|
||||
>x : Bar
|
||||
>g : () => number
|
||||
>0 : number
|
||||
|
||||
let h1 = x.h && x.h();
|
||||
>h1 : number | undefined
|
||||
>x.h && x.h() : number | undefined
|
||||
>x.h : (() => number) | undefined
|
||||
>x : Bar
|
||||
>h : (() => number) | undefined
|
||||
>x.h() : number
|
||||
>x.h : () => number
|
||||
>x : Bar
|
||||
>h : () => number
|
||||
|
||||
let h2 = x.h ? x.h() : 0;
|
||||
>h2 : number
|
||||
>x.h ? x.h() : 0 : number
|
||||
>x.h : (() => number) | undefined
|
||||
>x : Bar
|
||||
>h : (() => number) | undefined
|
||||
>x.h() : number
|
||||
>x.h : () => number
|
||||
>x : Bar
|
||||
>h : () => number
|
||||
>0 : number
|
||||
}
|
||||
|
42
tests/cases/conformance/types/namedTypes/optionalMethods.ts
Normal file
42
tests/cases/conformance/types/namedTypes/optionalMethods.ts
Normal file
|
@ -0,0 +1,42 @@
|
|||
// @strictNullChecks: true
|
||||
|
||||
interface Foo {
|
||||
a: number;
|
||||
b?: number;
|
||||
f(): number;
|
||||
g?(): number;
|
||||
}
|
||||
|
||||
function test1(x: Foo) {
|
||||
x.a;
|
||||
x.b;
|
||||
x.f;
|
||||
x.g;
|
||||
let f1 = x.f();
|
||||
let g1 = x.g && x.g();
|
||||
let g2 = x.g ? x.g() : 0;
|
||||
}
|
||||
|
||||
class Bar {
|
||||
a: number;
|
||||
b?: number;
|
||||
f() {
|
||||
return 1;
|
||||
}
|
||||
g?(): number; // Body of optional method can be omitted
|
||||
h?() {
|
||||
return 2;
|
||||
}
|
||||
}
|
||||
|
||||
function test2(x: Bar) {
|
||||
x.a;
|
||||
x.b;
|
||||
x.f;
|
||||
x.g;
|
||||
let f1 = x.f();
|
||||
let g1 = x.g && x.g();
|
||||
let g2 = x.g ? x.g() : 0;
|
||||
let h1 = x.h && x.h();
|
||||
let h2 = x.h ? x.h() : 0;
|
||||
}
|
Loading…
Reference in a new issue