Skip to content

Commit 876ca1a

Browse files
committed
stearm: add HeaderContentFmt testcases
1 parent 46d3281 commit 876ca1a

File tree

1 file changed

+46
-0
lines changed

1 file changed

+46
-0
lines changed

stream_test.go

Lines changed: 46 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,46 @@
1+
// Copyright 2019 The go-language-server Authors. All rights reserved.
2+
// Use of this source code is governed by a BSD-style
3+
// license that can be found in the LICENSE file.
4+
5+
package jsonrpc2
6+
7+
import (
8+
"fmt"
9+
"testing"
10+
11+
"github.com/google/go-cmp/cmp"
12+
)
13+
14+
func TestHeaderContentFmt(t *testing.T) {
15+
tests := []struct {
16+
name string
17+
header string
18+
want string
19+
}{
20+
{
21+
name: "ContentLength",
22+
header: fmt.Sprintf(HeaderContentLengthFmt, 512),
23+
want: "Content-Length: 512\r\n",
24+
},
25+
{
26+
name: "ContentType",
27+
header: fmt.Sprintf(HeaderContentTypeFmt, ContentTypeJSONRPC),
28+
want: "Content-Type: application/jsonrpc; charset=utf-8\r\n",
29+
},
30+
{
31+
name: "Both",
32+
header: fmt.Sprintf(HeaderContentLengthFmt+HeaderContentTypeFmt, 512, ContentTypeVSCodeJSONRPC),
33+
want: "Content-Length: 512\r\nContent-Type: application/vscode-jsonrpc; charset=utf-8\r\n",
34+
},
35+
}
36+
for _, tt := range tests {
37+
tt := tt
38+
t.Run(tt.name, func(t *testing.T) {
39+
t.Parallel()
40+
41+
if diff := cmp.Diff(tt.header, tt.want); diff != "" {
42+
t.Errorf("%s: (-got, +want)\n%s", tt.name, diff)
43+
}
44+
})
45+
}
46+
}

0 commit comments

Comments
 (0)