Skip to content

Commit ef81594

Browse files
committed
Add tests
1 parent 2344a80 commit ef81594

File tree

4 files changed

+1944
-0
lines changed

4 files changed

+1944
-0
lines changed
Lines changed: 348 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,348 @@
1+
//// [literalTypes2.ts]
2+
enum E {
3+
A, B, C
4+
}
5+
6+
let cond: boolean;
7+
8+
function f1(p1 = 1, p2 = "abc", p3 = true, p4 = E.A) {
9+
var v1 = 1;
10+
var v2 = -123;
11+
var v3 = 3 + 4;
12+
var v4 = "abc";
13+
var v5 = "";
14+
var v6 = "abc" + "def";
15+
var v7 = true;
16+
var v8 = E.A;
17+
let x1 = 1;
18+
let x2 = -123;
19+
let x3 = 3 + 4;
20+
let x4 = "abc";
21+
let x5 = "";
22+
let x6 = "abc" + "def";
23+
let x7 = true;
24+
var x8 = E.A;
25+
const c1 = 1;
26+
const c2 = -123;
27+
const c3 = 3 + 4;
28+
const c4 = "abc";
29+
const c5 = "";
30+
const c6 = "abc" + "def";
31+
const c7 = true;
32+
const c8 = E.A;
33+
}
34+
35+
function f2(p1: 1 = 1, p2: "abc" = "abc", p3: true = true, p4: E.A = E.A) {
36+
var v1: 1 = 1;
37+
var v2: -123 = -123;
38+
var v3: "abc" = "abc";
39+
var v4: true = true;
40+
var v5: E.A = E.A;
41+
let x1: 1 = 1;
42+
let x2: -123 = -123;
43+
let x3: "abc" = "abc";
44+
let x4: true = true;
45+
let x5: E.A = E.A;
46+
}
47+
48+
function f3() {
49+
const c1 = cond ? 1 : 2;
50+
const c2 = cond ? 1 : "two";
51+
const c3 = cond ? E.A : cond ? true : 123;
52+
const c4 = cond ? "abc" : null;
53+
const c5 = cond ? 456 : undefined;
54+
const c6: { kind: 123 } = { kind: 123 };
55+
const c7: [1 | 2, "foo" | "bar"] = [1, "bar"];
56+
const c8 = cond ? c6 : cond ? c7 : "hello";
57+
let x1 = c1;
58+
let x2 = c2;
59+
let x3 = c3;
60+
let x4 = c4;
61+
let x5 = c5;
62+
let x6 = c6;
63+
let x7 = c7;
64+
let x8 = c8;
65+
}
66+
67+
class C1 {
68+
x1 = 1;
69+
x2 = -123;
70+
x3 = 3 + 4;
71+
x4 = "abc";
72+
x5 = "";
73+
x6 = "abc" + "def";
74+
x7 = true;
75+
x8 = E.A;
76+
readonly c1 = 1;
77+
readonly c2 = -123;
78+
readonly c3 = 3 + 4;
79+
readonly c4 = "abc";
80+
readonly c5 = "";
81+
readonly c6 = "abc" + "def";
82+
readonly c7 = true;
83+
readonly c8 = E.A;
84+
}
85+
86+
function f4() {
87+
const c1 = { a: 1, b: "foo" };
88+
const c2: { a : 0 | 1, b: "foo" | "bar" } = { a: 1, b: "foo" };
89+
let x1 = { a: 1, b: "foo" };
90+
let x2: { a : 0 | 1, b: "foo" | "bar" } = { a: 1, b: "foo" };
91+
}
92+
93+
function f5() {
94+
const c1 = [1, "foo"];
95+
const c2: (1 | "foo")[] = [1, "foo"];
96+
const c3: [1, "foo"] = [1, "foo"];
97+
let x1 = [1, "foo"];
98+
let x2: (1 | "foo")[] = [1, "foo"];
99+
let x3: [1, "foo"] = [1, "foo"];
100+
}
101+
102+
function f6() {
103+
const { c1 = true, c2 = 0, c3 = "foo" } = { c1: false, c2: 1, c3: "bar" };
104+
let { x1 = true, x2 = 0, x3 = "foo" } = { x1: false, x2: 1, x3: "bar" };
105+
}
106+
107+
function f10() {
108+
return "hello";
109+
}
110+
111+
function f11() {
112+
return cond ? 1 : "two";
113+
}
114+
115+
function f12() {
116+
if (cond) {
117+
return 1;
118+
}
119+
else {
120+
return "two";
121+
}
122+
}
123+
124+
class C2 {
125+
foo() {
126+
return 0;
127+
}
128+
bar() {
129+
return cond ? 0 : 1;
130+
}
131+
}
132+
133+
function f20() {
134+
const f1 = () => 0;
135+
const f2 = () => "hello";
136+
const f3 = () => true;
137+
const f4 = () => E.C;
138+
const f5 = (): "foo" => "foo";
139+
const f6: () => "foo" | "bar" = () => "bar";
140+
const f7: (() => "foo") | (() => "bar") = () => "bar";
141+
}
142+
143+
declare function g1<T>(x: T): T;
144+
declare function g2<T>(x: T, y: T): T;
145+
declare function g3<T, U>(x: T, y: U): T | U;
146+
declare function g4<T>(x: T): T[];
147+
declare function g5<T extends number>(x: T, y: T): T[];
148+
declare function g6<T>(x: T[]): T;
149+
declare function g7<T>(x: T[]): T[];
150+
declare function g8<T>(x: T, f: (p: T) => T): T;
151+
152+
const a: (1 | 2)[] = [1, 2];
153+
154+
const x1 = g1(1); // Type 1
155+
const x2 = g2(1, 1); // Type 1
156+
const x3 = g2(1, 2); // Type 1 | 2
157+
const x4 = g3(1, "two"); // Type 1 | "two"
158+
const x5 = g4(1); // Type number[]
159+
const x6 = g5(1, 2); // Type (1 | 2)[]
160+
const x7 = g6([1, 2]); // Type number
161+
const x8 = g6(a); // Type 1 | 2
162+
const x9 = g7(a); // Type (1 | 2)[]
163+
const x10 = g8(1, x => x); // Type number
164+
const x11 = g8(1, x => x + 1); // Type number
165+
166+
function makeArray<T>(x: T): T[] {
167+
return [x];
168+
}
169+
170+
function append<T>(a: T[], x: T): T[] {
171+
let result = a.slice();
172+
result.push(x);
173+
return result;
174+
}
175+
176+
type Bit = 0 | 1;
177+
178+
let aa = makeArray<Bit>(0);
179+
aa = append(aa, 1);
180+
181+
182+
//// [literalTypes2.js]
183+
var E;
184+
(function (E) {
185+
E[E["A"] = 0] = "A";
186+
E[E["B"] = 1] = "B";
187+
E[E["C"] = 2] = "C";
188+
})(E || (E = {}));
189+
var cond;
190+
function f1(p1, p2, p3, p4) {
191+
if (p1 === void 0) { p1 = 1; }
192+
if (p2 === void 0) { p2 = "abc"; }
193+
if (p3 === void 0) { p3 = true; }
194+
if (p4 === void 0) { p4 = E.A; }
195+
var v1 = 1;
196+
var v2 = -123;
197+
var v3 = 3 + 4;
198+
var v4 = "abc";
199+
var v5 = "";
200+
var v6 = "abc" + "def";
201+
var v7 = true;
202+
var v8 = E.A;
203+
var x1 = 1;
204+
var x2 = -123;
205+
var x3 = 3 + 4;
206+
var x4 = "abc";
207+
var x5 = "";
208+
var x6 = "abc" + "def";
209+
var x7 = true;
210+
var x8 = E.A;
211+
var c1 = 1;
212+
var c2 = -123;
213+
var c3 = 3 + 4;
214+
var c4 = "abc";
215+
var c5 = "";
216+
var c6 = "abc" + "def";
217+
var c7 = true;
218+
var c8 = E.A;
219+
}
220+
function f2(p1, p2, p3, p4) {
221+
if (p1 === void 0) { p1 = 1; }
222+
if (p2 === void 0) { p2 = "abc"; }
223+
if (p3 === void 0) { p3 = true; }
224+
if (p4 === void 0) { p4 = E.A; }
225+
var v1 = 1;
226+
var v2 = -123;
227+
var v3 = "abc";
228+
var v4 = true;
229+
var v5 = E.A;
230+
var x1 = 1;
231+
var x2 = -123;
232+
var x3 = "abc";
233+
var x4 = true;
234+
var x5 = E.A;
235+
}
236+
function f3() {
237+
var c1 = cond ? 1 : 2;
238+
var c2 = cond ? 1 : "two";
239+
var c3 = cond ? E.A : cond ? true : 123;
240+
var c4 = cond ? "abc" : null;
241+
var c5 = cond ? 456 : undefined;
242+
var c6 = { kind: 123 };
243+
var c7 = [1, "bar"];
244+
var c8 = cond ? c6 : cond ? c7 : "hello";
245+
var x1 = c1;
246+
var x2 = c2;
247+
var x3 = c3;
248+
var x4 = c4;
249+
var x5 = c5;
250+
var x6 = c6;
251+
var x7 = c7;
252+
var x8 = c8;
253+
}
254+
var C1 = (function () {
255+
function C1() {
256+
this.x1 = 1;
257+
this.x2 = -123;
258+
this.x3 = 3 + 4;
259+
this.x4 = "abc";
260+
this.x5 = "";
261+
this.x6 = "abc" + "def";
262+
this.x7 = true;
263+
this.x8 = E.A;
264+
this.c1 = 1;
265+
this.c2 = -123;
266+
this.c3 = 3 + 4;
267+
this.c4 = "abc";
268+
this.c5 = "";
269+
this.c6 = "abc" + "def";
270+
this.c7 = true;
271+
this.c8 = E.A;
272+
}
273+
return C1;
274+
}());
275+
function f4() {
276+
var c1 = { a: 1, b: "foo" };
277+
var c2 = { a: 1, b: "foo" };
278+
var x1 = { a: 1, b: "foo" };
279+
var x2 = { a: 1, b: "foo" };
280+
}
281+
function f5() {
282+
var c1 = [1, "foo"];
283+
var c2 = [1, "foo"];
284+
var c3 = [1, "foo"];
285+
var x1 = [1, "foo"];
286+
var x2 = [1, "foo"];
287+
var x3 = [1, "foo"];
288+
}
289+
function f6() {
290+
var _a = { c1: false, c2: 1, c3: "bar" }, _b = _a.c1, c1 = _b === void 0 ? true : _b, _c = _a.c2, c2 = _c === void 0 ? 0 : _c, _d = _a.c3, c3 = _d === void 0 ? "foo" : _d;
291+
var _e = { x1: false, x2: 1, x3: "bar" }, _f = _e.x1, x1 = _f === void 0 ? true : _f, _g = _e.x2, x2 = _g === void 0 ? 0 : _g, _h = _e.x3, x3 = _h === void 0 ? "foo" : _h;
292+
}
293+
function f10() {
294+
return "hello";
295+
}
296+
function f11() {
297+
return cond ? 1 : "two";
298+
}
299+
function f12() {
300+
if (cond) {
301+
return 1;
302+
}
303+
else {
304+
return "two";
305+
}
306+
}
307+
var C2 = (function () {
308+
function C2() {
309+
}
310+
C2.prototype.foo = function () {
311+
return 0;
312+
};
313+
C2.prototype.bar = function () {
314+
return cond ? 0 : 1;
315+
};
316+
return C2;
317+
}());
318+
function f20() {
319+
var f1 = function () { return 0; };
320+
var f2 = function () { return "hello"; };
321+
var f3 = function () { return true; };
322+
var f4 = function () { return E.C; };
323+
var f5 = function () { return "foo"; };
324+
var f6 = function () { return "bar"; };
325+
var f7 = function () { return "bar"; };
326+
}
327+
var a = [1, 2];
328+
var x1 = g1(1); // Type 1
329+
var x2 = g2(1, 1); // Type 1
330+
var x3 = g2(1, 2); // Type 1 | 2
331+
var x4 = g3(1, "two"); // Type 1 | "two"
332+
var x5 = g4(1); // Type number[]
333+
var x6 = g5(1, 2); // Type (1 | 2)[]
334+
var x7 = g6([1, 2]); // Type number
335+
var x8 = g6(a); // Type 1 | 2
336+
var x9 = g7(a); // Type (1 | 2)[]
337+
var x10 = g8(1, function (x) { return x; }); // Type number
338+
var x11 = g8(1, function (x) { return x + 1; }); // Type number
339+
function makeArray(x) {
340+
return [x];
341+
}
342+
function append(a, x) {
343+
var result = a.slice();
344+
result.push(x);
345+
return result;
346+
}
347+
var aa = makeArray(0);
348+
aa = append(aa, 1);

0 commit comments

Comments
 (0)