Skip to content

Commit e6c676e

Browse files
Added tests and baselines
1 parent 8777657 commit e6c676e

5 files changed

+178
-2
lines changed

src/testRunner/unittests/convertToAsyncFunction.ts

Lines changed: 18 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -1039,12 +1039,28 @@ function res(result){
10391039
return 5;
10401040
}
10411041
1042+
function rej(reject): Response{
1043+
return reject;
1044+
}
1045+
`
1046+
);
1047+
1048+
_testConvertToAsyncFunction("convertToAsyncFunction_CatchFollowedByThenMismatchTypes02NoAnnotations", `
1049+
function [#|f|](){
1050+
return fetch("https://typescriptlang.org").then(res).catch(rej).then(res);
1051+
}
1052+
1053+
function res(result){
1054+
return 5;
1055+
}
1056+
10421057
function rej(reject){
10431058
return reject;
10441059
}
10451060
`
10461061
);
10471062

1063+
10481064
_testConvertToAsyncFunction("convertToAsyncFunction_CatchFollowedByThenMismatchTypes03", `
10491065
function [#|f|](){
10501066
return fetch("https://typescriptlang.org").then(res).catch(rej).then(res);
@@ -1075,11 +1091,11 @@ function [#|f|](){
10751091
return fetch("https://typescriptlang.org").then(res).catch(rej).then(res);
10761092
}
10771093
1078-
function res(result){
1094+
function res(result): b{
10791095
return {name: "myName", age: 22, color: "red"};
10801096
}
10811097
1082-
function rej(reject){
1098+
function rej(reject): a{
10831099
return {name: "myName", age: 27};
10841100
}
10851101
`
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,35 @@
1+
// ==ORIGINAL==
2+
3+
function /*[#|*/f/*|]*/(){
4+
return fetch("https://typescriptlang.org").then(res).catch(rej).then(res);
5+
}
6+
7+
function res(result){
8+
return 5;
9+
}
10+
11+
function rej(reject): Response{
12+
return reject;
13+
}
14+
15+
// ==ASYNC FUNCTION::Convert to async function==
16+
17+
async function f(){
18+
let result: number | Response;
19+
try {
20+
const result_1 = await fetch("https://typescriptlang.org");
21+
result = await res(result_1);
22+
}
23+
catch (reject) {
24+
result = await rej(reject);
25+
}
26+
return res(result);
27+
}
28+
29+
function res(result){
30+
return 5;
31+
}
32+
33+
function rej(reject): Response{
34+
return reject;
35+
}
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,35 @@
1+
// ==ORIGINAL==
2+
3+
function /*[#|*/f/*|]*/(){
4+
return fetch("https://typescriptlang.org").then(res).catch(rej).then(res);
5+
}
6+
7+
function res(result){
8+
return 5;
9+
}
10+
11+
function rej(reject){
12+
return reject;
13+
}
14+
15+
// ==ASYNC FUNCTION::Convert to async function==
16+
17+
async function f(){
18+
let result;
19+
try {
20+
const result_1 = await fetch("https://typescriptlang.org");
21+
result = await res(result_1);
22+
}
23+
catch (reject) {
24+
result = await rej(reject);
25+
}
26+
return res(result);
27+
}
28+
29+
function res(result){
30+
return 5;
31+
}
32+
33+
function rej(reject){
34+
return reject;
35+
}
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,35 @@
1+
// ==ORIGINAL==
2+
3+
function /*[#|*/f/*|]*/(){
4+
return fetch("https://typescriptlang.org").then(res).catch(rej).then(res);
5+
}
6+
7+
function res(result){
8+
return 5;
9+
}
10+
11+
function rej(reject){
12+
return reject;
13+
}
14+
15+
// ==ASYNC FUNCTION::Convert to async function==
16+
17+
async function f(){
18+
let result: any;
19+
try {
20+
const result_1 = await fetch("https://typescriptlang.org");
21+
result = await res(result_1);
22+
}
23+
catch (reject) {
24+
result = await rej(reject);
25+
}
26+
return res(result);
27+
}
28+
29+
function res(result){
30+
return 5;
31+
}
32+
33+
function rej(reject){
34+
return reject;
35+
}
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,55 @@
1+
// ==ORIGINAL==
2+
3+
interface a {
4+
name: string;
5+
age: number;
6+
}
7+
8+
interface b extends a {
9+
color: string;
10+
}
11+
12+
13+
function /*[#|*/f/*|]*/(){
14+
return fetch("https://typescriptlang.org").then(res).catch(rej).then(res);
15+
}
16+
17+
function res(result): b{
18+
return {name: "myName", age: 22, color: "red"};
19+
}
20+
21+
function rej(reject): a{
22+
return {name: "myName", age: 27};
23+
}
24+
25+
// ==ASYNC FUNCTION::Convert to async function==
26+
27+
interface a {
28+
name: string;
29+
age: number;
30+
}
31+
32+
interface b extends a {
33+
color: string;
34+
}
35+
36+
37+
async function f(){
38+
let result: a;
39+
try {
40+
const result_1 = await fetch("https://typescriptlang.org");
41+
result = await res(result_1);
42+
}
43+
catch (reject) {
44+
result = await rej(reject);
45+
}
46+
return res(result);
47+
}
48+
49+
function res(result): b{
50+
return {name: "myName", age: 22, color: "red"};
51+
}
52+
53+
function rej(reject): a{
54+
return {name: "myName", age: 27};
55+
}

0 commit comments

Comments
 (0)