@@ -55,17 +55,16 @@ func TestBatchFraming(t *testing.T) {
5555
5656func TestIOConnRead (t * testing.T ) {
5757 tests := []struct {
58- name string
59- input string
60- want string
58+ name string
59+ input string
60+ want string
61+ protocolVersion string
6162 }{
62-
6363 {
6464 name : "valid json input" ,
6565 input : `{"jsonrpc":"2.0","id":1,"method":"test","params":{}}` ,
6666 want : "" ,
6767 },
68-
6968 {
7069 name : "newline at the end of first valid json input" ,
7170 input : `{"jsonrpc":"2.0","id":1,"method":"test","params":{}}
@@ -77,13 +76,41 @@ func TestIOConnRead(t *testing.T) {
7776 input : `{"jsonrpc":"2.0","id":1,"method":"test","params":{}},` ,
7877 want : "invalid trailing data at the end of stream" ,
7978 },
79+ {
80+ name : "batching unknown protocol" ,
81+ input : `[{"jsonrpc":"2.0","id":1,"method":"test1"},{"jsonrpc":"2.0","id":2,"method":"test2"}]` ,
82+ want : "" ,
83+ protocolVersion : "" ,
84+ },
85+ {
86+ name : "batching old protocol" ,
87+ input : `[{"jsonrpc":"2.0","id":1,"method":"test1"},{"jsonrpc":"2.0","id":2,"method":"test2"}]` ,
88+ want : "" ,
89+ protocolVersion : protocolVersion20241105 ,
90+ },
91+ {
92+ name : "batching new protocol" ,
93+ input : `[{"jsonrpc":"2.0","id":1,"method":"test1"},{"jsonrpc":"2.0","id":2,"method":"test2"}]` ,
94+ want : "JSON-RPC batching is not supported in 2025-06-18 and later (request version: 2025-06-18)" ,
95+ protocolVersion : protocolVersion20250618 ,
96+ },
8097 }
8198 for _ , tt := range tests {
8299 t .Run (tt .name , func (t * testing.T ) {
83100 tr := newIOConn (rwc {
84101 rc : io .NopCloser (strings .NewReader (tt .input )),
85102 })
103+ if tt .protocolVersion != "" {
104+ tr .sessionUpdated (ServerSessionState {
105+ InitializeParams : & InitializeParams {
106+ ProtocolVersion : tt .protocolVersion ,
107+ },
108+ })
109+ }
86110 _ , err := tr .Read (context .Background ())
111+ if err == nil && tt .want != "" {
112+ t .Errorf ("ioConn.Read() got nil error but wanted %v" , tt .want )
113+ }
87114 if err != nil && err .Error () != tt .want {
88115 t .Errorf ("ioConn.Read() = %v, want %v" , err .Error (), tt .want )
89116 }
0 commit comments