mirror of
https://github.com/Myzel394/config-lsp.git
synced 2025-06-18 23:15:26 +02:00
commit
3ebdc848e8
26
.github/workflows/pr-tests.yaml
vendored
Normal file
26
.github/workflows/pr-tests.yaml
vendored
Normal file
@ -0,0 +1,26 @@
|
||||
name: Run Go tests
|
||||
|
||||
on: [pull_request]
|
||||
|
||||
jobs:
|
||||
build:
|
||||
runs-on: ubuntu-latest
|
||||
strategy:
|
||||
matrix:
|
||||
go-version: [ '1.22.x' ]
|
||||
|
||||
steps:
|
||||
- uses: actions/checkout@v4
|
||||
- name: Setup Go ${{ matrix.go-version }}
|
||||
uses: actions/setup-go@v5
|
||||
with:
|
||||
go-version: ${{ matrix.go-version }}
|
||||
# You can test your matrix by printing the current Go version
|
||||
- name: Display Go version
|
||||
run: go version
|
||||
|
||||
- name: Get dependencies
|
||||
run: go mod download
|
||||
|
||||
- name: Run tests
|
||||
run: go test -v ./...
|
121
handlers/fstab/fstab_test.go
Normal file
121
handlers/fstab/fstab_test.go
Normal file
@ -0,0 +1,121 @@
|
||||
package fstab
|
||||
|
||||
import (
|
||||
fstabdocumentation "config-lsp/handlers/fstab/documentation"
|
||||
"config-lsp/utils"
|
||||
"testing"
|
||||
)
|
||||
|
||||
var sampleValidBasicExample = `
|
||||
LABEL=test /mnt/test ext4 defaults 0 0
|
||||
`
|
||||
var sampleInvalidOptionsExample = `
|
||||
LABEL=test /mnt/test btrfs subvol=backup,fat=32 0 0
|
||||
`
|
||||
|
||||
func TestValidBasicExample(t *testing.T) {
|
||||
// Arrange
|
||||
parser := FstabParser{}
|
||||
|
||||
errors := parser.ParseFromContent(sampleValidBasicExample)
|
||||
|
||||
if len(errors) > 0 {
|
||||
t.Fatal("ParseFromContent failed with error", errors)
|
||||
}
|
||||
|
||||
// Get hover for first field
|
||||
entry := parser.entries[0]
|
||||
|
||||
println("Getting hover info")
|
||||
{
|
||||
hover, err := getHoverInfo(&entry, uint32(0))
|
||||
|
||||
if err != nil {
|
||||
t.Fatal("getHoverInfo failed with error", err)
|
||||
}
|
||||
|
||||
if hover.Contents != SpecHoverField.Contents {
|
||||
t.Fatal("getHoverInfo failed to return correct hover content. Got:", hover.Contents, "but expected:", SpecHoverField.Contents)
|
||||
}
|
||||
|
||||
// Get hover for second field
|
||||
hover, err = getHoverInfo(&entry, uint32(11))
|
||||
if err != nil {
|
||||
t.Fatal("getHoverInfo failed with error", err)
|
||||
}
|
||||
|
||||
if hover.Contents != MountPointHoverField.Contents {
|
||||
t.Fatal("getHoverInfo failed to return correct hover content. Got:", hover.Contents, "but expected:", MountPointHoverField.Contents)
|
||||
}
|
||||
|
||||
hover, err = getHoverInfo(&entry, uint32(20))
|
||||
|
||||
if err != nil {
|
||||
t.Fatal("getHoverInfo failed with error", err)
|
||||
}
|
||||
|
||||
if hover.Contents != MountPointHoverField.Contents {
|
||||
t.Fatal("getHoverInfo failed to return correct hover content. Got:", hover.Contents, "but expected:", MountPointHoverField.Contents)
|
||||
}
|
||||
}
|
||||
|
||||
println("Getting completions")
|
||||
{
|
||||
completions, err := getCompletion(entry.Line, uint32(0))
|
||||
|
||||
if err != nil {
|
||||
t.Fatal("getCompletion failed with error", err)
|
||||
}
|
||||
|
||||
if len(completions) != 4 {
|
||||
t.Fatal("getCompletion failed to return correct number of completions. Got:", len(completions), "but expected:", 4)
|
||||
}
|
||||
|
||||
if completions[0].Label != "UUID" {
|
||||
t.Fatal("getCompletion failed to return correct label. Got:", completions[0].Label, "but expected:", "UUID")
|
||||
}
|
||||
}
|
||||
|
||||
{
|
||||
completions, err := getCompletion(entry.Line, uint32(21))
|
||||
|
||||
if err != nil {
|
||||
t.Fatal("getCompletion failed with error", err)
|
||||
}
|
||||
|
||||
expectedLength := len(utils.KeysOfMap(fstabdocumentation.MountOptionsMapField))
|
||||
if len(completions) != expectedLength {
|
||||
t.Fatal("getCompletion failed to return correct number of completions. Got:", len(completions), "but expected:", expectedLength)
|
||||
}
|
||||
}
|
||||
|
||||
println("Checking values")
|
||||
{
|
||||
diagnostics := parser.AnalyzeValues()
|
||||
|
||||
if len(diagnostics) > 0 {
|
||||
t.Fatal("AnalyzeValues failed with error", diagnostics)
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
func TestInvalidOptionsExample(t *testing.T) {
|
||||
// Arrange
|
||||
parser := FstabParser{}
|
||||
|
||||
errors := parser.ParseFromContent(sampleInvalidOptionsExample)
|
||||
|
||||
if len(errors) > 0 {
|
||||
t.Fatal("ParseFromContent returned error", errors)
|
||||
}
|
||||
|
||||
// Get hover for first field
|
||||
println("Checking values")
|
||||
{
|
||||
diagnostics := parser.AnalyzeValues()
|
||||
|
||||
if len(diagnostics) == 0 {
|
||||
t.Fatal("AnalyzeValues should have returned error")
|
||||
}
|
||||
}
|
||||
}
|
@ -21,8 +21,20 @@ func TextDocumentCompletion(context *glsp.Context, params *protocol.CompletionPa
|
||||
), nil
|
||||
}
|
||||
|
||||
if entry.Type == FstabEntryTypeComment {
|
||||
return nil, nil
|
||||
}
|
||||
|
||||
cursor := params.Position.Character
|
||||
line := entry.Line
|
||||
|
||||
return getCompletion(line, cursor)
|
||||
}
|
||||
|
||||
func getCompletion(
|
||||
line FstabLine,
|
||||
cursor uint32,
|
||||
) ([]protocol.CompletionItem, error) {
|
||||
targetField := line.GetFieldAtPosition(cursor)
|
||||
|
||||
switch targetField {
|
||||
|
@ -26,6 +26,10 @@ func TextDocumentHover(context *glsp.Context, params *protocol.HoverParams) (*pr
|
||||
return nil, nil
|
||||
}
|
||||
|
||||
return getHoverInfo(entry, cursor)
|
||||
}
|
||||
|
||||
func getHoverInfo(entry *FstabEntry, cursor uint32) (*protocol.Hover, error) {
|
||||
line := entry.Line
|
||||
targetField := line.GetFieldAtPosition(cursor)
|
||||
|
||||
|
@ -27,7 +27,7 @@ func (v DataAmountValue) CheckIsValid(value string) []*docvalues.InvalidValue {
|
||||
if !dataAmountCheckPattern.MatchString(value) {
|
||||
return []*docvalues.InvalidValue{
|
||||
{
|
||||
Err: InvalidDataAmountError{},
|
||||
Err: InvalidDataAmountError{},
|
||||
Start: 0,
|
||||
End: uint32(len(value)),
|
||||
},
|
||||
|
@ -29,7 +29,7 @@ func (v TimeFormatValue) CheckIsValid(value string) []*docvalues.InvalidValue {
|
||||
if !timeFormatCheckPattern.MatchString(value) {
|
||||
return []*docvalues.InvalidValue{
|
||||
{
|
||||
Err: InvalidTimeFormatError{},
|
||||
Err: InvalidTimeFormatError{},
|
||||
Start: 0,
|
||||
End: uint32(len(value)),
|
||||
},
|
||||
|
@ -28,7 +28,7 @@ type FatalFileNotReadableError struct {
|
||||
}
|
||||
|
||||
func (e FatalFileNotReadableError) Error() string {
|
||||
return fmt.Sprint("Fatal error! config-lsp was unable to read the file (%s); error: %s", e.FileURI, e.Err.Error())
|
||||
return fmt.Sprintf("Fatal error! config-lsp was unable to read the file (%s); error: %s", e.FileURI, e.Err.Error())
|
||||
}
|
||||
|
||||
type UnsupportedLanguageError struct {
|
||||
@ -36,7 +36,7 @@ type UnsupportedLanguageError struct {
|
||||
}
|
||||
|
||||
func (e UnsupportedLanguageError) Error() string {
|
||||
return fmt.Sprint("Language '%s' is not supported. Choose one of: %s", e.SuggestedLanguage, strings.Join(AllSupportedLanguages, ", "))
|
||||
return fmt.Sprintf("Language '%s' is not supported. Choose one of: %s", e.SuggestedLanguage, strings.Join(AllSupportedLanguages, ", "))
|
||||
}
|
||||
|
||||
type LanguageUndetectableError struct{}
|
||||
|
Loading…
x
Reference in New Issue
Block a user