Skip to content

Commit 91eb495

Browse files
Replace checker unit test with compiler diagnostic baselines
Co-authored-by: RyanCavanaugh <[email protected]>
1 parent e9f7e8c commit 91eb495

6 files changed

Lines changed: 92 additions & 38 deletions

File tree

‎tsc/internal/checker/checker_test.go‎

Lines changed: 0 additions & 27 deletions
Original file line numberDiff line numberDiff line change
@@ -11,7 +11,6 @@ import (
1111
"github.com/microsoft/TypeScript/tsc/internal/checker"
1212
"github.com/microsoft/TypeScript/tsc/internal/compiler"
1313
"github.com/microsoft/TypeScript/tsc/internal/core"
14-
"github.com/microsoft/TypeScript/tsc/internal/diagnostics"
1514
"github.com/microsoft/TypeScript/tsc/internal/repo"
1615
"github.com/microsoft/TypeScript/tsc/internal/tsoptions"
1716
"github.com/microsoft/TypeScript/tsc/internal/tspath"
@@ -63,32 +62,6 @@ foo.bar;`
6362
}
6463
}
6564

66-
func TestTypeArgumentConstraintDiagnosticWithHeadMessage(t *testing.T) {
67-
t.Parallel()
68-
69-
fs := bundled.WrapFS(vfstest.FromMap(map[string]string{
70-
"/foo.ts": `declare function f<T extends U, U>(): void;
71-
f<number, string>();`,
72-
"/tsconfig.json": `{"files":["foo.ts"]}`,
73-
}, tspath.CaseInsensitive))
74-
host := compiler.NewCompilerHost(fs, bundled.LibPath(), nil, nil, nil)
75-
parsed, errors := tsoptions.GetParsedCommandLineOfConfigFile("/tsconfig.json", &core.CompilerOptions{}, nil, tsoptions.NewDefaultParseConfigHost(fs), nil)
76-
assert.Equal(t, len(errors), 0)
77-
p := compiler.NewProgram(compiler.ProgramOptions{Config: parsed, Host: host})
78-
c, done := p.GetTypeChecker(t.Context())
79-
defer done()
80-
file := p.GetSourceFile("/foo.ts")
81-
call := file.Statements.Nodes[1].Expression()
82-
signature := c.GetSignaturesOfType(c.GetTypeAtLocation(call.Expression()), checker.SignatureKindCall)[0]
83-
diags := c.CheckTypeArgumentsForTest(signature, call.TypeArguments(), diagnostics.Unable_to_resolve_signature_of_class_decorator_when_called_as_an_expression)
84-
assert.Equal(t, len(diags), 1)
85-
assert.Equal(t, diags[0].Code(), diagnostics.Type_0_does_not_satisfy_the_constraint_1.Code())
86-
assert.DeepEqual(t, diags[0].MessageArgs(), []string{"number", "string"})
87-
assert.Assert(t, strings.Contains(diags[0].String(), "Type 'number' does not satisfy the constraint 'string'."))
88-
assert.Equal(t, len(diags[0].MessageChain()), 1)
89-
assert.Equal(t, diags[0].MessageChain()[0].Code(), diagnostics.Unable_to_resolve_signature_of_class_decorator_when_called_as_an_expression.Code())
90-
}
91-
9265
func TestGetTypeAtLocationOfTypeOnlyImportClause(t *testing.T) {
9366
t.Parallel()
9467

‎tsc/internal/checker/export_test.go‎

Lines changed: 0 additions & 11 deletions
This file was deleted.
Lines changed: 25 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,25 @@
1+
typeArgumentConstraintDiagnostic.ts(2,13): error TS2344: Type 'number' does not satisfy the constraint 'string'.
2+
typeArgumentConstraintDiagnostic.ts(5,11): error TS2344: Type 'number' does not satisfy the constraint 'string'.
3+
typeArgumentConstraintDiagnostic.ts(8,17): error TS2344: Type '{ value: number; }' does not satisfy the constraint '{ value: string; }'.
4+
Types of property 'value' are incompatible.
5+
Type 'number' is not assignable to type 'string'.
6+
7+
8+
==== typeArgumentConstraintDiagnostic.ts (3 errors) ====
9+
declare function constrained<T extends string>(): void;
10+
constrained<number>();
11+
~~~~~~
12+
!!! error TS2344: Type 'number' does not satisfy the constraint 'string'.
13+
14+
declare function dependent<T extends U, U>(): void;
15+
dependent<number, string>();
16+
~~~~~~
17+
!!! error TS2344: Type 'number' does not satisfy the constraint 'string'.
18+
19+
declare function dependentObject<T extends U, U>(): void;
20+
dependentObject<{ value: number }, { value: string }>();
21+
~~~~~~~~~~~~~~~~~
22+
!!! error TS2344: Type '{ value: number; }' does not satisfy the constraint '{ value: string; }'.
23+
!!! error TS2344: Types of property 'value' are incompatible.
24+
!!! error TS2344: Type 'number' is not assignable to type 'string'.
25+
Lines changed: 30 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,30 @@
1+
//// [tests/cases/compiler/typeArgumentConstraintDiagnostic.ts] ////
2+
3+
=== typeArgumentConstraintDiagnostic.ts ===
4+
declare function constrained<T extends string>(): void;
5+
>constrained : Symbol(constrained, Decl(typeArgumentConstraintDiagnostic.ts, 0, 0))
6+
>T : Symbol(T, Decl(typeArgumentConstraintDiagnostic.ts, 0, 29))
7+
8+
constrained<number>();
9+
>constrained : Symbol(constrained, Decl(typeArgumentConstraintDiagnostic.ts, 0, 0))
10+
11+
declare function dependent<T extends U, U>(): void;
12+
>dependent : Symbol(dependent, Decl(typeArgumentConstraintDiagnostic.ts, 1, 22))
13+
>T : Symbol(T, Decl(typeArgumentConstraintDiagnostic.ts, 3, 27))
14+
>U : Symbol(U, Decl(typeArgumentConstraintDiagnostic.ts, 3, 39))
15+
>U : Symbol(U, Decl(typeArgumentConstraintDiagnostic.ts, 3, 39))
16+
17+
dependent<number, string>();
18+
>dependent : Symbol(dependent, Decl(typeArgumentConstraintDiagnostic.ts, 1, 22))
19+
20+
declare function dependentObject<T extends U, U>(): void;
21+
>dependentObject : Symbol(dependentObject, Decl(typeArgumentConstraintDiagnostic.ts, 4, 28))
22+
>T : Symbol(T, Decl(typeArgumentConstraintDiagnostic.ts, 6, 33))
23+
>U : Symbol(U, Decl(typeArgumentConstraintDiagnostic.ts, 6, 45))
24+
>U : Symbol(U, Decl(typeArgumentConstraintDiagnostic.ts, 6, 45))
25+
26+
dependentObject<{ value: number }, { value: string }>();
27+
>dependentObject : Symbol(dependentObject, Decl(typeArgumentConstraintDiagnostic.ts, 4, 28))
28+
>value : Symbol(value, Decl(typeArgumentConstraintDiagnostic.ts, 7, 17))
29+
>value : Symbol(value, Decl(typeArgumentConstraintDiagnostic.ts, 7, 36))
30+
Lines changed: 26 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,26 @@
1+
//// [tests/cases/compiler/typeArgumentConstraintDiagnostic.ts] ////
2+
3+
=== typeArgumentConstraintDiagnostic.ts ===
4+
declare function constrained<T extends string>(): void;
5+
>constrained : <T extends string>() => void
6+
7+
constrained<number>();
8+
>constrained<number>() : void
9+
>constrained : <T extends string>() => void
10+
11+
declare function dependent<T extends U, U>(): void;
12+
>dependent : <T extends U, U>() => void
13+
14+
dependent<number, string>();
15+
>dependent<number, string>() : void
16+
>dependent : <T extends U, U>() => void
17+
18+
declare function dependentObject<T extends U, U>(): void;
19+
>dependentObject : <T extends U, U>() => void
20+
21+
dependentObject<{ value: number }, { value: string }>();
22+
>dependentObject<{ value: number }, { value: string }>() : void
23+
>dependentObject : <T extends U, U>() => void
24+
>value : number
25+
>value : string
26+
Lines changed: 11 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,11 @@
1+
// @strict: true
2+
// @noEmit: true
3+
4+
declare function constrained<T extends string>(): void;
5+
constrained<number>();
6+
7+
declare function dependent<T extends U, U>(): void;
8+
dependent<number, string>();
9+
10+
declare function dependentObject<T extends U, U>(): void;
11+
dependentObject<{ value: number }, { value: string }>();

0 commit comments

Comments
 (0)