-
Notifications
You must be signed in to change notification settings - Fork 577
feat: add reference resolver tests #561
New issue
Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.
By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.
Already on GitHub? Sign in to your account
Open
SoulPancake
wants to merge
8
commits into
microsoft:main
Choose a base branch
from
SoulPancake:ab/reference-resolver-test
base: main
Could not load branches
Branch not found: {{ refName }}
Loading
Could not load tags
Nothing to show
Loading
Are you sure you want to change the base?
Some commits from the old base branch may be removed from the timeline,
and old review comments may become outdated.
Open
Changes from all commits
Commits
Show all changes
8 commits
Select commit
Hold shift + click to select a range
872ab1f
feat: test for reference resolver
SoulPancake 952f8cb
feat: remove idea files from cache and add to gitignore
SoulPancake 63ad817
fix: unexport const
SoulPancake a916d7b
Merge branch 'main' into ab/reference-resolver-test
SoulPancake 1691ee6
feat: push
SoulPancake f0ff384
Merge branch 'main' into ab/reference-resolver-test
SoulPancake e62d803
feat: call t.Parallel()
SoulPancake 834501d
Merge branch 'main' into ab/reference-resolver-test
SoulPancake File filter
Filter by extension
Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
There are no files selected for viewing
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,178 @@ | ||
package binder | ||
|
||
import ( | ||
"github.com/microsoft/typescript-go/internal/ast" | ||
"github.com/microsoft/typescript-go/internal/compiler/diagnostics" | ||
"gotest.tools/v3/assert" | ||
"testing" | ||
) | ||
|
||
const identifier = "some-identifier" | ||
|
||
func TestNewReferenceResolver(t *testing.T) { | ||
t.Parallel() | ||
hooks := ReferenceResolverHooks{} | ||
resolver := NewReferenceResolver(hooks) | ||
assert.Assert(t, resolver != nil) | ||
} | ||
|
||
func TestGetResolvedSymbol(t *testing.T) { | ||
t.Parallel() | ||
hooks := ReferenceResolverHooks{ | ||
GetResolvedSymbol: func(node *ast.Node) *ast.Symbol { | ||
return &ast.Symbol{} | ||
}, | ||
} | ||
resolver := NewReferenceResolver(hooks) | ||
node := &ast.Node{} | ||
symbol := resolver.(*referenceResolver).getResolvedSymbol(node) | ||
assert.Assert(t, symbol != nil) | ||
} | ||
|
||
func TestGetMergedSymbol(t *testing.T) { | ||
t.Parallel() | ||
hooks := ReferenceResolverHooks{ | ||
GetMergedSymbol: func(symbol *ast.Symbol) *ast.Symbol { | ||
return &ast.Symbol{} | ||
}, | ||
} | ||
resolver := NewReferenceResolver(hooks) | ||
symbol := &ast.Symbol{} | ||
mergedSymbol := resolver.(*referenceResolver).getMergedSymbol(symbol) | ||
assert.Assert(t, mergedSymbol != nil) | ||
} | ||
|
||
func TestGetParentOfSymbol(t *testing.T) { | ||
t.Parallel() | ||
hooks := ReferenceResolverHooks{ | ||
GetParentOfSymbol: func(symbol *ast.Symbol) *ast.Symbol { | ||
return &ast.Symbol{} | ||
}, | ||
} | ||
resolver := NewReferenceResolver(hooks) | ||
symbol := &ast.Symbol{} | ||
parentSymbol := resolver.(*referenceResolver).getParentOfSymbol(symbol) | ||
assert.Assert(t, parentSymbol != nil) | ||
} | ||
|
||
func TestGetSymbolOfDeclaration(t *testing.T) { | ||
t.Parallel() | ||
hooks := ReferenceResolverHooks{ | ||
GetSymbolOfDeclaration: func(declaration *ast.Declaration) *ast.Symbol { | ||
return &ast.Symbol{} | ||
}, | ||
} | ||
resolver := NewReferenceResolver(hooks) | ||
declaration := &ast.Declaration{} | ||
symbol := resolver.(*referenceResolver).getSymbolOfDeclaration(declaration) | ||
assert.Assert(t, symbol != nil) | ||
} | ||
|
||
func TestGetReferencedValueSymbol(t *testing.T) { | ||
t.Parallel() | ||
hooks := ReferenceResolverHooks{ | ||
ResolveName: func(location *ast.Node, name string, meaning ast.SymbolFlags, nameNotFoundMessage *diagnostics.Message, isUse bool, excludeGlobals bool) *ast.Symbol { | ||
return &ast.Symbol{} | ||
}, | ||
} | ||
resolver := NewReferenceResolver(hooks) | ||
|
||
nf := ast.NodeFactory{} | ||
reference := nf.NewIdentifier("sometext") | ||
symbol := resolver.(*referenceResolver).getReferencedValueSymbol(reference, false) | ||
assert.Assert(t, symbol != nil) | ||
} | ||
|
||
func TestIsTypeOnlyAliasDeclaration(t *testing.T) { | ||
t.Parallel() | ||
hooks := ReferenceResolverHooks{ | ||
GetTypeOnlyAliasDeclaration: func(symbol *ast.Symbol, include ast.SymbolFlags) *ast.Declaration { | ||
return &ast.Declaration{} | ||
}, | ||
} | ||
resolver := NewReferenceResolver(hooks) | ||
symbol := &ast.Symbol{} | ||
isTypeOnly := resolver.(*referenceResolver).isTypeOnlyAliasDeclaration(symbol) | ||
assert.Assert(t, isTypeOnly) | ||
} | ||
|
||
func TestGetDeclarationOfAliasSymbol(t *testing.T) { | ||
t.Parallel() | ||
resolver := NewReferenceResolver(ReferenceResolverHooks{}) | ||
symbol := &ast.Symbol{ | ||
Declarations: []*ast.Declaration{ | ||
{Kind: ast.KindImportEqualsDeclaration}, | ||
}, | ||
} | ||
declaration := resolver.(*referenceResolver).getDeclarationOfAliasSymbol(symbol) | ||
assert.Assert(t, declaration != nil) | ||
} | ||
|
||
func TestGetExportSymbolOfValueSymbolIfExported(t *testing.T) { | ||
t.Parallel() | ||
hooks := ReferenceResolverHooks{ | ||
GetExportSymbolOfValueSymbolIfExported: func(symbol *ast.Symbol) *ast.Symbol { | ||
return &ast.Symbol{} | ||
}, | ||
} | ||
resolver := NewReferenceResolver(hooks) | ||
symbol := &ast.Symbol{} | ||
exportSymbol := resolver.(*referenceResolver).getExportSymbolOfValueSymbolIfExported(symbol) | ||
assert.Assert(t, exportSymbol != nil) | ||
} | ||
|
||
func TestGetReferencedExportContainer(t *testing.T) { | ||
t.Parallel() | ||
hooks := ReferenceResolverHooks{ | ||
ResolveName: func(location *ast.Node, name string, meaning ast.SymbolFlags, nameNotFoundMessage *diagnostics.Message, isUse bool, excludeGlobals bool) *ast.Symbol { | ||
return &ast.Symbol{} | ||
}, | ||
} | ||
resolver := NewReferenceResolver(hooks) | ||
NF := ast.NodeFactory{} | ||
node := NF.NewIdentifier("sometext") | ||
container := resolver.GetReferencedExportContainer(node, false) | ||
assert.Assert(t, container == nil) | ||
} | ||
|
||
func TestGetReferencedImportDeclaration(t *testing.T) { | ||
t.Parallel() | ||
hooks := ReferenceResolverHooks{ | ||
ResolveName: func(location *ast.Node, name string, meaning ast.SymbolFlags, nameNotFoundMessage *diagnostics.Message, isUse bool, excludeGlobals bool) *ast.Symbol { | ||
return &ast.Symbol{} | ||
}, | ||
} | ||
resolver := NewReferenceResolver(hooks) | ||
NF := ast.NodeFactory{} | ||
node := NF.NewIdentifier("sometext") | ||
declaration := resolver.GetReferencedImportDeclaration(node) | ||
assert.Assert(t, declaration == nil) | ||
} | ||
|
||
func TestGetReferencedValueDeclaration(t *testing.T) { | ||
t.Parallel() | ||
hooks := ReferenceResolverHooks{ | ||
ResolveName: func(location *ast.Node, name string, meaning ast.SymbolFlags, nameNotFoundMessage *diagnostics.Message, isUse bool, excludeGlobals bool) *ast.Symbol { | ||
return &ast.Symbol{} | ||
}, | ||
} | ||
resolver := NewReferenceResolver(hooks) | ||
NF := ast.NodeFactory{} | ||
node := NF.NewIdentifier("sometext") | ||
declaration := resolver.GetReferencedValueDeclaration(node) | ||
assert.Assert(t, declaration == nil) | ||
} | ||
|
||
func TestGetReferencedValueDeclarations(t *testing.T) { | ||
t.Parallel() | ||
hooks := ReferenceResolverHooks{ | ||
ResolveName: func(location *ast.Node, name string, meaning ast.SymbolFlags, nameNotFoundMessage *diagnostics.Message, isUse bool, excludeGlobals bool) *ast.Symbol { | ||
return &ast.Symbol{} | ||
}, | ||
} | ||
resolver := NewReferenceResolver(hooks) | ||
NF := ast.NodeFactory{} | ||
node := NF.NewIdentifier(identifier) | ||
declarations := resolver.GetReferencedValueDeclarations(node) | ||
assert.Assert(t, len(declarations) == 0) | ||
} |
Add this suggestion to a batch that can be applied as a single commit.
This suggestion is invalid because no changes were made to the code.
Suggestions cannot be applied while the pull request is closed.
Suggestions cannot be applied while viewing a subset of changes.
Only one suggestion per line can be applied in a batch.
Add this suggestion to a batch that can be applied as a single commit.
Applying suggestions on deleted lines is not supported.
You must change the existing code in this line in order to create a valid suggestion.
Outdated suggestions cannot be applied.
This suggestion has been applied or marked resolved.
Suggestions cannot be applied from pending reviews.
Suggestions cannot be applied on multi-line comments.
Suggestions cannot be applied while the pull request is queued to merge.
Suggestion cannot be applied right now. Please check back later.
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
I can perhaps add a
//nolint:paralleltest