mirror of
https://github.com/Myzel394/config-lsp.git
synced 2025-06-19 07:25:27 +02:00
chore(aliases): Add more tests
This commit is contained in:
parent
d56eef43bf
commit
40a570809d
@ -12,7 +12,7 @@ import (
|
|||||||
func GetDefinitionLocationForValue(
|
func GetDefinitionLocationForValue(
|
||||||
i indexes.AliasesIndexes,
|
i indexes.AliasesIndexes,
|
||||||
value ast.AliasValueInterface,
|
value ast.AliasValueInterface,
|
||||||
params *protocol.DefinitionParams,
|
documentURI string,
|
||||||
) []protocol.Location {
|
) []protocol.Location {
|
||||||
switch value.(type) {
|
switch value.(type) {
|
||||||
case ast.AliasValueUser:
|
case ast.AliasValueUser:
|
||||||
@ -22,7 +22,7 @@ func GetDefinitionLocationForValue(
|
|||||||
if entry, found := i.Keys[indexes.NormalizeKey(userValue.Value)]; found {
|
if entry, found := i.Keys[indexes.NormalizeKey(userValue.Value)]; found {
|
||||||
return []protocol.Location{
|
return []protocol.Location{
|
||||||
{
|
{
|
||||||
URI: params.TextDocument.URI,
|
URI: documentURI,
|
||||||
Range: entry.Key.Location.ToLSPRange(),
|
Range: entry.Key.Location.ToLSPRange(),
|
||||||
},
|
},
|
||||||
}
|
}
|
||||||
|
54
handlers/aliases/handlers/go_to_definition_test.go
Normal file
54
handlers/aliases/handlers/go_to_definition_test.go
Normal file
@ -0,0 +1,54 @@
|
|||||||
|
package handlers
|
||||||
|
|
||||||
|
import (
|
||||||
|
"config-lsp/handlers/aliases/ast"
|
||||||
|
"config-lsp/handlers/aliases/indexes"
|
||||||
|
"config-lsp/utils"
|
||||||
|
"testing"
|
||||||
|
)
|
||||||
|
|
||||||
|
func TestGoToDefinitionSimpleExample(
|
||||||
|
t *testing.T,
|
||||||
|
) {
|
||||||
|
input := utils.Dedent(`
|
||||||
|
alice: root
|
||||||
|
bob: root
|
||||||
|
steve: alice@example.com, bob
|
||||||
|
david: alice
|
||||||
|
`)
|
||||||
|
parser := ast.NewAliasesParser()
|
||||||
|
errors := parser.Parse(input)
|
||||||
|
|
||||||
|
if len(errors) > 0 {
|
||||||
|
t.Fatalf("Unexpected errors: %v", errors)
|
||||||
|
}
|
||||||
|
|
||||||
|
i, errors := indexes.CreateIndexes(parser)
|
||||||
|
|
||||||
|
if len(errors) > 0 {
|
||||||
|
t.Fatalf("Expected no errors, but got: %v", errors)
|
||||||
|
}
|
||||||
|
|
||||||
|
rawEntry, _ := parser.Aliases.Get(uint32(3))
|
||||||
|
entry := rawEntry.(*ast.AliasEntry)
|
||||||
|
rawValue := entry.Values.Values[0]
|
||||||
|
value := rawValue.(ast.AliasValueUser)
|
||||||
|
|
||||||
|
locations := GetDefinitionLocationForValue(
|
||||||
|
i,
|
||||||
|
value,
|
||||||
|
"file:///etc/aliases",
|
||||||
|
)
|
||||||
|
|
||||||
|
if !(len(locations) == 1) {
|
||||||
|
t.Errorf("Expected 1 location, but got %v", len(locations))
|
||||||
|
}
|
||||||
|
|
||||||
|
if !(locations[0].URI == "file:///etc/aliases") {
|
||||||
|
t.Errorf("Unexpected location: %v", locations[0])
|
||||||
|
}
|
||||||
|
|
||||||
|
if !(locations[0].Range.Start.Line == 0 && locations[0].Range.Start.Character == 0 && locations[0].Range.End.Line == 0 && locations[0].Range.End.Character == 5) {
|
||||||
|
t.Errorf("Unexpected location: %v", locations[0])
|
||||||
|
}
|
||||||
|
}
|
@ -7,7 +7,7 @@ import (
|
|||||||
"testing"
|
"testing"
|
||||||
)
|
)
|
||||||
|
|
||||||
func TestComplexExample(
|
func TestRenameSimpleExample(
|
||||||
t *testing.T,
|
t *testing.T,
|
||||||
) {
|
) {
|
||||||
input := utils.Dedent(`
|
input := utils.Dedent(`
|
||||||
|
@ -32,7 +32,7 @@ func TextDocumentDefinition(context *glsp.Context, params *protocol.DefinitionPa
|
|||||||
return handlers.GetDefinitionLocationForValue(
|
return handlers.GetDefinitionLocationForValue(
|
||||||
*d.Indexes,
|
*d.Indexes,
|
||||||
*rawValue,
|
*rawValue,
|
||||||
params,
|
params.TextDocument.URI,
|
||||||
), nil
|
), nil
|
||||||
}
|
}
|
||||||
|
|
||||||
|
Loading…
x
Reference in New Issue
Block a user