Skip to content

Commit 8498ef1

Browse files
committed
Adding more tests
1 parent e82bbce commit 8498ef1

File tree

4 files changed

+223
-46
lines changed

4 files changed

+223
-46
lines changed

tests/baselines/reference/optionalMethods.js

+72-1
Original file line numberDiff line numberDiff line change
@@ -20,6 +20,8 @@ function test1(x: Foo) {
2020
class Bar {
2121
a: number;
2222
b?: number;
23+
c? = 2;
24+
constructor(public d?: number, public e = 10) {}
2325
f() {
2426
return 1;
2527
}
@@ -32,6 +34,9 @@ class Bar {
3234
function test2(x: Bar) {
3335
x.a;
3436
x.b;
37+
x.c;
38+
x.d;
39+
x.e;
3540
x.f;
3641
x.g;
3742
let f1 = x.f();
@@ -40,9 +45,24 @@ function test2(x: Bar) {
4045
let h1 = x.h && x.h();
4146
let h2 = x.h ? x.h() : 0;
4247
}
48+
49+
class Base {
50+
a?: number;
51+
f?(): number;
52+
}
53+
54+
class Derived extends Base {
55+
a = 1;
56+
f(): number { return 1; }
57+
}
4358

4459

4560
//// [optionalMethods.js]
61+
var __extends = (this && this.__extends) || function (d, b) {
62+
for (var p in b) if (b.hasOwnProperty(p)) d[p] = b[p];
63+
function __() { this.constructor = d; }
64+
d.prototype = b === null ? Object.create(b) : (__.prototype = b.prototype, new __());
65+
};
4666
function test1(x) {
4767
x.a;
4868
x.b;
@@ -53,7 +73,11 @@ function test1(x) {
5373
var g2 = x.g ? x.g() : 0;
5474
}
5575
var Bar = (function () {
56-
function Bar() {
76+
function Bar(d, e) {
77+
if (e === void 0) { e = 10; }
78+
this.d = d;
79+
this.e = e;
80+
this.c = 2;
5781
}
5882
Bar.prototype.f = function () {
5983
return 1;
@@ -66,6 +90,9 @@ var Bar = (function () {
6690
function test2(x) {
6791
x.a;
6892
x.b;
93+
x.c;
94+
x.d;
95+
x.e;
6996
x.f;
7097
x.g;
7198
var f1 = x.f();
@@ -74,3 +101,47 @@ function test2(x) {
74101
var h1 = x.h && x.h();
75102
var h2 = x.h ? x.h() : 0;
76103
}
104+
var Base = (function () {
105+
function Base() {
106+
}
107+
return Base;
108+
}());
109+
var Derived = (function (_super) {
110+
__extends(Derived, _super);
111+
function Derived() {
112+
_super.apply(this, arguments);
113+
this.a = 1;
114+
}
115+
Derived.prototype.f = function () { return 1; };
116+
return Derived;
117+
}(Base));
118+
119+
120+
//// [optionalMethods.d.ts]
121+
interface Foo {
122+
a: number;
123+
b?: number;
124+
f(): number;
125+
g?(): number;
126+
}
127+
declare function test1(x: Foo): void;
128+
declare class Bar {
129+
d?: number;
130+
e: number;
131+
a: number;
132+
b?: number;
133+
c?: number | undefined;
134+
constructor(d?: number, e?: number);
135+
f(): number;
136+
g?(): number;
137+
h?(): number;
138+
}
139+
declare function test2(x: Bar): void;
140+
declare class Base {
141+
a?: number;
142+
f?(): number;
143+
}
144+
declare class Derived extends Base {
145+
a: number;
146+
f(): number;
147+
}

tests/baselines/reference/optionalMethods.symbols

+88-45
Original file line numberDiff line numberDiff line change
@@ -75,86 +75,129 @@ class Bar {
7575
b?: number;
7676
>b : Symbol(Bar.b, Decl(optionalMethods.ts, 19, 14))
7777

78+
c? = 2;
79+
>c : Symbol(Bar.c, Decl(optionalMethods.ts, 20, 15))
80+
81+
constructor(public d?: number, public e = 10) {}
82+
>d : Symbol(Bar.d, Decl(optionalMethods.ts, 22, 16))
83+
>e : Symbol(Bar.e, Decl(optionalMethods.ts, 22, 34))
84+
7885
f() {
79-
>f : Symbol(Bar.f, Decl(optionalMethods.ts, 20, 15))
86+
>f : Symbol(Bar.f, Decl(optionalMethods.ts, 22, 52))
8087

8188
return 1;
8289
}
8390
g?(): number; // Body of optional method can be omitted
84-
>g : Symbol(Bar.g, Decl(optionalMethods.ts, 23, 5))
91+
>g : Symbol(Bar.g, Decl(optionalMethods.ts, 25, 5))
8592

8693
h?() {
87-
>h : Symbol(Bar.h, Decl(optionalMethods.ts, 24, 17))
94+
>h : Symbol(Bar.h, Decl(optionalMethods.ts, 26, 17))
8895

8996
return 2;
9097
}
9198
}
9299

93100
function test2(x: Bar) {
94-
>test2 : Symbol(test2, Decl(optionalMethods.ts, 28, 1))
95-
>x : Symbol(x, Decl(optionalMethods.ts, 30, 15))
101+
>test2 : Symbol(test2, Decl(optionalMethods.ts, 30, 1))
102+
>x : Symbol(x, Decl(optionalMethods.ts, 32, 15))
96103
>Bar : Symbol(Bar, Decl(optionalMethods.ts, 16, 1))
97104

98105
x.a;
99106
>x.a : Symbol(Bar.a, Decl(optionalMethods.ts, 18, 11))
100-
>x : Symbol(x, Decl(optionalMethods.ts, 30, 15))
107+
>x : Symbol(x, Decl(optionalMethods.ts, 32, 15))
101108
>a : Symbol(Bar.a, Decl(optionalMethods.ts, 18, 11))
102109

103110
x.b;
104111
>x.b : Symbol(Bar.b, Decl(optionalMethods.ts, 19, 14))
105-
>x : Symbol(x, Decl(optionalMethods.ts, 30, 15))
112+
>x : Symbol(x, Decl(optionalMethods.ts, 32, 15))
106113
>b : Symbol(Bar.b, Decl(optionalMethods.ts, 19, 14))
107114

115+
x.c;
116+
>x.c : Symbol(Bar.c, Decl(optionalMethods.ts, 20, 15))
117+
>x : Symbol(x, Decl(optionalMethods.ts, 32, 15))
118+
>c : Symbol(Bar.c, Decl(optionalMethods.ts, 20, 15))
119+
120+
x.d;
121+
>x.d : Symbol(Bar.d, Decl(optionalMethods.ts, 22, 16))
122+
>x : Symbol(x, Decl(optionalMethods.ts, 32, 15))
123+
>d : Symbol(Bar.d, Decl(optionalMethods.ts, 22, 16))
124+
125+
x.e;
126+
>x.e : Symbol(Bar.e, Decl(optionalMethods.ts, 22, 34))
127+
>x : Symbol(x, Decl(optionalMethods.ts, 32, 15))
128+
>e : Symbol(Bar.e, Decl(optionalMethods.ts, 22, 34))
129+
108130
x.f;
109-
>x.f : Symbol(Bar.f, Decl(optionalMethods.ts, 20, 15))
110-
>x : Symbol(x, Decl(optionalMethods.ts, 30, 15))
111-
>f : Symbol(Bar.f, Decl(optionalMethods.ts, 20, 15))
131+
>x.f : Symbol(Bar.f, Decl(optionalMethods.ts, 22, 52))
132+
>x : Symbol(x, Decl(optionalMethods.ts, 32, 15))
133+
>f : Symbol(Bar.f, Decl(optionalMethods.ts, 22, 52))
112134

113135
x.g;
114-
>x.g : Symbol(Bar.g, Decl(optionalMethods.ts, 23, 5))
115-
>x : Symbol(x, Decl(optionalMethods.ts, 30, 15))
116-
>g : Symbol(Bar.g, Decl(optionalMethods.ts, 23, 5))
136+
>x.g : Symbol(Bar.g, Decl(optionalMethods.ts, 25, 5))
137+
>x : Symbol(x, Decl(optionalMethods.ts, 32, 15))
138+
>g : Symbol(Bar.g, Decl(optionalMethods.ts, 25, 5))
117139

118140
let f1 = x.f();
119-
>f1 : Symbol(f1, Decl(optionalMethods.ts, 35, 7))
120-
>x.f : Symbol(Bar.f, Decl(optionalMethods.ts, 20, 15))
121-
>x : Symbol(x, Decl(optionalMethods.ts, 30, 15))
122-
>f : Symbol(Bar.f, Decl(optionalMethods.ts, 20, 15))
141+
>f1 : Symbol(f1, Decl(optionalMethods.ts, 40, 7))
142+
>x.f : Symbol(Bar.f, Decl(optionalMethods.ts, 22, 52))
143+
>x : Symbol(x, Decl(optionalMethods.ts, 32, 15))
144+
>f : Symbol(Bar.f, Decl(optionalMethods.ts, 22, 52))
123145

124146
let g1 = x.g && x.g();
125-
>g1 : Symbol(g1, Decl(optionalMethods.ts, 36, 7))
126-
>x.g : Symbol(Bar.g, Decl(optionalMethods.ts, 23, 5))
127-
>x : Symbol(x, Decl(optionalMethods.ts, 30, 15))
128-
>g : Symbol(Bar.g, Decl(optionalMethods.ts, 23, 5))
129-
>x.g : Symbol(Bar.g, Decl(optionalMethods.ts, 23, 5))
130-
>x : Symbol(x, Decl(optionalMethods.ts, 30, 15))
131-
>g : Symbol(Bar.g, Decl(optionalMethods.ts, 23, 5))
147+
>g1 : Symbol(g1, Decl(optionalMethods.ts, 41, 7))
148+
>x.g : Symbol(Bar.g, Decl(optionalMethods.ts, 25, 5))
149+
>x : Symbol(x, Decl(optionalMethods.ts, 32, 15))
150+
>g : Symbol(Bar.g, Decl(optionalMethods.ts, 25, 5))
151+
>x.g : Symbol(Bar.g, Decl(optionalMethods.ts, 25, 5))
152+
>x : Symbol(x, Decl(optionalMethods.ts, 32, 15))
153+
>g : Symbol(Bar.g, Decl(optionalMethods.ts, 25, 5))
132154

133155
let g2 = x.g ? x.g() : 0;
134-
>g2 : Symbol(g2, Decl(optionalMethods.ts, 37, 7))
135-
>x.g : Symbol(Bar.g, Decl(optionalMethods.ts, 23, 5))
136-
>x : Symbol(x, Decl(optionalMethods.ts, 30, 15))
137-
>g : Symbol(Bar.g, Decl(optionalMethods.ts, 23, 5))
138-
>x.g : Symbol(Bar.g, Decl(optionalMethods.ts, 23, 5))
139-
>x : Symbol(x, Decl(optionalMethods.ts, 30, 15))
140-
>g : Symbol(Bar.g, Decl(optionalMethods.ts, 23, 5))
156+
>g2 : Symbol(g2, Decl(optionalMethods.ts, 42, 7))
157+
>x.g : Symbol(Bar.g, Decl(optionalMethods.ts, 25, 5))
158+
>x : Symbol(x, Decl(optionalMethods.ts, 32, 15))
159+
>g : Symbol(Bar.g, Decl(optionalMethods.ts, 25, 5))
160+
>x.g : Symbol(Bar.g, Decl(optionalMethods.ts, 25, 5))
161+
>x : Symbol(x, Decl(optionalMethods.ts, 32, 15))
162+
>g : Symbol(Bar.g, Decl(optionalMethods.ts, 25, 5))
141163

142164
let h1 = x.h && x.h();
143-
>h1 : Symbol(h1, Decl(optionalMethods.ts, 38, 7))
144-
>x.h : Symbol(Bar.h, Decl(optionalMethods.ts, 24, 17))
145-
>x : Symbol(x, Decl(optionalMethods.ts, 30, 15))
146-
>h : Symbol(Bar.h, Decl(optionalMethods.ts, 24, 17))
147-
>x.h : Symbol(Bar.h, Decl(optionalMethods.ts, 24, 17))
148-
>x : Symbol(x, Decl(optionalMethods.ts, 30, 15))
149-
>h : Symbol(Bar.h, Decl(optionalMethods.ts, 24, 17))
165+
>h1 : Symbol(h1, Decl(optionalMethods.ts, 43, 7))
166+
>x.h : Symbol(Bar.h, Decl(optionalMethods.ts, 26, 17))
167+
>x : Symbol(x, Decl(optionalMethods.ts, 32, 15))
168+
>h : Symbol(Bar.h, Decl(optionalMethods.ts, 26, 17))
169+
>x.h : Symbol(Bar.h, Decl(optionalMethods.ts, 26, 17))
170+
>x : Symbol(x, Decl(optionalMethods.ts, 32, 15))
171+
>h : Symbol(Bar.h, Decl(optionalMethods.ts, 26, 17))
150172

151173
let h2 = x.h ? x.h() : 0;
152-
>h2 : Symbol(h2, Decl(optionalMethods.ts, 39, 7))
153-
>x.h : Symbol(Bar.h, Decl(optionalMethods.ts, 24, 17))
154-
>x : Symbol(x, Decl(optionalMethods.ts, 30, 15))
155-
>h : Symbol(Bar.h, Decl(optionalMethods.ts, 24, 17))
156-
>x.h : Symbol(Bar.h, Decl(optionalMethods.ts, 24, 17))
157-
>x : Symbol(x, Decl(optionalMethods.ts, 30, 15))
158-
>h : Symbol(Bar.h, Decl(optionalMethods.ts, 24, 17))
174+
>h2 : Symbol(h2, Decl(optionalMethods.ts, 44, 7))
175+
>x.h : Symbol(Bar.h, Decl(optionalMethods.ts, 26, 17))
176+
>x : Symbol(x, Decl(optionalMethods.ts, 32, 15))
177+
>h : Symbol(Bar.h, Decl(optionalMethods.ts, 26, 17))
178+
>x.h : Symbol(Bar.h, Decl(optionalMethods.ts, 26, 17))
179+
>x : Symbol(x, Decl(optionalMethods.ts, 32, 15))
180+
>h : Symbol(Bar.h, Decl(optionalMethods.ts, 26, 17))
181+
}
182+
183+
class Base {
184+
>Base : Symbol(Base, Decl(optionalMethods.ts, 45, 1))
185+
186+
a?: number;
187+
>a : Symbol(Base.a, Decl(optionalMethods.ts, 47, 12))
188+
189+
f?(): number;
190+
>f : Symbol(Base.f, Decl(optionalMethods.ts, 48, 15))
191+
}
192+
193+
class Derived extends Base {
194+
>Derived : Symbol(Derived, Decl(optionalMethods.ts, 50, 1))
195+
>Base : Symbol(Base, Decl(optionalMethods.ts, 45, 1))
196+
197+
a = 1;
198+
>a : Symbol(Derived.a, Decl(optionalMethods.ts, 52, 28))
199+
200+
f(): number { return 1; }
201+
>f : Symbol(Derived.f, Decl(optionalMethods.ts, 53, 10))
159202
}
160203

tests/baselines/reference/optionalMethods.types

+47
Original file line numberDiff line numberDiff line change
@@ -81,6 +81,15 @@ class Bar {
8181
b?: number;
8282
>b : number | undefined
8383

84+
c? = 2;
85+
>c : number | undefined
86+
>2 : number
87+
88+
constructor(public d?: number, public e = 10) {}
89+
>d : number | undefined
90+
>e : number
91+
>10 : number
92+
8493
f() {
8594
>f : () => number
8695

@@ -113,6 +122,21 @@ function test2(x: Bar) {
113122
>x : Bar
114123
>b : number | undefined
115124

125+
x.c;
126+
>x.c : number | undefined
127+
>x : Bar
128+
>c : number | undefined
129+
130+
x.d;
131+
>x.d : number | undefined
132+
>x : Bar
133+
>d : number | undefined
134+
135+
x.e;
136+
>x.e : number
137+
>x : Bar
138+
>e : number
139+
116140
x.f;
117141
>x.f : () => number
118142
>x : Bar
@@ -177,3 +201,26 @@ function test2(x: Bar) {
177201
>0 : number
178202
}
179203

204+
class Base {
205+
>Base : Base
206+
207+
a?: number;
208+
>a : number | undefined
209+
210+
f?(): number;
211+
>f : (() => number) | undefined
212+
}
213+
214+
class Derived extends Base {
215+
>Derived : Derived
216+
>Base : Base
217+
218+
a = 1;
219+
>a : number
220+
>1 : number
221+
222+
f(): number { return 1; }
223+
>f : () => number
224+
>1 : number
225+
}
226+

tests/cases/conformance/types/namedTypes/optionalMethods.ts

+16
Original file line numberDiff line numberDiff line change
@@ -1,4 +1,5 @@
11
// @strictNullChecks: true
2+
// @declaration: true
23

34
interface Foo {
45
a: number;
@@ -20,6 +21,8 @@ function test1(x: Foo) {
2021
class Bar {
2122
a: number;
2223
b?: number;
24+
c? = 2;
25+
constructor(public d?: number, public e = 10) {}
2326
f() {
2427
return 1;
2528
}
@@ -32,6 +35,9 @@ class Bar {
3235
function test2(x: Bar) {
3336
x.a;
3437
x.b;
38+
x.c;
39+
x.d;
40+
x.e;
3541
x.f;
3642
x.g;
3743
let f1 = x.f();
@@ -40,3 +46,13 @@ function test2(x: Bar) {
4046
let h1 = x.h && x.h();
4147
let h2 = x.h ? x.h() : 0;
4248
}
49+
50+
class Base {
51+
a?: number;
52+
f?(): number;
53+
}
54+
55+
class Derived extends Base {
56+
a = 1;
57+
f(): number { return 1; }
58+
}

0 commit comments

Comments
 (0)