Debian Codegraph @

copy_test.go

raw symbols SCIP
1 package activitypub
2
3 import (
4 "testing"
5
6 "github.com/google/go-cmp/cmp"
7 )
8
9 func TestClone(t *testing.T) {
10 tests := []struct {
11 name string
12 it Item
13 want Item
14 }{
15 {
16 name: "empty",
17 },
18 {
19 name: "*object empty",
20 it: &Object{},
21 want: &Object{},
22 },
23 {
24 name: "object empty",
25 it: Object{},
26 want: &Object{},
27 },
28 {
29 name: "*object with ID",
30 it: &Object{ID: "http://example.com"},
31 want: &Object{ID: "http://example.com"},
32 },
33 {
34 name: "object with ID",
35 it: Object{ID: "http://example.com"},
36 want: &Object{ID: "http://example.com"},
37 },
38 {
39 name: "*object with Type",
40 it: &Object{Type: NoteType},
41 want: &Object{Type: NoteType},
42 },
43 {
44 name: "object with Type",
45 it: Object{Type: NoteType},
46 want: &Object{Type: NoteType},
47 },
48 {
49 name: "*collection",
50 it: &Collection{Type: CollectionType},
51 want: &Collection{Type: CollectionType},
52 },
53 {
54 name: "collection",
55 it: Collection{Type: CollectionType},
56 want: &Collection{Type: CollectionType},
57 },
58 {
59 name: "*collection with items",
60 it: &Collection{Type: CollectionType, Items: ItemCollection{&Object{ID: "http://example.com"}, &Place{ID: "http//:example.com/home"}}},
61 want: &Collection{Type: CollectionType, Items: ItemCollection{&Object{ID: "http://example.com"}, &Place{ID: "http//:example.com/home"}}},
62 },
63 {
64 name: "collection with items",
65 it: Collection{Type: CollectionType, Items: ItemCollection{&Object{ID: "http://example.com"}, &Place{ID: "http//:example.com/home"}}},
66 want: &Collection{Type: CollectionType, Items: ItemCollection{&Object{ID: "http://example.com"}, &Place{ID: "http//:example.com/home"}}},
67 },
68 {
69 name: "empty item collection",
70 it: ItemCollection{},
71 want: &ItemCollection{},
72 },
73 {
74 name: "empty *item collection",
75 it: &ItemCollection{},
76 want: &ItemCollection{},
77 },
78 {
79 name: "not empty item collection",
80 it: ItemCollection{&Object{ID: "http://example.com"}, &Place{ID: "http//:example.com/home"}},
81 want: &ItemCollection{&Object{ID: "http://example.com"}, &Place{ID: "http//:example.com/home"}},
82 },
83 {
84 name: "not empty *item collection",
85 it: &ItemCollection{&Actor{ID: "http://example.com/~jdoe"}, Link{ID: "https://example.com/test"}},
86 want: &ItemCollection{&Actor{ID: "http://example.com/~jdoe"}, Link{ID: "https://example.com/test"}},
87 },
88 {
89 name: "empty IRIs",
90 it: IRIs{},
91 want: &IRIs{},
92 },
93 {
94 name: "empty *IRIs",
95 it: &IRIs{},
96 want: &IRIs{},
97 },
98 {
99 name: "not empty IRIs",
100 it: IRIs{"http://example.com", "http//:example.com/home"},
101 want: &IRIs{"http://example.com", "http//:example.com/home"},
102 },
103 {
104 name: "not empty *IRIs",
105 it: &IRIs{"http://example.com/~jdoe", "https://example.com/test"},
106 want: &IRIs{"http://example.com/~jdoe", "https://example.com/test"},
107 },
108 {
109 name: "empty IRI",
110 it: IRI(""),
111 want: IRI(""),
112 },
113 {
114 name: "not empty IRI",
115 it: IRI("http://example.com"),
116 want: IRI("http://example.com"),
117 },
118 }
119 for _, tt := range tests {
120 t.Run(tt.name, func(t *testing.T) {
121 got := Clone(tt.it)
122 if !cmp.Equal(got, tt.want) {
123 t.Errorf("Clone() got = %s", cmp.Diff(tt.want, got))
124 }
125 })
126 }
127 }