Skip to content

Commit

Permalink
Add tests
Browse files Browse the repository at this point in the history
  • Loading branch information
OliverJAsh committed Dec 18, 2024
1 parent 52717ac commit f6c6b4d
Show file tree
Hide file tree
Showing 10 changed files with 224 additions and 1 deletion.
12 changes: 11 additions & 1 deletion tests/baselines/reference/arrowFunctionErrorSpan.errors.txt
Original file line number Diff line number Diff line change
Expand Up @@ -19,9 +19,11 @@ arrowFunctionErrorSpan.ts(43,5): error TS2345: Argument of type '() => void' is
Type 'void' is not assignable to type 'number'.
arrowFunctionErrorSpan.ts(52,3): error TS2345: Argument of type '(_: any) => number' is not assignable to parameter of type '() => number'.
Target signature provides too few arguments. Expected 1 or more, but got 0.
arrowFunctionErrorSpan.ts(55,7): error TS2355: A function whose declared type is neither 'undefined', 'void', nor 'any' must return a value.
arrowFunctionErrorSpan.ts(57,17): error TS2322: Type 'string' is not assignable to type 'number'.


==== arrowFunctionErrorSpan.ts (11 errors) ====
==== arrowFunctionErrorSpan.ts (13 errors) ====
function f(a: () => number) { }

// oneliner
Expand Down Expand Up @@ -112,4 +114,12 @@ arrowFunctionErrorSpan.ts(52,3): error TS2345: Argument of type '(_: any) => num
~~~~~
!!! error TS2345: Argument of type '(_: any) => number' is not assignable to parameter of type '() => number'.
!!! error TS2345: Target signature provides too few arguments. Expected 1 or more, but got 0.

f((): number => { });
~~~~~~
!!! error TS2355: A function whose declared type is neither 'undefined', 'void', nor 'any' must return a value.

f((): number => '');
~~
!!! error TS2322: Type 'string' is not assignable to type 'number'.

6 changes: 6 additions & 0 deletions tests/baselines/reference/arrowFunctionErrorSpan.js
Original file line number Diff line number Diff line change
Expand Up @@ -54,6 +54,10 @@ f( // comment 1
// body is not a block
f(_ => 1 +
2);

f((): number => { });

f((): number => '');


//// [arrowFunctionErrorSpan.js]
Expand Down Expand Up @@ -91,3 +95,5 @@ function () {
// body is not a block
f(function (_) { return 1 +
2; });
f(function () { });
f(function () { return ''; });
6 changes: 6 additions & 0 deletions tests/baselines/reference/arrowFunctionErrorSpan.symbols
Original file line number Diff line number Diff line change
Expand Up @@ -81,3 +81,9 @@ f(_ => 1 +

2);

f((): number => { });
>f : Symbol(f, Decl(arrowFunctionErrorSpan.ts, 0, 0))

f((): number => '');
>f : Symbol(f, Decl(arrowFunctionErrorSpan.ts, 0, 0))

18 changes: 18 additions & 0 deletions tests/baselines/reference/arrowFunctionErrorSpan.types
Original file line number Diff line number Diff line change
Expand Up @@ -145,3 +145,21 @@ f(_ => 1 +
>2 : 2
> : ^

f((): number => { });
>f((): number => { }) : void
> : ^^^^
>f : (a: () => number) => void
> : ^ ^^ ^^^^^^^^^
>(): number => { } : () => number
> : ^^^^^^

f((): number => '');
>f((): number => '') : void
> : ^^^^
>f : (a: () => number) => void
> : ^ ^^ ^^^^^^^^^
>(): number => '' : () => number
> : ^^^^^^
>'' : ""
> : ^^

Original file line number Diff line number Diff line change
@@ -0,0 +1,41 @@
arrowFunctionReturnTypeErrorSpan.ts(2,7): error TS2451: Cannot redeclare block-scoped variable 'a'.
arrowFunctionReturnTypeErrorSpan.ts(3,3): error TS2322: Type 'string' is not assignable to type 'number'.
arrowFunctionReturnTypeErrorSpan.ts(6,7): error TS2451: Cannot redeclare block-scoped variable 'a'.
arrowFunctionReturnTypeErrorSpan.ts(7,10): error TS2304: Cannot find name 'missing'.
arrowFunctionReturnTypeErrorSpan.ts(11,25): error TS2322: Type 'string' is not assignable to type 'number'.
arrowFunctionReturnTypeErrorSpan.ts(14,28): error TS2322: Type 'string' is not assignable to type 'number'.
arrowFunctionReturnTypeErrorSpan.ts(16,25): error TS2304: Cannot find name 'missing'.


==== arrowFunctionReturnTypeErrorSpan.ts (7 errors) ====
// block body
const a = (): number => {
~
!!! error TS2451: Cannot redeclare block-scoped variable 'a'.
return "foo";
~~~~~~
!!! error TS2322: Type 'string' is not assignable to type 'number'.
};

const a = (): number => {
~
!!! error TS2451: Cannot redeclare block-scoped variable 'a'.
return missing;
~~~~~~~
!!! error TS2304: Cannot find name 'missing'.
};

// expression body
const b = (): number => "foo";
~~~~~
!!! error TS2322: Type 'string' is not assignable to type 'number'.

type F<T> = T;
const c = (): F<number> => "foo";
~~~~~
!!! error TS2322: Type 'string' is not assignable to type 'number'.

const d = (): number => missing;
~~~~~~~
!!! error TS2304: Cannot find name 'missing'.

33 changes: 33 additions & 0 deletions tests/baselines/reference/arrowFunctionReturnTypeErrorSpan.js
Original file line number Diff line number Diff line change
@@ -0,0 +1,33 @@
//// [tests/cases/compiler/arrowFunctionReturnTypeErrorSpan.ts] ////

//// [arrowFunctionReturnTypeErrorSpan.ts]
// block body
const a = (): number => {
return "foo";
};

const a = (): number => {
return missing;
};

// expression body
const b = (): number => "foo";

type F<T> = T;
const c = (): F<number> => "foo";

const d = (): number => missing;


//// [arrowFunctionReturnTypeErrorSpan.js]
// block body
var a = function () {
return "foo";
};
var a = function () {
return missing;
};
// expression body
var b = function () { return "foo"; };
var c = function () { return "foo"; };
var d = function () { return missing; };
32 changes: 32 additions & 0 deletions tests/baselines/reference/arrowFunctionReturnTypeErrorSpan.symbols
Original file line number Diff line number Diff line change
@@ -0,0 +1,32 @@
//// [tests/cases/compiler/arrowFunctionReturnTypeErrorSpan.ts] ////

=== arrowFunctionReturnTypeErrorSpan.ts ===
// block body
const a = (): number => {
>a : Symbol(a, Decl(arrowFunctionReturnTypeErrorSpan.ts, 1, 5))

return "foo";
};

const a = (): number => {
>a : Symbol(a, Decl(arrowFunctionReturnTypeErrorSpan.ts, 5, 5))

return missing;
};

// expression body
const b = (): number => "foo";
>b : Symbol(b, Decl(arrowFunctionReturnTypeErrorSpan.ts, 10, 5))

type F<T> = T;
>F : Symbol(F, Decl(arrowFunctionReturnTypeErrorSpan.ts, 10, 30))
>T : Symbol(T, Decl(arrowFunctionReturnTypeErrorSpan.ts, 12, 7))
>T : Symbol(T, Decl(arrowFunctionReturnTypeErrorSpan.ts, 12, 7))

const c = (): F<number> => "foo";
>c : Symbol(c, Decl(arrowFunctionReturnTypeErrorSpan.ts, 13, 5))
>F : Symbol(F, Decl(arrowFunctionReturnTypeErrorSpan.ts, 10, 30))

const d = (): number => missing;
>d : Symbol(d, Decl(arrowFunctionReturnTypeErrorSpan.ts, 15, 5))

57 changes: 57 additions & 0 deletions tests/baselines/reference/arrowFunctionReturnTypeErrorSpan.types
Original file line number Diff line number Diff line change
@@ -0,0 +1,57 @@
//// [tests/cases/compiler/arrowFunctionReturnTypeErrorSpan.ts] ////

=== arrowFunctionReturnTypeErrorSpan.ts ===
// block body
const a = (): number => {
>a : () => number
> : ^^^^^^
>(): number => { return "foo";} : () => number
> : ^^^^^^

return "foo";
>"foo" : "foo"
> : ^^^^^

};

const a = (): number => {
>a : () => number
> : ^^^^^^
>(): number => { return missing;} : () => number
> : ^^^^^^

return missing;
>missing : any
> : ^^^

};

// expression body
const b = (): number => "foo";
>b : () => number
> : ^^^^^^
>(): number => "foo" : () => number
> : ^^^^^^
>"foo" : "foo"
> : ^^^^^

type F<T> = T;
>F : T
> : ^

const c = (): F<number> => "foo";
>c : () => F<number>
> : ^^^^^^
>(): F<number> => "foo" : () => F<number>
> : ^^^^^^
>"foo" : "foo"
> : ^^^^^

const d = (): number => missing;
>d : () => number
> : ^^^^^^
>(): number => missing : () => number
> : ^^^^^^
>missing : any
> : ^^^

4 changes: 4 additions & 0 deletions tests/cases/compiler/arrowFunctionErrorSpan.ts
Original file line number Diff line number Diff line change
Expand Up @@ -51,3 +51,7 @@ f( // comment 1
// body is not a block
f(_ => 1 +
2);

f((): number => { });

f((): number => '');
16 changes: 16 additions & 0 deletions tests/cases/compiler/arrowFunctionReturnTypeErrorSpan.ts
Original file line number Diff line number Diff line change
@@ -0,0 +1,16 @@
// block body
const a = (): number => {
return "foo";
};

const a = (): number => {
return missing;
};

// expression body
const b = (): number => "foo";

type F<T> = T;
const c = (): F<number> => "foo";

const d = (): number => missing;

0 comments on commit f6c6b4d

Please sign in to comment.