-
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
-
390
-
391
-
392
-
393
-
394
-
395
-
396
-
397
-
398
-
399
-
400
-
401
-
402
-
403
-
404
-
405
-
406
-
407
-
408
-
409
-
410
-
411
-
412
-
413
-
414
-
415
-
416
-
417
-
418
-
419
-
420
-
421
-
422
-
423
-
424
-
425
-
426
-
427
-
428
-
429
-
430
-
431
-
432
-
433
-
434
-
435
-
436
-
437
-
438
-
439
-
440
-
441
-
442
-
443
-
444
-
445
-
446
-
447
-
448
-
449
-
450
-
451
-
452
-
453
-
454
-
455
-
456
-
457
-
458
-
459
-
460
-
461
-
462
-
463
-
464
-
465
-
466
-
467
-
468
-
469
-
470
-
471
-
472
-
473
-
474
-
475
-
476
-
477
-
478
-
479
-
480
-
481
-
482
-
483
-
484
-
485
-
486
-
487
-
488
-
489
-
490
-
491
-
492
-
493
-
494
-
495
-
496
-
497
-
498
-
499
-
500
-
501
-
502
-
503
-
504
-
505
-
506
-
507
-
508
-
509
-
510
-
511
-
512
-
513
-
514
-
515
-
516
-
517
-
518
-
519
-
520
-
521
-
522
-
523
-
524
-
525
-
526
-
527
-
528
-
529
-
530
-
531
-
532
-
533
-
534
-
535
-
536
-
537
-
538
-
539
-
540
-
541
-
542
-
543
-
544
-
545
-
546
-
547
-
548
-
549
-
550
-
551
-
552
-
553
-
554
-
555
-
556
-
557
-
558
-
559
-
560
-
561
-
562
-
563
-
564
-
565
-
566
-
567
-
568
-
569
-
570
-
571
-
572
-
573
-
574
-
575
-
576
-
577
-
578
-
579
-
580
-
581
-
582
-
583
-
584
-
585
-
586
-
587
-
588
-
589
-
590
-
591
-
592
-
593
-
594
-
595
-
596
-
597
-
598
-
599
-
600
-
601
-
602
-
603
-
604
-
605
-
606
-
607
-
608
-
609
-
610
-
611
-
612
-
613
-
614
-
615
-
616
-
617
-
618
-
619
-
620
-
621
-
622
-
623
-
624
-
625
-
626
-
627
-
628
-
629
-
630
-
631
-
632
-
633
-
634
-
635
-
636
-
637
-
638
-
639
-
640
-
641
-
642
-
643
-
644
-
645
-
646
-
647
-
648
-
649
-
650
-
651
-
652
-
653
-
654
-
655
-
656
-
657
-
658
-
659
-
660
-
661
-
662
-
663
-
664
-
665
-
666
-
667
-
668
-
669
-
670
-
671
-
672
-
673
-
674
-
675
-
676
-
677
-
678
-
679
-
680
-
681
-
682
-
683
-
684
-
685
-
686
-
687
-
688
-
689
-
690
-
691
-
692
-
693
-
694
-
695
-
696
-
697
-
698
-
699
-
700
-
701
-
702
-
703
-
704
-
705
-
706
-
707
-
708
-
709
-
710
-
711
-
712
-
713
-
714
-
715
-
716
-
717
-
718
-
719
-
720
-
721
-
722
-
723
-
724
-
725
-
726
-
727
-
728
-
729
-
730
-
731
-
732
-
733
-
734
-
735
-
736
-
737
-
738
-
739
-
740
-
741
-
742
-
743
-
744
-
745
-
746
-
747
-
748
-
749
-
750
-
751
-
752
-
753
-
754
-
755
-
756
-
757
-
758
-
759
-
760
-
761
-
762
-
763
-
764
-
765
-
766
-
767
-
768
-
769
-
770
-
771
-
772
-
773
-
774
-
775
-
776
-
777
-
778
-
779
-
780
-
781
-
782
-
783
-
784
-
785
-
786
-
787
-
788
-
789
-
790
-
791
-
792
-
793
-
794
-
795
-
796
-
797
-
798
-
799
-
800
-
801
-
802
-
803
-
804
-
805
-
806
-
807
-
808
-
809
-
810
-
811
-
812
-
813
-
814
-
815
-
816
-
817
-
818
-
819
-
820
-
821
-
822
-
823
-
824
-
825
-
826
-
827
-
828
-
829
-
830
-
831
-
832
-
833
-
834
-
835
-
836
-
837
-
838
-
839
-
840
-
841
-
842
-
843
-
844
-
845
-
846
-
847
-
848
-
849
-
850
-
851
-
852
-
853
-
854
-
855
-
856
-
857
-
858
-
859
-
860
-
861
-
862
-
863
-
864
-
865
-
866
-
867
-
868
-
869
-
870
-
871
-
872
-
873
-
874
-
875
-
876
-
877
-
878
-
879
-
880
-
881
-
882
-
883
-
884
-
885
-
886
-
887
-
888
-
889
-
890
-
891
-
892
-
893
-
894
-
895
-
896
-
897
-
898
-
899
-
900
-
901
-
902
-
903
-
904
-
905
-
906
-
907
-
908
-
909
-
910
-
911
-
912
-
913
-
914
-
915
-
916
-
917
-
918
-
919
-
920
-
921
-
922
-
923
-
924
-
925
-
926
-
927
-
928
-
929
-
930
-
931
-
932
-
933
-
934
-
935
-
936
-
937
-
938
-
939
-
940
-
941
-
942
-
943
-
944
-
945
-
946
-
947
-
948
-
949
-
950
-
951
-
952
-
953
-
954
-
955
-
956
-
957
-
958
-
959
-
960
-
961
-
962
-
963
package activitypub
import (
"encoding/json"
"fmt"
"reflect"
"strconv"
"testing"
)
func TestObjectNew(t *testing.T) {
var testValue = ObjectID("test")
var testType = ArticleType
o := ObjectNew(testType)
o.ID = testValue
if o.ID != testValue {
t.Errorf("APObject Id '%v' different than expected '%v'", o.ID, testValue)
}
if o.Type != testType {
t.Errorf("APObject Type '%v' different than expected '%v'", o.Type, testType)
}
n := ObjectNew("")
n.ID = testValue
if n.ID != testValue {
t.Errorf("APObject Id '%v' different than expected '%v'", n.ID, testValue)
}
if n.Type != ObjectType {
t.Errorf("APObject Type '%v' different than expected '%v'", n.Type, ObjectType)
}
}
func TestActivityVocabularyTypes_Contains(t *testing.T) {
{
var invalidType ActivityVocabularyType = "RandomType"
if ActivityTypes.Contains(ActivityType) {
t.Errorf("Generic Activity Type '%v' should not be valid", ActivityType)
}
for _, inValidType := range ObjectTypes {
if ActivityTypes.Contains(inValidType) {
t.Errorf("APObject Type '%v' should be invalid", inValidType)
}
}
if ActivityTypes.Contains(invalidType) {
t.Errorf("Activity Type '%v' should not be valid", invalidType)
}
for _, validType := range ActivityTypes {
if !ActivityTypes.Contains(validType) {
t.Errorf("Activity Type '%v' should be valid", validType)
}
}
}
{
var invalidType ActivityVocabularyType = "RandomType"
if IntransitiveActivityTypes.Contains(ActivityType) {
t.Errorf("Generic Activity Type '%v' should not be valid", ActivityType)
}
for _, inValidType := range ActivityTypes {
if IntransitiveActivityTypes.Contains(inValidType) {
t.Errorf("APObject Type '%v' should be invalid", inValidType)
}
}
if IntransitiveActivityTypes.Contains(invalidType) {
t.Errorf("Activity Type '%v' should not be valid", invalidType)
}
for _, validType := range IntransitiveActivityTypes {
if !IntransitiveActivityTypes.Contains(validType) {
t.Errorf("Activity Type '%v' should be valid", validType)
}
}
}
{
var invalidType ActivityVocabularyType = "RandomType"
if ActivityTypes.Contains(ActivityType) {
t.Errorf("Generic Activity Type '%v' should not be valid", ActivityType)
}
for _, inValidType := range CollectionManagementActivityTypes {
if !CollectionManagementActivityTypes.Contains(inValidType) {
t.Errorf("APObject Type '%v' should be valid", inValidType)
}
}
if CollectionManagementActivityTypes.Contains(invalidType) {
t.Errorf("Activity Type '%v' should not be valid", invalidType)
}
for _, validType := range ContentManagementActivityTypes {
if CollectionManagementActivityTypes.Contains(validType) {
t.Errorf("Activity Type '%v' should not be valid", validType)
}
}
for _, validType := range ReactionsActivityTypes {
if CollectionManagementActivityTypes.Contains(validType) {
t.Errorf("Activity Type '%v' should not be valid", validType)
}
}
}
{
var invalidType ActivityVocabularyType = "RandomType"
if ActivityTypes.Contains(ActivityType) {
t.Errorf("Generic Activity Type '%v' should not be valid", ActivityType)
}
for _, inValidType := range ContentManagementActivityTypes {
if !ContentManagementActivityTypes.Contains(inValidType) {
t.Errorf("APObject Type '%v' should be valid", inValidType)
}
}
if ContentManagementActivityTypes.Contains(invalidType) {
t.Errorf("Activity Type '%v' should not be valid", invalidType)
}
for _, validType := range CollectionManagementActivityTypes {
if ContentManagementActivityTypes.Contains(validType) {
t.Errorf("Activity Type '%v' should not be valid", validType)
}
}
for _, validType := range ReactionsActivityTypes {
if ContentManagementActivityTypes.Contains(validType) {
t.Errorf("Activity Type '%v' should not be valid", validType)
}
}
}
{
var invalidType ActivityVocabularyType = "RandomType"
if ReactionsActivityTypes.Contains(ActivityType) {
t.Errorf("Generic Activity Type '%v' should not be valid", ActivityType)
}
for _, inValidType := range ReactionsActivityTypes {
if !ReactionsActivityTypes.Contains(inValidType) {
t.Errorf("APObject Type '%v' should be valid", inValidType)
}
}
if ReactionsActivityTypes.Contains(invalidType) {
t.Errorf("Activity Type '%v' should not be valid", invalidType)
}
for _, validType := range CollectionManagementActivityTypes {
if ReactionsActivityTypes.Contains(validType) {
t.Errorf("Activity Type '%v' should not be valid", validType)
}
}
for _, validType := range ContentManagementActivityTypes {
if ReactionsActivityTypes.Contains(validType) {
t.Errorf("Activity Type '%v' should not be valid", validType)
}
}
}
{
for _, validType := range CollectionTypes {
if !CollectionTypes.Contains(validType) {
t.Errorf("Generic Type '%#v' should be valid", validType)
}
}
}
{
var invalidType ActivityVocabularyType = "RandomType"
if ActorTypes.Contains(invalidType) {
t.Errorf("APObject Type '%v' should not be valid", invalidType)
}
for _, validType := range ActorTypes {
if !ActorTypes.Contains(validType) {
t.Errorf("APObject Type '%v' should be valid", validType)
}
}
}
{
for _, validType := range GenericObjectTypes {
if !GenericObjectTypes.Contains(validType) {
t.Errorf("Generic Type '%v' should be valid", validType)
}
}
}
{
var invalidType ActivityVocabularyType = "RandomType"
if ObjectTypes.Contains(invalidType) {
t.Errorf("APObject Type '%v' should not be valid", invalidType)
}
for _, validType := range ObjectTypes {
if !ObjectTypes.Contains(validType) {
t.Errorf("APObject Type '%v' should be valid", validType)
}
}
}
}
func TestNaturalLanguageValue_MarshalJSON(t *testing.T) {
p := NaturalLanguageValues{
{
"en", "the test",
},
{
"fr", "le test",
},
}
js := "{\"en\":\"the test\",\"fr\":\"le test\"}"
out, err := p.MarshalJSON()
if err != nil {
t.Errorf("Error: '%s'", err)
}
if js != string(out) {
t.Errorf("Different marshal result '%s', instead of '%s'", out, js)
}
p1 := NaturalLanguageValues{
{
"en", "the test",
},
}
out1, err1 := p1.MarshalJSON()
if err1 != nil {
t.Errorf("Error: '%s'", err1)
}
txt := `{"en":"the test"}`
if txt != string(out1) {
t.Errorf("Different marshal result '%s', instead of '%s'", out1, txt)
}
}
func TestLangRefValue_MarshalJSON(t *testing.T) {
{
tst := LangRefValue{
Ref: NilLangRef,
Value: "test",
}
j, err := tst.MarshalJSON()
if err != nil {
t.Errorf("Error: %s", err)
}
expected := `"test"`
if string(j) != expected {
t.Errorf("Different marshal result '%s', expected '%s'", j, expected)
}
}
{
tst := LangRefValue{
Ref: "en",
Value: "test",
}
j, err := tst.MarshalJSON()
if err != nil {
t.Errorf("Error: %s", err)
}
expected := `"en":"test"`
if string(j) != expected {
t.Errorf("Different marshal result '%s', expected '%s'", j, expected)
}
}
{
tst := LangRefValue{
Ref: "en",
Value: "test\nwith characters\tneeding escaping\r\n",
}
j, err := tst.MarshalJSON()
if err != nil {
t.Errorf("Error: %s", err)
}
expected := `"en":"test\nwith characters\tneeding escaping\r\n"`
if string(j) != expected {
t.Errorf("Different marshal result '%s', expected '%s'", j, expected)
}
}
}
func TestLangRefValue_MarshalText(t *testing.T) {
{
tst := LangRefValue{
Ref: NilLangRef,
Value: "test",
}
j, err := tst.MarshalText()
if err != nil {
t.Errorf("Error: %s", err)
}
expected := "test"
if string(j) != expected {
t.Errorf("Different marshal result '%s', expected '%s'", j, expected)
}
}
{
tst := LangRefValue{
Ref: "en",
Value: "test",
}
j, err := tst.MarshalText()
if err != nil {
t.Errorf("Error: %s", err)
}
expected := "test[en]"
if string(j) != expected {
t.Errorf("Different marshal result '%s', expected '%s'", j, expected)
}
}
}
func TestObject_IsLink(t *testing.T) {
o := ObjectNew(ObjectType)
o.ID = "test"
if o.IsLink() {
t.Errorf("%#v should not be a valid link", o.Type)
}
m := ObjectNew(AcceptType)
m.ID = "test"
if m.IsLink() {
t.Errorf("%#v should not be a valid link", m.Type)
}
}
func TestObject_IsObject(t *testing.T) {
o := ObjectNew(ObjectType)
o.ID = "test"
if !o.IsObject() {
t.Errorf("%#v should be a valid object", o.Type)
}
m := ObjectNew(AcceptType)
m.ID = "test"
if !m.IsObject() {
t.Errorf("%#v should be a valid object", m.Type)
}
}
func TestObjectsArr_Append(t *testing.T) {
d := make(ItemCollection, 0)
val := Object{ID: ObjectID("grrr")}
d.Append(val)
if len(d) != 1 {
t.Errorf("Objects array should have exactly an element")
}
if !reflect.DeepEqual(d[0], val) {
t.Errorf("First item in object array does not match %q", val.ID)
}
}
func TestRecipients(t *testing.T) {
bob := PersonNew("bob")
alice := PersonNew("alice")
foo := OrganizationNew("foo")
bar := GroupNew("bar")
first := make(ItemCollection, 0)
if len(first) != 0 {
t.Errorf("Objects array should have exactly an element")
}
first.Append(bob)
first.Append(alice)
first.Append(foo)
first.Append(bar)
if len(first) != 4 {
t.Errorf("Objects array should have exactly 4(four) elements, not %d", len(first))
}
first.Append(bar)
first.Append(alice)
first.Append(foo)
first.Append(bob)
if len(first) != 8 {
t.Errorf("Objects array should have exactly 8(eight) elements, not %d", len(first))
}
ItemCollectionDeduplication(&first)
if len(first) != 4 {
t.Errorf("Objects array should have exactly 4(four) elements, not %d", len(first))
}
second := make(ItemCollection, 0)
second.Append(bar)
second.Append(foo)
ItemCollectionDeduplication(&first, &second)
if len(first) != 4 {
t.Errorf("First Objects array should have exactly 8(eight) elements, not %d", len(first))
}
if len(second) != 0 {
t.Errorf("Second Objects array should have exactly 0(zero) elements, not %d", len(second))
}
_, err := ItemCollectionDeduplication(&first, &second, nil)
if err != nil {
t.Errorf("Deduplication with empty array failed")
}
}
func TestNaturalLanguageValue_Get(t *testing.T) {
testVal := "test"
a := NaturalLanguageValues{{NilLangRef, testVal}}
if a.Get(NilLangRef) != testVal {
t.Errorf("Invalid Get result. Expected %s received %s", testVal, a.Get(NilLangRef))
}
}
func TestNaturalLanguageValue_Set(t *testing.T) {
testVal := "test"
a := NaturalLanguageValues{{NilLangRef, "ana are mere"}}
err := a.Set(LangRef("en"), testVal)
if err != nil {
t.Errorf("Received error when doing Set %s", err)
}
}
func TestNaturalLanguageValue_Append(t *testing.T) {
var a NaturalLanguageValues
if len(a) != 0 {
t.Errorf("Invalid initialization of %T. Size %d > 0 ", a, len(a))
}
langEn := LangRef("en")
valEn := "random value"
a.Append(langEn, valEn)
if len(a) != 1 {
t.Errorf("Invalid append of one element to %T. Size %d != 1", a, len(a))
}
if a.Get(langEn) != valEn {
t.Errorf("Invalid append of one element to %T. Value of %q not equal to %q, but %q", a, langEn, valEn, a.Get(langEn))
}
langDe := LangRef("de")
valDe := "randomisch"
a.Append(langDe, valDe)
if len(a) != 2 {
t.Errorf("Invalid append of one element to %T. Size %d != 2", a, len(a))
}
if a.Get(langEn) != valEn {
t.Errorf("Invalid append of one element to %T. Value of %q not equal to %q, but %q", a, langEn, valEn, a.Get(langEn))
}
if a.Get(langDe) != valDe {
t.Errorf("Invalid append of one element to %T. Value of %q not equal to %q, but %q", a, langDe, valDe, a.Get(langDe))
}
}
func TestLangRef_UnmarshalJSON(t *testing.T) {
lang := "en-US"
json := `"` + lang + `"`
var a LangRef
a.UnmarshalJSON([]byte(json))
if string(a) != lang {
t.Errorf("Invalid json unmarshal for %T. Expected %q, found %q", lang, lang, string(a))
}
}
func TestNaturalLanguageValue_UnmarshalFullObjectJSON(t *testing.T) {
langEn := "en-US"
valEn := "random"
langDe := "de-DE"
valDe := "zufällig\n"
//m := make(map[string]string)
//m[langEn] = valEn
//m[langDe] = valDe
json := `{
"` + langEn + `": "` + valEn + `",
"` + langDe + `": "` + valDe + `"
}`
a := make(NaturalLanguageValues, 0)
_ = a.Append(LangRef(langEn), valEn)
_ = a.Append(LangRef(langDe), valDe)
err := a.UnmarshalJSON([]byte(json))
if err != nil {
t.Error(err)
}
for lang, val := range a {
if val.Ref != LangRef(langEn) && val.Ref != LangRef(langDe) {
t.Errorf("Invalid json unmarshal for %T. Expected lang %q or %q, found %q", a, langEn, langDe, lang)
}
if val.Ref == LangRef(langEn) && val.Value != valEn {
t.Errorf("Invalid json unmarshal for %T. Expected value %q, found %q", a, valEn, val)
}
if val.Ref == LangRef(langDe) && val.Value != valDe {
t.Errorf("Invalid json unmarshal for %T. Expected value %q, found %q", a, valDe, val)
}
}
}
func validateEmptyObject(o Object, t *testing.T) {
if o.ID != "" {
t.Errorf("Unmarshaled object %T should have empty ID, received %q", o, o.ID)
}
if o.Type != "" {
t.Errorf("Unmarshaled object %T should have empty Type, received %q", o, o.Type)
}
if o.AttributedTo != nil {
t.Errorf("Unmarshaled object %T should have empty AttributedTo, received %q", o, o.AttributedTo)
}
if len(o.Name) != 0 {
t.Errorf("Unmarshaled object %T should have empty Name, received %q", o, o.Name)
}
if len(o.Summary) != 0 {
t.Errorf("Unmarshaled object %T should have empty Summary, received %q", o, o.Summary)
}
if len(o.Content) != 0 {
t.Errorf("Unmarshaled object %T should have empty Content, received %q", o, o.Content)
}
if o.URL != nil {
t.Errorf("Unmarshaled object %T should have empty URL, received %v", o, o.URL)
}
if o.Icon != nil {
t.Errorf("Unmarshaled object %T should have empty Icon, received %v", o, o.Icon)
}
if o.Image != nil {
t.Errorf("Unmarshaled object %T should have empty Image, received %v", o, o.Image)
}
if !o.Published.IsZero() {
t.Errorf("Unmarshaled object %T should have empty Published, received %q", o, o.Published)
}
if !o.StartTime.IsZero() {
t.Errorf("Unmarshaled object %T should have empty StartTime, received %q", o, o.StartTime)
}
if !o.Updated.IsZero() {
t.Errorf("Unmarshaled object %T should have empty Updated, received %q", o, o.Updated)
}
if !o.EndTime.IsZero() {
t.Errorf("Unmarshaled object %T should have empty EndTime, received %q", o, o.EndTime)
}
if o.Duration != 0 {
t.Errorf("Unmarshaled object %T should have empty Duration, received %q", o, o.Duration)
}
if len(o.To) > 0 {
t.Errorf("Unmarshaled object %T should have empty To, received %q", o, o.To)
}
if len(o.Bto) > 0 {
t.Errorf("Unmarshaled object %T should have empty Bto, received %q", o, o.Bto)
}
if len(o.CC) > 0 {
t.Errorf("Unmarshaled object %T should have empty CC, received %q", o, o.CC)
}
if len(o.BCC) > 0 {
t.Errorf("Unmarshaled object %T should have empty BCC, received %q", o, o.BCC)
}
validateEmptySource(o.Source, t)
}
func validateEmptySource(s Source, t *testing.T) {
if s.MediaType != "" {
t.Errorf("Unmarshalled object %T should have empty Source.MediaType, received %q", s, s.MediaType)
}
if s.Content != nil {
t.Errorf("Unmarshalled object %T should have empty Source.Content, received %q", s, s.Content)
}
}
func TestObject_UnmarshalJSON(t *testing.T) {
o := Object{}
dataEmpty := []byte("{}")
o.UnmarshalJSON(dataEmpty)
validateEmptyObject(o, t)
}
func TestMimeType_UnmarshalJSON(t *testing.T) {
m := MimeType("")
dataEmpty := []byte("")
m.UnmarshalJSON(dataEmpty)
if m != "" {
t.Errorf("Unmarshaled object %T should be an empty string, received %q", m, m)
}
}
func TestLangRefValue_String(t *testing.T) {
t.Skipf("TODO")
}
func TestLangRefValue_UnmarshalJSON(t *testing.T) {
t.Skipf("TODO")
}
func TestLangRefValue_UnmarshalText(t *testing.T) {
t.Skipf("TODO")
}
func TestLangRef_UnmarshalText(t *testing.T) {
l := LangRef("")
dataEmpty := []byte("")
l.UnmarshalText(dataEmpty)
if l != "" {
t.Errorf("Unmarshaled object %T should be an empty string, received %q", l, l)
}
}
func TestObjectID_UnmarshalJSON(t *testing.T) {
o := ObjectID("")
dataEmpty := []byte("")
o.UnmarshalJSON(dataEmpty)
if o != "" {
t.Errorf("Unmarshaled object %T should be an empty string, received %q", o, o)
}
}
func TestNaturalLanguageValue_UnmarshalJSON(t *testing.T) {
l := LangRef("")
dataEmpty := []byte("")
l.UnmarshalJSON(dataEmpty)
if l != "" {
t.Errorf("Unmarshaled object %T should be an empty string, received %q", l, l)
}
}
func TestNaturalLanguageValue_UnmarshalText(t *testing.T) {
l := LangRef("")
dataEmpty := []byte("")
l.UnmarshalText(dataEmpty)
if l != "" {
t.Errorf("Unmarshaled object %T should be an empty string, received %q", l, l)
}
}
func TestObject_GetID(t *testing.T) {
a := Object{}
testVal := "crash$"
a.ID = ObjectID(testVal)
if string(a.GetID()) != testVal {
t.Errorf("%T should return %q, Received %q", a.GetID, testVal, a.GetID())
}
}
func TestObject_GetLink(t *testing.T) {
a := Object{}
testVal := "crash$"
a.ID = ObjectID(testVal)
if string(a.GetLink()) != testVal {
t.Errorf("%T should return %q, Received %q", a.GetLink, testVal, a.GetLink())
}
}
func TestObject_GetType(t *testing.T) {
a := Object{}
a.Type = ActorType
if a.GetType() != ActorType {
t.Errorf("%T should return %q, Received %q", a.GetType, ActorType, a.GetType())
}
}
func TestNaturalLanguageValue_First(t *testing.T) {
t.Skipf("TODO")
}
func TestNaturalLanguageValueNew(t *testing.T) {
n := NaturalLanguageValuesNew()
if len(n) != 0 {
t.Errorf("Initial %T should have length 0, received %d", n, len(n))
}
}
func TestNaturalLanguageValue_MarshalText(t *testing.T) {
nlv := LangRefValue{
Ref: "en",
Value: "test",
}
tst := NaturalLanguageValues{nlv}
j, err := tst.MarshalText()
if err != nil {
t.Errorf("Error marshaling: %s", err)
}
if j == nil {
t.Errorf("Error marshaling: nil value returned")
}
expected := fmt.Sprintf("\"%s[%s]\"", nlv.Value, nlv.Ref)
if string(j) != expected {
t.Errorf("Wrong value: %s, expected %s", j, expected)
}
}
func TestNaturalLanguageValues_Append(t *testing.T) {
t.Skipf("TODO")
}
func TestNaturalLanguageValues_First(t *testing.T) {
t.Skipf("TODO")
}
func TestNaturalLanguageValues_Get(t *testing.T) {
t.Skipf("TODO")
}
func TestNaturalLanguageValues_MarshalJSON(t *testing.T) {
{
m := NaturalLanguageValues{
{
"en", "test",
},
{
"de", "test",
},
}
result, err := m.MarshalJSON()
if err != nil {
t.Errorf("Failed marshaling '%v'", err)
}
mRes := "{\"de\":\"test\",\"en\":\"test\"}"
if string(result) != mRes {
t.Errorf("Different results '%v' vs. '%v'", string(result), mRes)
}
//n := NaturalLanguageValuesNew()
//result, err := n.MarshalJSON()
s := make(map[LangRef]string)
s["en"] = "test"
n1 := NaturalLanguageValues{{
"en", "test",
}}
result1, err1 := n1.MarshalJSON()
if err1 != nil {
t.Errorf("Failed marshaling '%v'", err1)
}
mRes1 := `{"en":"test"}`
if string(result1) != mRes1 {
t.Errorf("Different results '%v' vs. '%v'", string(result1), mRes1)
}
}
{
nlv := LangRefValue{
Ref: NilLangRef,
Value: "test",
}
tst := NaturalLanguageValues{nlv}
j, err := tst.MarshalJSON()
if err != nil {
t.Errorf("Error marshaling: %s", err)
}
if j == nil {
t.Errorf("Error marshaling: nil value returned")
}
expected := fmt.Sprintf("\"%s\"", nlv.Value)
if string(j) != expected {
t.Errorf("Wrong value: %s, expected %s", j, expected)
}
}
{
nlv := LangRefValue{
Ref: "en",
Value: "test",
}
tst := NaturalLanguageValues{nlv}
j, err := tst.MarshalJSON()
if err != nil {
t.Errorf("Error marshaling: %s", err)
}
if j == nil {
t.Errorf("Error marshaling: nil value returned")
}
expected := fmt.Sprintf("{\"%s\":\"%s\"}", nlv.Ref, nlv.Value)
if string(j) != expected {
t.Errorf("Wrong value: %s, expected %s", j, expected)
}
}
{
nlvEn := LangRefValue{
Ref: "en",
Value: "test",
}
nlvFr := LangRefValue{
Ref: "fr",
Value: "teste",
}
tst := NaturalLanguageValues{nlvEn, nlvFr}
j, err := tst.MarshalJSON()
if err != nil {
t.Errorf("Error marshaling: %s", err)
}
if j == nil {
t.Errorf("Error marshaling: nil value returned")
}
expected := fmt.Sprintf("{\"%s\":\"%s\",\"%s\":\"%s\"}", nlvEn.Ref, nlvEn.Value, nlvFr.Ref, nlvFr.Value)
if string(j) != expected {
t.Errorf("Wrong value: %s, expected %s", j, expected)
}
}
{
nlvEn := LangRefValue{
Ref: "en",
Value: "test\nwith new line",
}
nlvFr := LangRefValue{
Ref: "fr",
Value: "teste\navec une ligne nouvelle",
}
tst := NaturalLanguageValues{nlvEn, nlvFr}
j, err := tst.MarshalJSON()
if err != nil {
t.Errorf("Error marshaling: %s", err)
}
if j == nil {
t.Errorf("Error marshaling: nil value returned")
}
expected := fmt.Sprintf("{\"%s\":%s,\"%s\":%s}", nlvEn.Ref, strconv.Quote(nlvEn.Value), nlvFr.Ref, strconv.Quote(nlvFr.Value))
if string(j) != expected {
t.Errorf("Wrong value: %s, expected %s", j, expected)
}
}
}
func TestNaturalLanguageValues_MarshalText(t *testing.T) {
t.Skipf("TODO")
}
func TestNaturalLanguageValues_Set(t *testing.T) {
t.Skipf("TODO")
}
func TestNaturalLanguageValues_UnmarshalJSON(t *testing.T) {
{
lang := []byte{'e', 'n'}
val := []byte{'a', 'n', 'a', ' ', 'a', 'r', 'e', ' ', 'm', 'e', 'r', 'e', '\n'}
js := fmt.Sprintf(`[{"%s": "%s"}]`, lang, val)
n := NaturalLanguageValues{}
err := n.UnmarshalJSON([]byte(js))
if err != nil {
t.Errorf("Unexpected error when unmarshaling %T: %s", n, err)
}
if n.Count() != 1 {
t.Errorf("Invalid number of elements %d, expected %d", n.Count(), 1)
}
l := n.First()
if l.Value != "ana are mere\n" {
t.Errorf("Invalid %T value %q, expected %q", l, l.Value, "ana are mere\n")
}
if l.Ref != "en" {
t.Errorf("Invalid %T ref %q, expected %q", l, l.Ref, "en")
}
}
{
ob := make(map[string]string)
ob["en"] = "ana are mere\n"
js, err := json.Marshal(ob)
if err != nil {
t.Errorf("Unexpected error when marshaling %T: %s", ob, err)
}
n := NaturalLanguageValues{}
err = n.UnmarshalJSON(js)
if err != nil {
t.Errorf("Unexpected error when unmarshaling %T: %s", n, err)
}
if n.Count() != 1 {
t.Errorf("Invalid number of elements %d, expected %d", n.Count(), 1)
}
l := n.First()
if l.Value != "ana are mere\n" {
t.Errorf("Invalid %T value %q, expected %q", l, l.Value, "ana are mere\n")
}
if l.Ref != "en" {
t.Errorf("Invalid %T ref %q, expected %q", l, l.Ref, "en")
}
}
}
func TestNaturalLanguageValues_UnmarshalText(t *testing.T) {
t.Skipf("TODO")
}
func TestNaturalLanguageValuesNew(t *testing.T) {
t.Skipf("TODO")
}
func TestToObject(t *testing.T) {
var it Item
ob := ObjectNew(ArticleType)
it = ob
o, err := ToObject(it)
if err != nil {
t.Error(err)
}
if o != ob {
t.Errorf("Invalid activity returned by ToObject #%v", ob)
}
act := ActivityNew("test", CreateType, nil)
it = act
a, err := ToObject(it)
if err != nil {
t.Errorf("Error returned when calling ToObject with activity should be nil, received %s", err)
}
if a == nil {
t.Errorf("Invalid return by ToObject #%v, should have not been nil", a)
}
}
func TestFlattenObjectProperties(t *testing.T) {
t.Skipf("TODO")
}
func TestFlattenProperties(t *testing.T) {
t.Skipf("TODO")
}
func TestToTombstone(t *testing.T) {
t.Skipf("TODO")
}
func TestToRelationship(t *testing.T) {
t.Skipf("TODO")
}
func TestObject_Recipients(t *testing.T) {
t.Skipf("TODO")
}
func TestRelationship_Recipients(t *testing.T) {
t.Skipf("TODO")
}
func TestTombstone_Recipients(t *testing.T) {
t.Skipf("TODO")
}
func TestNaturalLanguageValues_String(t *testing.T) {
t.Skipf("TODO")
}
func TestNaturalLanguageValues_Count(t *testing.T) {
t.Skipf("TODO")
}
func TestItemCollectionDeduplication(t *testing.T) {
t.Skipf("TODO")
}
func TestSource_UnmarshalJSON(t *testing.T) {
s := Source{}
dataEmpty := []byte("{}")
s.UnmarshalJSON(dataEmpty)
validateEmptySource(s, t)
}
func TestGetAPSource(t *testing.T) {
data := []byte(`{"source": {"content": "test", "mediaType": "text/plain" }}`)
a := GetAPSource(data)
if a.Content.First().String() != "test" {
t.Errorf("Content didn't match test value. Received %q, expecting %q", a.Content, "test")
}
if a.MediaType != "text/plain" {
t.Errorf("Content didn't match test value. Received %q, expecting %q", a.MediaType, "text/plain")
}
}