Skip to content

Commit b6b8e8c

Browse files
committed
Add tests
1 parent 791ae5b commit b6b8e8c

File tree

4 files changed

+274
-0
lines changed

4 files changed

+274
-0
lines changed
Lines changed: 72 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,72 @@
1+
//// [ambientConstLiterals.ts]
2+
3+
function f<T>(x: T): T {
4+
return x;
5+
}
6+
7+
enum E { A, B, C }
8+
9+
const c1 = "abc";
10+
const c2 = 123;
11+
const c3 = c1;
12+
const c4 = c2;
13+
const c5 = f(123);
14+
const c6 = f(-123);
15+
const c7 = true;
16+
const c8 = E.A;
17+
const c9 = { x: "abc" };
18+
const c10 = [123];
19+
const c11 = "abc" + "def";
20+
const c12 = 123 + 456;
21+
const c13 = Math.random() > 0.5 ? "abc" : "def";
22+
const c14 = Math.random() > 0.5 ? 123 : 456;
23+
24+
//// [ambientConstLiterals.js]
25+
function f(x) {
26+
return x;
27+
}
28+
var E;
29+
(function (E) {
30+
E[E["A"] = 0] = "A";
31+
E[E["B"] = 1] = "B";
32+
E[E["C"] = 2] = "C";
33+
})(E || (E = {}));
34+
var c1 = "abc";
35+
var c2 = 123;
36+
var c3 = c1;
37+
var c4 = c2;
38+
var c5 = f(123);
39+
var c6 = f(-123);
40+
var c7 = true;
41+
var c8 = E.A;
42+
var c9 = { x: "abc" };
43+
var c10 = [123];
44+
var c11 = "abc" + "def";
45+
var c12 = 123 + 456;
46+
var c13 = Math.random() > 0.5 ? "abc" : "def";
47+
var c14 = Math.random() > 0.5 ? 123 : 456;
48+
49+
50+
//// [ambientConstLiterals.d.ts]
51+
declare function f<T>(x: T): T;
52+
declare enum E {
53+
A = 0,
54+
B = 1,
55+
C = 2,
56+
}
57+
declare const c1 = "abc";
58+
declare const c2 = 123;
59+
declare const c3 = "abc";
60+
declare const c4 = 123;
61+
declare const c5 = 123;
62+
declare const c6 = -123;
63+
declare const c7: boolean;
64+
declare const c8: E;
65+
declare const c9: {
66+
x: string;
67+
};
68+
declare const c10: number[];
69+
declare const c11: string;
70+
declare const c12: number;
71+
declare const c13: string;
72+
declare const c14: number;
Lines changed: 75 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,75 @@
1+
=== tests/cases/compiler/ambientConstLiterals.ts ===
2+
3+
function f<T>(x: T): T {
4+
>f : Symbol(f, Decl(ambientConstLiterals.ts, 0, 0))
5+
>T : Symbol(T, Decl(ambientConstLiterals.ts, 1, 11))
6+
>x : Symbol(x, Decl(ambientConstLiterals.ts, 1, 14))
7+
>T : Symbol(T, Decl(ambientConstLiterals.ts, 1, 11))
8+
>T : Symbol(T, Decl(ambientConstLiterals.ts, 1, 11))
9+
10+
return x;
11+
>x : Symbol(x, Decl(ambientConstLiterals.ts, 1, 14))
12+
}
13+
14+
enum E { A, B, C }
15+
>E : Symbol(E, Decl(ambientConstLiterals.ts, 3, 1))
16+
>A : Symbol(E.A, Decl(ambientConstLiterals.ts, 5, 8))
17+
>B : Symbol(E.B, Decl(ambientConstLiterals.ts, 5, 11))
18+
>C : Symbol(E.C, Decl(ambientConstLiterals.ts, 5, 14))
19+
20+
const c1 = "abc";
21+
>c1 : Symbol(c1, Decl(ambientConstLiterals.ts, 7, 5))
22+
23+
const c2 = 123;
24+
>c2 : Symbol(c2, Decl(ambientConstLiterals.ts, 8, 5))
25+
26+
const c3 = c1;
27+
>c3 : Symbol(c3, Decl(ambientConstLiterals.ts, 9, 5))
28+
>c1 : Symbol(c1, Decl(ambientConstLiterals.ts, 7, 5))
29+
30+
const c4 = c2;
31+
>c4 : Symbol(c4, Decl(ambientConstLiterals.ts, 10, 5))
32+
>c2 : Symbol(c2, Decl(ambientConstLiterals.ts, 8, 5))
33+
34+
const c5 = f(123);
35+
>c5 : Symbol(c5, Decl(ambientConstLiterals.ts, 11, 5))
36+
>f : Symbol(f, Decl(ambientConstLiterals.ts, 0, 0))
37+
38+
const c6 = f(-123);
39+
>c6 : Symbol(c6, Decl(ambientConstLiterals.ts, 12, 5))
40+
>f : Symbol(f, Decl(ambientConstLiterals.ts, 0, 0))
41+
42+
const c7 = true;
43+
>c7 : Symbol(c7, Decl(ambientConstLiterals.ts, 13, 5))
44+
45+
const c8 = E.A;
46+
>c8 : Symbol(c8, Decl(ambientConstLiterals.ts, 14, 5))
47+
>E.A : Symbol(E.A, Decl(ambientConstLiterals.ts, 5, 8))
48+
>E : Symbol(E, Decl(ambientConstLiterals.ts, 3, 1))
49+
>A : Symbol(E.A, Decl(ambientConstLiterals.ts, 5, 8))
50+
51+
const c9 = { x: "abc" };
52+
>c9 : Symbol(c9, Decl(ambientConstLiterals.ts, 15, 5))
53+
>x : Symbol(x, Decl(ambientConstLiterals.ts, 15, 12))
54+
55+
const c10 = [123];
56+
>c10 : Symbol(c10, Decl(ambientConstLiterals.ts, 16, 5))
57+
58+
const c11 = "abc" + "def";
59+
>c11 : Symbol(c11, Decl(ambientConstLiterals.ts, 17, 5))
60+
61+
const c12 = 123 + 456;
62+
>c12 : Symbol(c12, Decl(ambientConstLiterals.ts, 18, 5))
63+
64+
const c13 = Math.random() > 0.5 ? "abc" : "def";
65+
>c13 : Symbol(c13, Decl(ambientConstLiterals.ts, 19, 5))
66+
>Math.random : Symbol(Math.random, Decl(lib.d.ts, --, --))
67+
>Math : Symbol(Math, Decl(lib.d.ts, --, --), Decl(lib.d.ts, --, --))
68+
>random : Symbol(Math.random, Decl(lib.d.ts, --, --))
69+
70+
const c14 = Math.random() > 0.5 ? 123 : 456;
71+
>c14 : Symbol(c14, Decl(ambientConstLiterals.ts, 20, 5))
72+
>Math.random : Symbol(Math.random, Decl(lib.d.ts, --, --))
73+
>Math : Symbol(Math, Decl(lib.d.ts, --, --), Decl(lib.d.ts, --, --))
74+
>random : Symbol(Math.random, Decl(lib.d.ts, --, --))
75+
Lines changed: 105 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,105 @@
1+
=== tests/cases/compiler/ambientConstLiterals.ts ===
2+
3+
function f<T>(x: T): T {
4+
>f : <T>(x: T) => T
5+
>T : T
6+
>x : T
7+
>T : T
8+
>T : T
9+
10+
return x;
11+
>x : T
12+
}
13+
14+
enum E { A, B, C }
15+
>E : E
16+
>A : E.A
17+
>B : E.B
18+
>C : E.C
19+
20+
const c1 = "abc";
21+
>c1 : "abc"
22+
>"abc" : "abc"
23+
24+
const c2 = 123;
25+
>c2 : 123
26+
>123 : 123
27+
28+
const c3 = c1;
29+
>c3 : "abc"
30+
>c1 : "abc"
31+
32+
const c4 = c2;
33+
>c4 : 123
34+
>c2 : 123
35+
36+
const c5 = f(123);
37+
>c5 : 123
38+
>f(123) : 123
39+
>f : <T>(x: T) => T
40+
>123 : 123
41+
42+
const c6 = f(-123);
43+
>c6 : -123
44+
>f(-123) : -123
45+
>f : <T>(x: T) => T
46+
>-123 : -123
47+
>123 : 123
48+
49+
const c7 = true;
50+
>c7 : true
51+
>true : true
52+
53+
const c8 = E.A;
54+
>c8 : E.A
55+
>E.A : E.A
56+
>E : typeof E
57+
>A : E.A
58+
59+
const c9 = { x: "abc" };
60+
>c9 : { x: string; }
61+
>{ x: "abc" } : { x: string; }
62+
>x : string
63+
>"abc" : "abc"
64+
65+
const c10 = [123];
66+
>c10 : number[]
67+
>[123] : number[]
68+
>123 : 123
69+
70+
const c11 = "abc" + "def";
71+
>c11 : string
72+
>"abc" + "def" : string
73+
>"abc" : "abc"
74+
>"def" : "def"
75+
76+
const c12 = 123 + 456;
77+
>c12 : number
78+
>123 + 456 : number
79+
>123 : 123
80+
>456 : 456
81+
82+
const c13 = Math.random() > 0.5 ? "abc" : "def";
83+
>c13 : "abc" | "def"
84+
>Math.random() > 0.5 ? "abc" : "def" : "abc" | "def"
85+
>Math.random() > 0.5 : boolean
86+
>Math.random() : number
87+
>Math.random : () => number
88+
>Math : Math
89+
>random : () => number
90+
>0.5 : 0.5
91+
>"abc" : "abc"
92+
>"def" : "def"
93+
94+
const c14 = Math.random() > 0.5 ? 123 : 456;
95+
>c14 : 123 | 456
96+
>Math.random() > 0.5 ? 123 : 456 : 123 | 456
97+
>Math.random() > 0.5 : boolean
98+
>Math.random() : number
99+
>Math.random : () => number
100+
>Math : Math
101+
>random : () => number
102+
>0.5 : 0.5
103+
>123 : 123
104+
>456 : 456
105+
Lines changed: 22 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,22 @@
1+
// @declaration: true
2+
3+
function f<T>(x: T): T {
4+
return x;
5+
}
6+
7+
enum E { A, B, C }
8+
9+
const c1 = "abc";
10+
const c2 = 123;
11+
const c3 = c1;
12+
const c4 = c2;
13+
const c5 = f(123);
14+
const c6 = f(-123);
15+
const c7 = true;
16+
const c8 = E.A;
17+
const c9 = { x: "abc" };
18+
const c10 = [123];
19+
const c11 = "abc" + "def";
20+
const c12 = 123 + 456;
21+
const c13 = Math.random() > 0.5 ? "abc" : "def";
22+
const c14 = Math.random() > 0.5 ? 123 : 456;

0 commit comments

Comments
 (0)