mirror of
https://github.com/sourcegraph/jsonrpc2.git
synced 2026-06-16 04:04:56 +02:00
Split jsonrpc2.go file into multiple files (#65)
This merge request moves some of the contents from the jsonrpc2.go file into their own designated file. The new files being introduced (excluding test files) are as follows: * conn.go * request.go * response.go The motive of this change is to make it easier to navigate the code. Without this change, the jsonrpc2.go file is 813 lines of code.
This commit is contained in:
parent
028a50bb39
commit
846c29e96d
10 changed files with 1028 additions and 978 deletions
35
internal_test.go
Normal file
35
internal_test.go
Normal file
|
|
@ -0,0 +1,35 @@
|
|||
package jsonrpc2
|
||||
|
||||
import (
|
||||
"encoding/json"
|
||||
"testing"
|
||||
)
|
||||
|
||||
func TestAnyMessage(t *testing.T) {
|
||||
tests := map[string]struct {
|
||||
request, response, invalid bool
|
||||
}{
|
||||
// Single messages
|
||||
`{}`: {invalid: true},
|
||||
`{"foo":"bar"}`: {invalid: true},
|
||||
`{"method":"m"}`: {request: true},
|
||||
`{"result":123}`: {response: true},
|
||||
`{"result":null}`: {response: true},
|
||||
`{"error":{"code":456,"message":"m"}}`: {response: true},
|
||||
}
|
||||
for s, want := range tests {
|
||||
var m anyMessage
|
||||
if err := json.Unmarshal([]byte(s), &m); err != nil {
|
||||
if !want.invalid {
|
||||
t.Errorf("%s: error: %v", s, err)
|
||||
}
|
||||
continue
|
||||
}
|
||||
if (m.request != nil) != want.request {
|
||||
t.Errorf("%s: got request %v, want %v", s, m.request != nil, want.request)
|
||||
}
|
||||
if (m.response != nil) != want.response {
|
||||
t.Errorf("%s: got response %v, want %v", s, m.response != nil, want.response)
|
||||
}
|
||||
}
|
||||
}
|
||||
Loading…
Add table
Add a link
Reference in a new issue