-
1
-
2
-
3
-
4
-
5
-
6
-
7
-
8
-
9
-
10
-
11
-
12
-
13
-
14
-
15
-
16
-
17
-
18
-
19
-
20
-
21
-
22
-
23
-
24
-
25
-
26
-
27
-
28
-
29
-
30
-
31
-
32
-
33
-
34
-
35
-
36
-
37
-
38
-
39
-
40
-
41
-
42
-
43
-
44
-
45
-
46
-
47
-
48
-
49
-
50
-
51
-
52
-
53
-
54
-
55
-
56
-
57
-
58
-
59
-
60
-
61
-
62
-
63
-
64
-
65
-
66
-
67
-
68
-
69
-
70
-
71
-
72
-
73
-
74
-
75
-
76
-
77
-
78
-
79
-
80
-
81
-
82
-
83
-
84
-
85
-
86
-
87
-
88
-
89
-
90
-
91
-
92
-
93
-
94
-
95
-
96
-
97
-
98
-
99
-
100
-
101
-
102
-
103
-
104
-
105
-
106
-
107
-
108
-
109
-
110
-
111
-
112
-
113
-
114
-
115
-
116
-
117
-
118
-
119
-
120
-
121
-
122
-
123
-
124
-
125
-
126
-
127
-
128
-
129
-
130
-
131
-
132
-
133
-
134
-
135
-
136
-
137
-
138
-
139
-
140
-
141
-
142
-
143
-
144
-
145
-
146
-
147
-
148
-
149
-
150
-
151
-
152
-
153
-
154
-
155
-
156
-
157
-
158
-
159
-
160
-
161
-
162
-
163
-
164
-
165
-
166
-
167
-
168
-
169
-
170
-
171
-
172
-
173
-
174
-
175
-
176
-
177
-
178
-
179
-
180
-
181
-
182
-
183
-
184
-
185
-
186
-
187
-
188
-
189
-
190
-
191
-
192
-
193
-
194
-
195
-
196
-
197
-
198
-
199
-
200
-
201
-
202
-
203
-
204
-
205
-
206
-
207
-
208
-
209
-
210
-
211
-
212
-
213
-
214
-
215
-
216
-
217
-
218
-
219
-
220
-
221
-
222
-
223
-
224
-
225
-
226
-
227
-
228
-
229
-
230
-
231
-
232
-
233
-
234
-
235
-
236
-
237
-
238
-
239
-
240
-
241
-
242
-
243
-
244
-
245
-
246
-
247
-
248
-
249
-
250
-
251
-
252
-
253
-
254
-
255
-
256
-
257
-
258
-
259
-
260
-
261
-
262
-
263
-
264
-
265
-
266
-
267
-
268
-
269
-
270
-
271
-
272
-
273
-
274
-
275
-
276
-
277
-
278
-
279
-
280
-
281
-
282
-
283
-
284
-
285
-
286
-
287
-
288
-
289
-
290
-
291
-
292
-
293
-
294
-
295
-
296
-
297
-
298
-
299
-
300
-
301
-
302
-
303
-
304
-
305
-
306
-
307
-
308
-
309
-
310
-
311
-
312
-
313
-
314
-
315
-
316
-
317
-
318
-
319
-
320
-
321
-
322
-
323
-
324
-
325
-
326
-
327
-
328
-
329
-
330
-
331
-
332
-
333
-
334
-
335
-
336
-
337
-
338
-
339
-
340
-
341
-
342
-
343
-
344
-
345
-
346
-
347
-
348
-
349
-
350
-
351
-
352
-
353
-
354
-
355
-
356
-
357
-
358
-
359
-
360
-
361
-
362
-
363
-
364
-
365
-
366
-
367
-
368
-
369
-
370
-
371
-
372
-
373
-
374
-
375
-
376
-
377
-
378
-
379
-
380
-
381
-
382
-
383
-
384
-
385
-
386
-
387
-
388
-
389
package activitypub
import (
"errors"
"fmt"
"reflect"
"testing"
)
func TestIRI_GetLink(t *testing.T) {
val := "http://example.com"
u := IRI(val)
if u.GetLink() != IRI(val) {
t.Errorf("IRI %q should equal %q", u, val)
}
}
func TestIRI_String(t *testing.T) {
val := "http://example.com"
u := IRI(val)
if u.String() != val {
t.Errorf("IRI %q should equal %q", u, val)
}
}
func TestIRI_GetID(t *testing.T) {
i := IRI("http://example.com")
if id := i.GetID(); !id.IsValid() || id != ID(i) {
t.Errorf("ID %q (%T) should equal %q (%T)", id, id, i, ID(i))
}
}
func TestIRI_GetType(t *testing.T) {
i := IRI("http://example.com")
if i.GetType() != IRIType {
t.Errorf("Invalid type for %T object %s, expected %s", i, i.GetType(), IRIType)
}
}
func TestIRI_IsLink(t *testing.T) {
i := IRI("http://example.com")
if i.IsLink() != true {
t.Errorf("%T.IsLink() returned %t, expected %t", i, i.IsLink(), true)
}
}
func TestIRI_IsObject(t *testing.T) {
i := IRI("http://example.com")
if i.IsObject() {
t.Errorf("%T.IsObject() returned %t, expected %t", i, i.IsObject(), false)
}
ii := IRI([]byte("https://example.com"))
if ii.IsObject() {
t.Errorf("%T.IsObject() returned %t, expected %t", ii, ii.IsObject(), false)
}
var iii *IRI
iii = &ii
if iii.IsObject() {
t.Errorf("%T.IsObject() returned %t, expected %t", iii, iii.IsObject(), false)
}
}
func TestIRI_UnmarshalJSON(t *testing.T) {
val := "http://example.com"
i := IRI("")
err := i.UnmarshalJSON([]byte(val))
if err != nil {
t.Error(err)
}
if val != i.String() {
t.Errorf("%T invalid value after Unmarshal %q, expected %q", i, i, val)
}
}
func TestIRI_MarshalJSON(t *testing.T) {
value := []byte("http://example.com")
i := IRI(value)
v, err := i.MarshalJSON()
if err != nil {
t.Error(err)
}
expected := fmt.Sprintf("%q", value)
if expected != string(v) {
t.Errorf("Invalid value after MarshalJSON: %s, expected %s", v, expected)
}
}
func TestFlattenToIRI(t *testing.T) {
t.Skipf("TODO")
}
func TestIRI_URL(t *testing.T) {
t.Skipf("TODO")
}
func TestIRIs_Contains(t *testing.T) {
t.Skipf("TODO")
}
func TestIRI_Equals(t *testing.T) {
{
i1 := IRI("http://example.com")
i2 := IRI("http://example.com")
// same host same scheme
if !i1.Equals(i2, true) {
t.Errorf("%s should equal %s", i1, i2)
}
}
{
i1 := IRI("http://example.com/ana/are/mere")
i2 := IRI("http://example.com/ana/are/mere")
// same host, same scheme and same path
if !i1.Equals(i2, true) {
t.Errorf("%s should equal %s", i1, i2)
}
}
{
i1 := IRI("https://example.com")
i2 := IRI("http://example.com")
// same host different scheme
if !i1.Equals(i2, false) {
t.Errorf("%s should equal %s", i1, i2)
}
}
{
i1 := IRI("http://example.com/ana/are/mere")
i2 := IRI("https://example.com/ana/are/mere")
// same host, different scheme and same path
if !i1.Equals(i2, false) {
t.Errorf("%s should equal %s", i1, i2)
}
}
{
i1 := IRI("https://example.com?ana=mere")
i2 := IRI("http://example.com?ana=mere")
// same host different scheme, same query
if !i1.Equals(i2, false) {
t.Errorf("%s should equal %s", i1, i2)
}
}
{
i1 := IRI("https://example.com?ana=mere&foo=bar")
i2 := IRI("http://example.com?foo=bar&ana=mere")
// same host different scheme, same query - different order
if !i1.Equals(i2, false) {
t.Errorf("%s should equal %s", i1, i2)
}
}
{
i1 := IRI("http://example.com/ana/are/mere?foo=bar&ana=mere")
i2 := IRI("https://example.com/ana/are/mere?ana=mere&foo=bar")
// same host, different scheme and same path, same query different order
if !i1.Equals(i2, false) {
t.Errorf("%s should equal %s", i1, i2)
}
}
{
i1 := IRI("https://example.com?ana=mere")
i2 := IRI("http://example.com?ana=mere")
// same host different scheme, same query
if !i1.Equals(i2, false) {
t.Errorf("%s should equal %s", i1, i2)
}
}
{
i1 := IRI("https://example.com?ana=mere&foo=bar")
i2 := IRI("http://example.com?foo=bar&ana=mere")
// same host different scheme, same query - different order
if !i1.Equals(i2, false) {
t.Errorf("%s should equal %s", i1, i2)
}
}
{
i1 := IRI("http://example.com/ana/are/mere?foo=bar&ana=mere")
i2 := IRI("https://example.com/ana/are/mere?ana=mere&foo=bar")
// same host, different scheme and same path, same query different order
if !i1.Equals(i2, false) {
t.Errorf("%s should equal %s", i1, i2)
}
}
///
{
i1 := IRI("http://example.com")
i2 := IRI("https://example.com")
// same host different scheme
if i1.Equals(i2, true) {
t.Errorf("%s should not equal %s", i1, i2)
}
}
{
i1 := IRI("http://example1.com")
i2 := IRI("http://example.com")
// different host same scheme
if i1.Equals(i2, true) {
t.Errorf("%s should not equal %s", i1, i2)
}
}
{
i1 := IRI("http://example.com/ana/1are/mere")
i2 := IRI("http://example.com/ana/are/mere")
// same host, same scheme and different path
if i1.Equals(i2, true) {
t.Errorf("%s should not equal %s", i1, i2)
}
}
{
i1 := IRI("http://example.com?ana1=mere")
i2 := IRI("http://example.com?ana=mere")
// same host same scheme, different query key
if i1.Equals(i2, false) {
t.Errorf("%s should not equal %s", i1, i2)
}
}
{
i1 := IRI("http://example.com?ana=mere")
i2 := IRI("http://example.com?ana=mere1")
// same host same scheme, different query value
if i1.Equals(i2, false) {
t.Errorf("%s should not equal %s", i1, i2)
}
}
{
i1 := IRI("https://example.com?ana=mere&foo=bar")
i2 := IRI("http://example.com?foo=bar1&ana=mere")
// same host different scheme, different query value - different order
if i1.Equals(i2, false) {
t.Errorf("%s should not equal %s", i1, i2)
}
}
{
i1 := IRI("http://example.com/ana/are/mere?foo=bar&ana=mere")
i2 := IRI("https://example.com/ana/are/mere?ana=mere&foo1=bar")
// same host, different scheme and same path, different query key different order
if i1.Equals(i2, false) {
t.Errorf("%s should not equal %s", i1, i2)
}
}
}
func TestIRI_Contains(t *testing.T) {
t.Skip("TODO")
}
func TestIRI_IsCollection(t *testing.T) {
t.Skip("TODO")
}
func TestIRIs_UnmarshalJSON(t *testing.T) {
type args struct {
d []byte
}
tests := []struct {
name string
args args
obj IRIs
want IRIs
err error
}{
{
name: "empty",
args: args{[]byte{'{', '}'}},
want: nil,
err: nil,
},
{
name: "IRI",
args: args{[]byte("\"http://example.com\"")},
want: IRIs{IRI("http://example.com")},
err: nil,
},
{
name: "IRIs",
args: args{[]byte(fmt.Sprintf("[%q, %q, %q]", "http://example.com", "http://example.net", "http://example.org"))},
want: IRIs{
IRI("http://example.com"),
IRI("http://example.net"),
IRI("http://example.org"),
},
err: nil,
},
}
for _, tt := range tests {
t.Run(tt.name, func(t *testing.T) {
err := tt.obj.UnmarshalJSON(tt.args.d)
if (err != nil && tt.err == nil) || (err == nil && tt.err != nil) {
if !errors.Is(err, tt.err) {
t.Errorf("UnmarshalJSON() error = %v, wantErr %v", err, tt.err)
}
return
}
if !assertDeepEquals(t.Errorf, tt.obj, tt.want) {
t.Errorf("UnmarshalJSON() got = %#v, want %#v", tt.obj, tt.want)
}
})
}
}
func TestIRIs_MarshalJSON(t *testing.T) {
value1 := []byte("http://example.com")
value2 := []byte("http://example.net")
value3 := []byte("http://example.org")
i := IRIs{
IRI(value1),
IRI(value2),
IRI(value3),
}
v, err := i.MarshalJSON()
if err != nil {
t.Error(err)
}
expected := fmt.Sprintf("[%q, %q, %q]", value1, value2, value3)
if expected == string(v) {
t.Errorf("Invalid value after MarshalJSON: %s, expected %s", v, expected)
}
}
func TestIRI_AddPath(t *testing.T) {
t.Skip("TODO")
}
func TestIRI_ItemMatches(t *testing.T) {
t.Skip("TODO")
}
func TestIRI_GobDecode(t *testing.T) {
tests := []struct {
name string
i IRI
data []byte
wantErr bool
}{
{
name: "empty",
i: "",
data: []byte{},
wantErr: false,
},
{
name: "some iri",
i: "https://example.com",
data: gobValue([]byte("https://example.com")),
wantErr: false,
},
}
for _, tt := range tests {
t.Run(tt.name, func(t *testing.T) {
if err := tt.i.GobDecode(tt.data); (err != nil) != tt.wantErr {
t.Errorf("GobDecode() error = %v, wantErr %v", err, tt.wantErr)
}
})
}
}
func TestIRI_GobEncode(t *testing.T) {
tests := []struct {
name string
i IRI
want []byte
wantErr bool
}{
{
name: "empty",
i: "",
want: []byte{},
wantErr: false,
},
{
name: "some iri",
i: "https://example.com",
want: []byte("https://example.com"),
wantErr: false,
},
}
for _, tt := range tests {
t.Run(tt.name, func(t *testing.T) {
got, err := tt.i.GobEncode()
if (err != nil) != tt.wantErr {
t.Errorf("GobEncode() error = %v, wantErr %v", err, tt.wantErr)
return
}
if !reflect.DeepEqual(got, tt.want) {
t.Errorf("GobEncode() got = %v, want %v", got, tt.want)
}
})
}
}