本文整理汇总了Golang中kythe/io/kythe/go/test/testutil.DeepEqual函数的典型用法代码示例。如果您正苦于以下问题:Golang DeepEqual函数的具体用法?Golang DeepEqual怎么用?Golang DeepEqual使用的例子?那么恭喜您, 这里精选的函数代码示例或许可以为您提供帮助。
在下文中一共展示了DeepEqual函数的15个代码示例,这些例子默认根据受欢迎程度排序。您可以为喜欢或者感觉有用的代码点赞,您的评价将有助于系统推荐出更棒的Golang代码示例。
示例1: TestNodes
func TestNodes(t *testing.T) {
st := tbl.Construct(t)
for _, node := range tbl.Nodes {
reply, err := st.Nodes(ctx, &xpb.NodesRequest{
Ticket: []string{node.Ticket},
})
testutil.FatalOnErrT(t, "NodesRequest error: %v", err)
if len(reply.Nodes) != 1 {
t.Fatalf("Expected 1 node for %q; found %d: {%v}", node.Ticket, len(reply.Nodes), reply)
} else if err := testutil.DeepEqual(nodeInfo(node), reply.Nodes[node.Ticket]); err != nil {
t.Fatal(err)
}
}
var tickets []string
expected := make(map[string]*xpb.NodeInfo)
for _, n := range tbl.Nodes {
tickets = append(tickets, n.Ticket)
expected[n.Ticket] = nodeInfo(n)
}
reply, err := st.Nodes(ctx, &xpb.NodesRequest{Ticket: tickets})
testutil.FatalOnErrT(t, "NodesRequest error: %v", err)
if err := testutil.DeepEqual(expected, reply.Nodes); err != nil {
t.Fatal(err)
}
}
示例2: TestDecorationsRefs
func TestDecorationsRefs(t *testing.T) {
d := tbl.Decorations[1]
st := tbl.Construct(t)
reply, err := st.Decorations(ctx, &xpb.DecorationsRequest{
Location: &xpb.Location{Ticket: d.File.Ticket},
References: true,
Filter: []string{"**"},
})
testutil.FatalOnErrT(t, "DecorationsRequest error: %v", err)
if len(reply.SourceText) != 0 {
t.Errorf("Unexpected source text: %q", string(reply.SourceText))
}
if reply.Encoding != "" {
t.Errorf("Unexpected encoding: %q", reply.Encoding)
}
expected := refs(xrefs.NewNormalizer(d.File.Text), d.Decoration)
if err := testutil.DeepEqual(expected, reply.Reference); err != nil {
t.Fatal(err)
}
expectedNodes := nodeInfos(tbl.Nodes[9:11], tbl.Nodes[12:13])
if err := testutil.DeepEqual(expectedNodes, reply.Nodes); err != nil {
t.Fatal(err)
}
}
示例3: TestDecorations
func TestDecorations(t *testing.T) {
xs := newService(t, testEntries)
reply, err := xs.Decorations(ctx, &xpb.DecorationsRequest{
Location: &xpb.Location{
Ticket: kytheuri.ToString(testFileVName),
},
SourceText: true,
References: true,
Filter: []string{"**"},
})
if err != nil {
t.Fatalf("Error fetching decorations for %+v: %v", testFileVName, err)
}
if string(reply.SourceText) != testFileContent {
t.Errorf("Incorrect file content: %q; Expected: %q", string(reply.SourceText), testFileContent)
}
if reply.Encoding != testFileEncoding {
t.Errorf("Incorrect file encoding: %q; Expected: %q", reply.Encoding, testFileEncoding)
}
expectedRefs := []*xpb.DecorationsReply_Reference{
{
SourceTicket: kytheuri.ToString(testAnchorVName),
TargetTicket: kytheuri.ToString(testAnchorTargetVName),
Kind: schema.RefEdge,
AnchorStart: &xpb.Location_Point{
ByteOffset: 1,
LineNumber: 1,
ColumnOffset: 1,
},
AnchorEnd: &xpb.Location_Point{
ByteOffset: 4,
LineNumber: 1,
ColumnOffset: 4,
},
},
}
if err := testutil.DeepEqual(sortRefs(expectedRefs), sortRefs(reply.Reference)); err != nil {
t.Error(err)
}
expectedNodes := nodesToInfos(testNodes[4:6])
if err := testutil.DeepEqual(expectedNodes, sortInfos(reply.Node)); err != nil {
t.Error(err)
}
}
示例4: TestReducer_EmptySplit
func TestReducer_EmptySplit(t *testing.T) {
expectedPivot := testNode("blah", "test", "subkind", "input")
// Input for a single node (pivot header only)
in := testInput([]*ipb.Path{{
Pivot: expectedPivot,
}})
var found *ipb.Path_Node
out, err := reduce.Sort(ctx, in, &Reducer{
Func: func(ctx context.Context, pivot *ipb.Path_Node, rio ReducerIO) error {
sortKey, p, err := rio.Next()
if err != io.EOF {
t.Errorf("Unexpected return values: %q %v %v", sortKey, p, err)
}
if found != nil {
t.Errorf("Already found pivot: %v", found)
}
found = pivot
return nil
},
})
if err != nil {
t.Fatal(err)
}
if err := testutil.DeepEqual(expectedPivot, found); err != nil {
t.Error(err)
}
if s, err := out.NextSplit(); err != io.EOF {
t.Fatalf("Unexpected output/err: %v / %v", s, err)
}
}
示例5: TestParseOrdinal
func TestParseOrdinal(t *testing.T) {
type ordinalTest struct { // fields exported for the comparator
Input, Kind string
Ordinal int
HasOrdinal bool
}
tests := []ordinalTest{
{"/kythe/edge/defines", "/kythe/edge/defines", 0, false},
{"/kythe/edge/kind.here", "/kythe/edge/kind.here", 0, false},
{"/kythe/edge/kind1", "/kythe/edge/kind1", 0, false},
{"kind.-1", "kind.-1", 0, false},
{"kind.3", "kind", 3, true},
{"/kythe/edge/param.0", "/kythe/edge/param", 0, true},
{"/kythe/edge/param.1", "/kythe/edge/param", 1, true},
{"%/kythe/edge/param.1", "%/kythe/edge/param", 1, true},
{"/kythe/edge/kind.1930", "/kythe/edge/kind", 1930, true},
}
for _, test := range tests {
kind, ord, ok := ParseOrdinal(test.Input)
if err := testutil.DeepEqual(test, ordinalTest{
Input: test.Input,
Kind: kind,
Ordinal: ord,
HasOrdinal: ok,
}); err != nil {
t.Errorf("ParseOrdinal(%q): %v", test.Input, err)
}
}
}
示例6: TestEdgesMultiPage
func TestEdgesMultiPage(t *testing.T) {
tests := []struct {
Ticket string
Kinds []string
EdgeSet *srvpb.PagedEdgeSet
Pages []*srvpb.EdgePage
}{{
Ticket: tbl.EdgeSets[1].Source.Ticket,
EdgeSet: tbl.EdgeSets[1],
Pages: []*srvpb.EdgePage{tbl.EdgePages[1], tbl.EdgePages[2]},
}}
st := tbl.Construct(t)
for _, test := range tests {
reply, err := st.Edges(ctx, &xpb.EdgesRequest{
Ticket: []string{test.Ticket},
Kind: test.Kinds,
})
testutil.FatalOnErrT(t, "EdgesRequest error: %v", err)
if len(reply.Nodes) > 0 {
t.Errorf("Received unexpected nodes in EdgesReply: {%v}", reply)
}
if reply.NextPageToken != "" {
t.Errorf("Received unexpected next_page_token in EdgesReply: {%v}", reply)
}
if len(reply.EdgeSets) != 1 {
t.Errorf("Expected 1 EdgeSet in EdgesReply; found %d: {%v}", len(reply.EdgeSets), reply)
}
expected := edgeSet(test.Kinds, test.EdgeSet, test.Pages)
if err := testutil.DeepEqual(expected, reply.EdgeSets[test.Ticket]); err != nil {
t.Error(err)
}
if err := testutil.DeepEqual(map[string]int64{
"%/kythe/edge/defines/binding": 1,
"%/kythe/edge/ref": 2,
"someEdgeKind": 2,
"anotherEdge": 1,
}, reply.TotalEdgesByKind); err != nil {
t.Error(err)
}
}
}
示例7: TestAppendEntry
func TestAppendEntry(t *testing.T) {
tests := []struct {
entries []*spb.Entry
expected *ipb.Source
}{{
entries: []*spb.Entry{fact("fact", "value")},
expected: &ipb.Source{
Facts: map[string][]byte{"fact": []byte("value")},
},
}, {
entries: []*spb.Entry{edge("kind", "target")},
expected: &ipb.Source{
EdgeGroups: map[string]*ipb.Source_EdgeGroup{
"kind": {
Edges: []*ipb.Source_Edge{{Ticket: "kythe:#target"}},
},
},
},
}, {
entries: []*spb.Entry{
fact("kind", "first"),
fact("kind", "second"),
edge("edgeKind", "firstTarget"),
edge("edgeKind", "secondTarget"),
fact("blah", "blah"),
},
expected: &ipb.Source{
Facts: map[string][]byte{
"kind": []byte("second"),
"blah": []byte("blah"),
},
EdgeGroups: map[string]*ipb.Source_EdgeGroup{
"edgeKind": &ipb.Source_EdgeGroup{
Edges: []*ipb.Source_Edge{{
Ticket: "kythe:#firstTarget",
}, {
Ticket: "kythe:#secondTarget",
}},
},
},
},
}}
for i, test := range tests {
src := &ipb.Source{
Facts: make(map[string][]byte),
EdgeGroups: make(map[string]*ipb.Source_EdgeGroup),
}
for _, e := range test.entries {
AppendEntry(src, e)
}
if err := testutil.DeepEqual(test.expected, src); err != nil {
t.Errorf("tests[%d] error: %v", i, err)
}
}
}
示例8: TestEdges
func TestEdges(t *testing.T) {
xs := newService(t, testEntries)
reply, err := xs.Edges(ctx, &gpb.EdgesRequest{
Ticket: nodesToTickets(testNodes),
Filter: []string{"**"}, // every fact
})
if err != nil {
t.Fatalf("Error fetching edges for %+v: %v", nodesToTickets(testNodes), err)
}
expectedEdges := nodesToEdgeSets(testNodes)
if err := testutil.DeepEqual(expectedEdges, sortEdgeSets(reply.EdgeSets)); err != nil {
t.Error(err)
}
nodesWithEdges := testNodes[1:]
expectedInfos := nodesToInfos(nodesWithEdges)
if err := testutil.DeepEqual(expectedInfos, reply.Nodes); err != nil {
t.Error(err)
}
}
示例9: TestNodes
func TestNodes(t *testing.T) {
xs := newService(t, testEntries)
reply, err := xs.Nodes(ctx, &xpb.NodesRequest{
Ticket: nodesToTickets(testNodes),
})
if err != nil {
t.Fatalf("Error fetching nodes for %+v: %v", nodesToTickets(testNodes), err)
}
expected := nodesToInfos(testNodes)
if err := testutil.DeepEqual(expected, sortInfos(reply.Node)); err != nil {
t.Fatal(err)
}
}
示例10: TestDecorationsDirtyBuffer
func TestDecorationsDirtyBuffer(t *testing.T) {
d := tbl.Decorations[1]
st := tbl.Construct(t)
dirty := []byte(`(defn map [f coll]
(if (seq coll)
[]
(cons (f (first coll)) (map f (rest coll)))))
`)
reply, err := st.Decorations(ctx, &xpb.DecorationsRequest{
Location: &xpb.Location{Ticket: d.FileTicket},
DirtyBuffer: dirty,
References: true,
Filter: []string{"**"},
})
testutil.FatalOnErrT(t, "DecorationsRequest error: %v", err)
if len(reply.SourceText) != 0 {
t.Errorf("Unexpected source text: %q", string(d.SourceText))
}
if reply.Encoding != "" {
t.Errorf("Unexpected encoding: %q", d.Encoding)
}
p := xrefs.NewPatcher(d.SourceText, dirty)
norm := xrefs.NewNormalizer(dirty)
var expected []*xpb.DecorationsReply_Reference
for _, d := range d.Decoration {
if _, _, exists := p.Patch(d.Anchor.StartOffset, d.Anchor.EndOffset); exists {
expected = append(expected, decorationToReference(norm, d))
}
}
if !reflect.DeepEqual(expected, reply.Reference) {
t.Fatalf("Expected references %v; found %v", expected, reply.Reference)
}
// These are a subset of the anchor nodes in tbl.Decorations[1]. tbl.Nodes[10] is missing because
// it is the target of an anchor in the edited region.
expectedNodes := nodeInfos([]*srvpb.Node{tbl.Nodes[9], tbl.Nodes[12]})
sort.Sort(byNodeTicket(expectedNodes))
sort.Sort(byNodeTicket(reply.Node))
if err := testutil.DeepEqual(expectedNodes, reply.Node); err != nil {
t.Fatal(err)
}
}
示例11: TestJSONReader
func TestJSONReader(t *testing.T) {
r := testJSONBuffer(testEntries)
var i int
if err := NewJSONReader(r)(func(e *spb.Entry) error {
if err := testutil.DeepEqual(testEntries[i], e); err != nil {
t.Errorf("testEntries[%d]: %v", i, err)
}
i++
return nil
}); err != nil {
t.Fatal(err)
}
if i != len(testEntries) {
t.Fatalf("Missing %d entries", len(testEntries)-i)
}
}
示例12: TestParseOrdinal
func TestParseOrdinal(t *testing.T) {
tests := []OrdinalTest{
{"/kythe/edge/defines", "/kythe/edge/defines", 0, false},
{"/kythe/edge/kind.here", "/kythe/edge/kind.here", 0, false},
{"/kythe/edge/kind1", "/kythe/edge/kind1", 0, false},
{"kind.-1", "kind.-1", 0, false},
{"kind.3", "kind", 3, true},
{"/kythe/edge/param.0", "/kythe/edge/param", 0, true},
{"/kythe/edge/param.1", "/kythe/edge/param", 1, true},
{"%/kythe/edge/param.1", "%/kythe/edge/param", 1, true},
{"/kythe/edge/kind.1930", "/kythe/edge/kind", 1930, true},
}
for _, test := range tests {
kind, ord, ok := ParseOrdinal(test.Input)
if err := testutil.DeepEqual(&test, &OrdinalTest{test.Input, kind, ord, ok}); err != nil {
t.Error(err)
}
}
}
示例13: TestEdgesLastPage
func TestEdgesLastPage(t *testing.T) {
tests := [][]string{
nil, // all kinds
{"%/kythe/edge/ref"},
{"%/kythe/edge/defines/binding"},
}
ticket := tbl.EdgeSets[1].Source.Ticket
es := tbl.EdgeSets[1]
pages := []*srvpb.EdgePage{tbl.EdgePages[1], tbl.EdgePages[2]}
st := tbl.Construct(t)
for _, kinds := range tests {
reply, err := st.Edges(ctx, &xpb.EdgesRequest{
Ticket: []string{ticket},
Kind: kinds,
})
testutil.FatalOnErrT(t, "EdgesRequest error: %v", err)
if len(reply.Nodes) > 0 {
t.Errorf("Received unexpected nodes in EdgesReply: {%v}", reply)
}
if reply.NextPageToken != "" {
t.Errorf("Received unexpected next_page_token in EdgesReply: {%v}", reply)
}
if len(reply.EdgeSets) != 1 {
t.Fatalf("Expected 1 EdgeSet in EdgesReply; found %d: {%v}", len(reply.EdgeSets), reply)
}
expected := edgeSet(kinds, es, pages)
if err := testutil.DeepEqual(expected, reply.EdgeSets[ticket]); err != nil {
t.Error(err)
}
}
}
示例14: TestCrossReferences
func TestCrossReferences(t *testing.T) {
ticket := "kythe://someCorpus?lang=otpl#signature"
st := tbl.Construct(t)
reply, err := st.CrossReferences(ctx, &xpb.CrossReferencesRequest{
Ticket: []string{ticket},
DefinitionKind: xpb.CrossReferencesRequest_BINDING_DEFINITIONS,
ReferenceKind: xpb.CrossReferencesRequest_ALL_REFERENCES,
ExperimentalSignatures: true,
})
testutil.FatalOnErrT(t, "CrossReferencesRequest error: %v", err)
expected := &xpb.CrossReferencesReply_CrossReferenceSet{
Ticket: ticket,
DisplayName: &xpb.Printable{RawText: ""},
Reference: []*xpb.CrossReferencesReply_RelatedAnchor{{Anchor: &xpb.Anchor{
Ticket: "kythe:?path=some/utf16/file#0-4",
Kind: "/kythe/edge/ref",
Parent: "kythe://someCorpus?path=some/utf16/file#utf16FTW",
Start: &xpb.Location_Point{LineNumber: 1},
End: &xpb.Location_Point{ByteOffset: 4, LineNumber: 1, ColumnOffset: 4},
SnippetStart: &xpb.Location_Point{
LineNumber: 1,
},
SnippetEnd: &xpb.Location_Point{
ByteOffset: 28,
LineNumber: 1,
ColumnOffset: 28,
},
Snippet: "これはいくつかのテキストです",
}}, {Anchor: &xpb.Anchor{
Ticket: "kythe://c?lang=otpl?path=/a/path#51-55",
Kind: "/kythe/edge/ref",
Parent: "kythe://someCorpus?path=some/path#aFileNode",
Start: &xpb.Location_Point{
ByteOffset: 51,
LineNumber: 4,
ColumnOffset: 15,
},
End: &xpb.Location_Point{
ByteOffset: 55,
LineNumber: 5,
ColumnOffset: 2,
},
SnippetStart: &xpb.Location_Point{
ByteOffset: 36,
LineNumber: 4,
},
SnippetEnd: &xpb.Location_Point{
ByteOffset: 52,
LineNumber: 4,
ColumnOffset: 16,
},
Snippet: "some random text",
}}},
Definition: []*xpb.CrossReferencesReply_RelatedAnchor{{Anchor: &xpb.Anchor{
Ticket: "kythe://c?lang=otpl?path=/a/path#27-33",
Kind: "/kythe/edge/defines/binding",
Parent: "kythe://someCorpus?path=some/path#aFileNode",
Start: &xpb.Location_Point{
ByteOffset: 27,
LineNumber: 2,
ColumnOffset: 10,
},
End: &xpb.Location_Point{
ByteOffset: 33,
LineNumber: 3,
ColumnOffset: 5,
},
SnippetStart: &xpb.Location_Point{
ByteOffset: 17,
LineNumber: 2,
},
SnippetEnd: &xpb.Location_Point{
ByteOffset: 27,
LineNumber: 2,
ColumnOffset: 10,
},
Snippet: "here and ",
}}},
}
if err := testutil.DeepEqual(&xpb.CrossReferencesReply_Total{
Definitions: 1,
References: 2,
}, reply.Total); err != nil {
t.Error(err)
}
xr := reply.CrossReferences[ticket]
if xr == nil {
//.........这里部分代码省略.........
示例15: TestSlowCallers
//.........这里部分代码省略.........
CrossReferencesFn: func(req *xpb.CrossReferencesRequest) (*xpb.CrossReferencesReply, error) {
if len(req.Ticket) == 1 && req.Ticket[0] == "kythe://test#f" {
if req.ReferenceKind == xpb.CrossReferencesRequest_ALL_REFERENCES {
return &xpb.CrossReferencesReply{
CrossReferences: map[string]*xpb.CrossReferencesReply_CrossReferenceSet{
req.Ticket[0]: &xpb.CrossReferencesReply_CrossReferenceSet{
Ticket: req.Ticket[0],
Reference: []*xpb.CrossReferencesReply_RelatedAnchor{
&xpb.CrossReferencesReply_RelatedAnchor{Anchor: &xpb.Anchor{
Ticket: "kythe://test#acall",
Kind: schema.RefCallEdge,
}},
},
},
},
}, nil
}
} else if len(req.Ticket) == 2 && containsString(req.Ticket, "kythe://test#f") && containsString(req.Ticket, "kythe://test#g") {
if req.DefinitionKind == xpb.CrossReferencesRequest_BINDING_DEFINITIONS {
return &xpb.CrossReferencesReply{
CrossReferences: map[string]*xpb.CrossReferencesReply_CrossReferenceSet{
"kythe://test#f": &xpb.CrossReferencesReply_CrossReferenceSet{
Ticket: "kythe://test#f",
Definition: []*xpb.CrossReferencesReply_RelatedAnchor{
&xpb.CrossReferencesReply_RelatedAnchor{Anchor: &xpb.Anchor{
Ticket: "kythe://test#afdef",
Text: "f",
}},
},
},
"kythe://test#g": &xpb.CrossReferencesReply_CrossReferenceSet{
Ticket: "kythe://test#g",
Definition: []*xpb.CrossReferencesReply_RelatedAnchor{
&xpb.CrossReferencesReply_RelatedAnchor{Anchor: &xpb.Anchor{
Ticket: "kythe://test#agdef",
Text: "g",
}},
},
},
},
}, nil
}
}
t.Fatalf("Unexpected CrossReferences request: %v", req)
return nil, nil
},
CallersFn: func(req *xpb.CallersRequest) (*xpb.CallersReply, error) {
t.Fatalf("Unexpected Callers request: %v", req)
return nil, nil
},
}
creq := &xpb.CallersRequest{
IncludeOverrides: true,
SemanticObject: []string{"kythe://test#f"},
}
creply, err := SlowCallers(nil, service, creq)
if err != nil {
t.Fatalf("SlowCallers error: %v", err)
}
if creply == nil {
t.Fatalf("SlowCallers returned nil response")
}
expected := &xpb.CallersReply{
Callee: []*xpb.CallersReply_CallableDetail{
&xpb.CallersReply_CallableDetail{
SemanticObject: "kythe://test#f",
Definition: &xpb.Anchor{
Ticket: "kythe://test#afdef",
Text: "f",
},
Identifier: "f",
DisplayName: "f",
},
},
Caller: []*xpb.CallersReply_Caller{
&xpb.CallersReply_Caller{
Detail: &xpb.CallersReply_CallableDetail{
SemanticObject: "kythe://test#g",
Definition: &xpb.Anchor{
Ticket: "kythe://test#agdef",
Text: "g",
},
Identifier: "g",
DisplayName: "g",
},
CallSite: []*xpb.CallersReply_Caller_CallSite{
&xpb.CallersReply_Caller_CallSite{
Anchor: &xpb.Anchor{
Ticket: "kythe://test#acall",
Kind: "/kythe/edge/ref/call",
},
},
},
},
},
}
if err := testutil.DeepEqual(expected, creply); err != nil {
t.Fatal(err)
}
}