-
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
package activitypub
import (
"testing"
)
func TestObjectNew(t *testing.T) {
var testValue = ObjectID("test")
var testType = ArticleType
o := ObjectNew(testValue, testType)
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(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 TestValidGenericType(t *testing.T) {
for _, validType := range validGenericObjectTypes {
if !ValidObjectType(validType) {
t.Errorf("Generic Type '%v' should be valid", validType)
}
}
}
func TestValidObjectType(t *testing.T) {
var invalidType ActivityVocabularyType = "RandomType"
if ValidObjectType(invalidType) {
t.Errorf("APObject Type '%v' should not be valid", invalidType)
}
for _, validType := range validObjectTypes {
if !ValidObjectType(validType) {
t.Errorf("APObject Type '%v' should be valid", validType)
}
}
}
func TestMarshalJSON(t *testing.T) {
m := make(map[LangRef]string)
m["en"] = "test"
m["de"] = "test"
n := NaturalLanguageValue(m)
result, err := n.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)
}
s := make(map[LangRef]string)
s["en"] = "test"
n1 := NaturalLanguageValue(s)
result1, err1 := n1.MarshalJSON()
if err1 != nil {
t.Errorf("Failed marshaling '%v'", err1)
}
mRes1 := "\"test\""
if string(result1) != mRes1 {
t.Errorf("Different results '%v' vs. '%v'", string(result1), mRes1)
}
}
func TestNaturalLanguageValue_MarshalJSON(t *testing.T) {
p := make(NaturalLanguageValue, 2)
p["en"] = "the test"
p["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 := make(NaturalLanguageValue, 1)
p1["en"] = "the test"
out1, err1 := p1.MarshalJSON()
if err1 != nil {
t.Errorf("Error: '%s'", err1)
}
txt := "\"the test\""
if txt != string(out1) {
t.Errorf("Different marshal result '%s', instead of '%s'", out1, txt)
}
}
func TestObject_IsLink(t *testing.T) {
o := ObjectNew("test", ObjectType)
if o.IsLink() {
t.Errorf("%#v should not be a valid link", o.Type)
}
m := ObjectNew("test", AcceptType)
if m.IsLink() {
t.Errorf("%#v should not be a valid link", m.Type)
}
}
func TestObject_IsObject(t *testing.T) {
o := ObjectNew("test", ObjectType)
if !o.IsObject() {
t.Errorf("%#v should be a valid object", o.Type)
}
m := ObjectNew("test", AcceptType)
if !m.IsObject() {
t.Errorf("%#v should be a valid object", m.Type)
}
}