mirror of
https://github.com/laravel-ls/protocol.git
synced 2026-06-18 13:00:03 +02:00
add tests
This commit is contained in:
parent
5049160990
commit
be37cd5a53
20 changed files with 755 additions and 1 deletions
42
document_change_operation_test.go
Normal file
42
document_change_operation_test.go
Normal file
|
|
@ -0,0 +1,42 @@
|
|||
package protocol_test
|
||||
|
||||
import (
|
||||
"encoding/json"
|
||||
"testing"
|
||||
|
||||
"github.com/laravel-ls/protocol"
|
||||
)
|
||||
|
||||
func Test_DocumentChangeOperation_StructsUnmarshalValidJSON(t *testing.T) {
|
||||
var op protocol.ResourceOperation
|
||||
if err := json.Unmarshal([]byte(`{"kind":"create","annotationId":"a1"}`), &op); err != nil {
|
||||
t.Fatalf("unmarshal ResourceOperation failed: %v", err)
|
||||
}
|
||||
if op.Kind != "create" {
|
||||
t.Fatalf("unexpected ResourceOperation: %+v", op)
|
||||
}
|
||||
|
||||
var create protocol.CreateFile
|
||||
if err := json.Unmarshal([]byte(`{"kind":"create","uri":"file:///tmp/new.go","options":{"overwrite":true}}`), &create); err != nil {
|
||||
t.Fatalf("unmarshal CreateFile failed: %v", err)
|
||||
}
|
||||
if create.Options == nil || !create.Options.Overwrite {
|
||||
t.Fatalf("unexpected CreateFile: %+v", create)
|
||||
}
|
||||
|
||||
var rename protocol.RenameFile
|
||||
if err := json.Unmarshal([]byte(`{"kind":"rename","oldUri":"file:///tmp/a.go","newUri":"file:///tmp/b.go","options":{"ignoreIfExists":true}}`), &rename); err != nil {
|
||||
t.Fatalf("unmarshal RenameFile failed: %v", err)
|
||||
}
|
||||
if rename.Options == nil || !rename.Options.IgnoreIfExists {
|
||||
t.Fatalf("unexpected RenameFile: %+v", rename)
|
||||
}
|
||||
|
||||
var del protocol.DeleteFile
|
||||
if err := json.Unmarshal([]byte(`{"kind":"delete","uri":"file:///tmp/old.go","options":{"recursive":true,"ignoreIfNotExists":true}}`), &del); err != nil {
|
||||
t.Fatalf("unmarshal DeleteFile failed: %v", err)
|
||||
}
|
||||
if del.Options == nil || !del.Options.Recursive || !del.Options.IgnoreIfNotExists {
|
||||
t.Fatalf("unexpected DeleteFile: %+v", del)
|
||||
}
|
||||
}
|
||||
Loading…
Add table
Add a link
Reference in a new issue