mirror of
https://github.com/Myzel394/config-lsp.git
synced 2025-06-18 23:15:26 +02:00
76 lines
2.2 KiB
Go
76 lines
2.2 KiB
Go
package matchparser
|
|
|
|
import (
|
|
"config-lsp/common"
|
|
"testing"
|
|
)
|
|
|
|
func TestFullExample(
|
|
t *testing.T,
|
|
) {
|
|
input := "User alice,adam Address 192.168.1.1 Host *.example.com"
|
|
match := NewMatch()
|
|
errs := match.Parse(input, 0, 0)
|
|
|
|
if len(errs) > 0 {
|
|
t.Fatalf("Failed to parse match: %v", errs)
|
|
}
|
|
|
|
entry := match.GetEntryAtPosition(common.LSPCharacterAsCursorPosition(0))
|
|
if !(entry == match.Entries[0]) {
|
|
t.Errorf("Expected entry at 0 to be %v, but got %v", match.Entries[0], entry)
|
|
}
|
|
|
|
entry = match.GetEntryAtPosition(common.LSPCharacterAsCursorPosition(5))
|
|
if !(entry == match.Entries[0]) {
|
|
t.Errorf("Expected entry at 5 to be %v, but got %v", match.Entries[0], entry)
|
|
}
|
|
|
|
entry = match.GetEntryAtPosition(common.LSPCharacterAsCursorPosition(13))
|
|
if !(entry == match.Entries[0]) {
|
|
t.Errorf("Expected entry at 13 to be %v, but got %v", match.Entries[1], entry)
|
|
}
|
|
|
|
entry = match.GetEntryAtPosition(common.LSPCharacterAsCursorPosition(16))
|
|
if !(entry == match.Entries[1]) {
|
|
t.Errorf("Expected entry at 16 to be %v, but got %v", match.Entries[1], entry)
|
|
}
|
|
|
|
entry = match.GetEntryAtPosition(common.LSPCharacterAsCursorPosition(24))
|
|
if !(entry == match.Entries[1]) {
|
|
t.Errorf("Expected entry at 24 to be %v, but got %v", match.Entries[2], entry)
|
|
}
|
|
|
|
entry = match.GetEntryAtPosition(common.LSPCharacterAsCursorPosition(36))
|
|
if !(entry == match.Entries[2]) {
|
|
t.Errorf("Expected entry at 36 to be %v, but got %v", match.Entries[2], entry)
|
|
}
|
|
}
|
|
|
|
func TestGetEntryForIncompleteExample(
|
|
t *testing.T,
|
|
) {
|
|
input := "User "
|
|
match := NewMatch()
|
|
errs := match.Parse(input, 0, 0)
|
|
|
|
if len(errs) > 0 {
|
|
t.Fatalf("Failed to parse match: %v", errs)
|
|
}
|
|
|
|
entry := match.GetEntryAtPosition(common.LSPCharacterAsCursorPosition(0))
|
|
if !(entry == match.Entries[0]) {
|
|
t.Errorf("Expected entry at 0 to be %v, but got %v", match.Entries[0], entry)
|
|
}
|
|
|
|
entry = match.GetEntryAtPosition(common.LSPCharacterAsCursorPosition(4))
|
|
if !(entry == match.Entries[0]) {
|
|
t.Errorf("Expected entry at 4 to be %v, but got %v", match.Entries[0], entry)
|
|
}
|
|
|
|
entry = match.GetEntryAtPosition(common.LSPCharacterAsCursorPosition(5))
|
|
if !(entry == match.Entries[0]) {
|
|
t.Errorf("Expected entry at 5 to be %v, but got %v", match.Entries[0], entry)
|
|
}
|
|
}
|