Skip to content

Commit

Permalink
Add a test for Ref's JSON serialization.
Browse files Browse the repository at this point in the history
  • Loading branch information
korfuri committed Jul 17, 2017
1 parent 25e46fc commit ab82b21
Showing 1 changed file with 41 additions and 0 deletions.
41 changes: 41 additions & 0 deletions ref_test.go
Original file line number Diff line number Diff line change
@@ -0,0 +1,41 @@
package goref_test

import (
"encoding/json"
"testing"

"github.com/korfuri/goref"
"github.com/stretchr/testify/assert"
)

func TestJSON(t *testing.T) {
correct := "{\"from\":{\"position\":{\"filename\":\"x/foo.go\",\"start_line\":42,\"end_line\":42,\"end_col\":10},\"package\":\"path/to/x\",\"ident\":\"foo\"},\"to\":{\"position\":{\"filename\":\"y/bar.go\",\"start_line\":314,\"start_col\":11,\"end_line\":314,\"end_col\":14},\"package\":\"path/to/y\",\"ident\":\"bar\"}}"
r := goref.Ref{
RefType: goref.Instantiation,
FromPosition: goref.Position{
File: "x/foo.go",
PosC: 0,
PosL: 42,
EndC: 10,
EndL: 42,
},
ToPosition: goref.Position{
File: "y/bar.go",
PosC: 11,
PosL: 314,
EndC: 14,
EndL: 314,
},
FromIdent: "foo",
ToIdent: "bar",
FromPackage: &goref.Package{
Path: "path/to/x",
},
ToPackage: &goref.Package{
Path: "path/to/y",
},
}
j, err := json.Marshal(r)
assert.NoError(t, err)
assert.Equal(t, correct, string(j))
}

0 comments on commit ab82b21

Please sign in to comment.