1
0
Fork 0
mirror of https://github.com/laravel-ls/protocol.git synced 2026-06-16 03:54:56 +02:00
protocol/workspace_test.go
2026-03-01 22:57:28 +01:00

29 lines
989 B
Go

package protocol_test
import (
"encoding/json"
"testing"
"github.com/laravel-ls/protocol"
)
func Test_Workspace_StructsUnmarshalValidJSON(t *testing.T) {
var ws protocol.WorkspaceEdit
if err := json.Unmarshal([]byte(`{
"changes":{"file:///tmp/main.go":[{"range":{"start":{"line":0,"character":0},"end":{"line":0,"character":0}},"newText":"package main\n"}]},
"changeAnnotations":{"a1":{"label":"Add package declaration","description":"Needed for file header","needsConfirmation":false}}
}`), &ws); err != nil {
t.Fatalf("unmarshal WorkspaceEdit failed: %v", err)
}
if len(ws.Changes) != 1 || len(ws.ChangeAnnotations) != 1 {
t.Fatalf("unexpected WorkspaceEdit: %+v", ws)
}
var folder protocol.WorkspaceFolder
if err := json.Unmarshal([]byte(`{"uri":"file:///workspace","name":"workspace"}`), &folder); err != nil {
t.Fatalf("unmarshal WorkspaceFolder failed: %v", err)
}
if folder.Name != "workspace" {
t.Fatalf("unexpected WorkspaceFolder: %+v", folder)
}
}