forked from bugst/go-lsp
-
Notifications
You must be signed in to change notification settings - Fork 1
/
lsp_basic_test.go
127 lines (117 loc) · 2.99 KB
/
lsp_basic_test.go
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
103
104
105
106
107
108
109
110
111
112
113
114
115
116
117
118
119
120
121
122
123
124
125
126
127
//
// Copyright 2024 Cristian Maglie. All rights reserved.
// Use of this source code is governed by a BSD-style
// license that can be found in the LICENSE file.
//
package lsp
import (
"testing"
"github.com/stretchr/testify/require"
"go.bug.st/json"
)
func TestDecodingProgressReports(t *testing.T) {
{
perc := 15.0
beginParam := &WorkDoneProgressBegin{
Title: "title",
Cancellable: true,
Message: "mesg",
Percentage: &perc,
}
beginJSON := `{
"cancellable" : true,
"kind" : "begin",
"message" : "mesg",
"percentage" : 15,
"title" : "title"
}`
beginData, err := json.Marshal(beginParam)
require.NoError(t, err)
require.JSONEq(t, beginJSON, string(beginData))
err = json.Unmarshal([]byte(beginJSON), &beginParam)
require.NoError(t, err)
}
{
beginJSON := `{
"token": "aaaa10292992929287172",
"value": {
"kind": "begin",
"title": "hello",
"cancellable": true
}
}`
r, err := DecodeServerNotificationParams("$/progress", json.RawMessage([]byte(beginJSON)))
require.NoError(t, err)
require.IsType(t, &ProgressParams{}, r)
pp := r.(*ProgressParams)
begin := pp.TryToDecodeWellKnownValues()
require.IsType(t, WorkDoneProgressBegin{}, begin)
require.Equal(t, "hello", begin.(WorkDoneProgressBegin).Title)
}
{
perc := 15.0
reportParam := &WorkDoneProgressReport{
Cancellable: true,
Message: "mesg",
Percentage: &perc,
}
reportJSON := `{
"cancellable" : true,
"kind" : "report",
"message" : "mesg",
"percentage" : 15
}`
reportData, err := json.Marshal(reportParam)
require.NoError(t, err)
require.JSONEq(t, reportJSON, string(reportData))
err = json.Unmarshal([]byte(reportJSON), &reportParam)
require.NoError(t, err)
}
{
reportJSON := `{
"token": "aaaa10292992929287172",
"value": {
"kind": "report",
"message": "hello",
"cancellable": true
}
}`
r, err := DecodeServerNotificationParams("$/progress", json.RawMessage([]byte(reportJSON)))
require.NoError(t, err)
require.IsType(t, &ProgressParams{}, r)
pp := r.(*ProgressParams)
report := pp.TryToDecodeWellKnownValues()
require.IsType(t, WorkDoneProgressReport{}, report)
require.Equal(t, "hello", report.(WorkDoneProgressReport).Message)
}
{
endParam := &WorkDoneProgressEnd{
Message: "mesg",
}
endJSON := `{
"kind" : "end",
"message" : "mesg"
}`
endData, err := json.Marshal(endParam)
require.NoError(t, err)
require.JSONEq(t, endJSON, string(endData))
err = json.Unmarshal([]byte(endJSON), &endParam)
require.NoError(t, err)
}
{
endJSON := `{
"token": "aaaa10292992929287172",
"value": {
"kind": "end",
"message": "bye"
}
}`
r, err := DecodeServerNotificationParams("$/progress", json.RawMessage([]byte(endJSON)))
require.NoError(t, err)
require.IsType(t, &ProgressParams{}, r)
pp := r.(*ProgressParams)
end := pp.TryToDecodeWellKnownValues()
require.IsType(t, WorkDoneProgressEnd{}, end)
require.Equal(t, "bye", end.(WorkDoneProgressEnd).Message)
}
}