-
Notifications
You must be signed in to change notification settings - Fork 16
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
- Loading branch information
Showing
3 changed files
with
83 additions
and
9 deletions.
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
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
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,75 @@ | ||
package protocol | ||
|
||
import ( | ||
"fmt" | ||
"path/filepath" | ||
"testing" | ||
|
||
"go.lsp.dev/uri" | ||
|
||
"github.com/stretchr/testify/assert" | ||
) | ||
|
||
func TestHoverResultsWithFiles_Format(t *testing.T) { | ||
rootURI := uri.New("file:///home/user/project") | ||
|
||
results := HoverResultsWithFiles{ | ||
{Value: "value1", URI: uri.New("file:///home/user/project/file1.yaml")}, | ||
{Value: "value2", URI: uri.New("file:///home/user/project/file2.yaml")}, | ||
{Value: "value3", URI: uri.New("file:///home/user/project/file3.yaml")}, | ||
} | ||
|
||
expected := `### file3.yaml | ||
value3 | ||
### file2.yaml | ||
value2 | ||
### file1.yaml | ||
value1 | ||
` | ||
|
||
formatted := results.Format(rootURI) | ||
assert.Equal(t, expected, formatted, "The formatted output should match the expected output") | ||
} | ||
|
||
func TestHoverResultsWithFiles_Format_EmptyValue(t *testing.T) { | ||
rootURI := uri.New("file:///home/user/project") | ||
|
||
results := HoverResultsWithFiles{ | ||
{Value: "", URI: uri.New("file:///home/user/project/file1.yaml")}, | ||
} | ||
expected := `### file1.yaml | ||
"" | ||
` | ||
|
||
formatted := results.Format(rootURI) | ||
assert.Equal(t, expected, formatted, "The formatted output should match the expected output") | ||
} | ||
|
||
func TestHoverResultsWithFiles_Format_DifferenPath(t *testing.T) { | ||
rootURI := uri.New("file:///home/user/project") | ||
|
||
results := HoverResultsWithFiles{ | ||
{Value: "value", URI: uri.New("file:///invalid/uri")}, | ||
} | ||
|
||
expected := fmt.Sprintf(`### %s | ||
value | ||
`, filepath.Join("..", "..", "..", "invalid", "uri")) | ||
formatted := results.Format(rootURI) | ||
assert.Equal(t, expected, formatted, "The formatted output should match the expected output") | ||
} | ||
|
||
func TestHoverResultWithFile_WithHelmCode(t *testing.T) { | ||
hoverResult := HoverResultWithFile{ | ||
Value: "some helm code", | ||
URI: uri.New("file:///home/user/project/file1.yaml"), | ||
}.AsHelmCode() | ||
|
||
expectedValue := "```helm\nsome helm code\n```" | ||
assert.Equal(t, expectedValue, hoverResult.Value, "The value should be formatted with Helm code block") | ||
} |