Changes
2 changed files (+88/-1)
-
-
@@ -1,6 +1,7 @@package activitypub import ( "github.com/buger/jsonparser" "net/url" "path" "strings"
-
@@ -113,6 +114,29 @@ func (i IRIs) MarshalJSON() ([]byte, error) {return b, nil } func (i *IRIs) UnmarshalJSON(data []byte) error { if i == nil { return nil } value, typ, _, err := jsonparser.Get(data) if err != nil { return err } switch typ { case jsonparser.String: if iri, ok := asIRI(value); ok { *i = append(*i, iri) } case jsonparser.Array: jsonparser.ArrayEach(data, func(value []byte, dataType jsonparser.ValueType, offset int, err error) { if iri, ok := asIRI(value); ok { *i = append(*i, iri) } }) } return nil } // Contains verifies if IRIs array contains the received one func (i IRIs) Contains(r IRI) bool { if len(i) == 0 {
-
@@ -204,3 +228,7 @@ func (i IRI) Contains(what IRI, checkScheme bool) bool {} return strings.Contains(p, pw) } func (i IRI) ItemMatches(it Item) bool { return it.GetLink().Contains(i, false) }
-
-
-
@@ -1,6 +1,10 @@package activitypub import "testing" import ( "fmt" "reflect" "testing" ) func TestIRI_GetLink(t *testing.T) { val := "http://example.com"
-
@@ -59,6 +63,20 @@ func TestIRI_UnmarshalJSON(t *testing.T) {} } 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") }
-
@@ -218,3 +236,44 @@ func TestIRI_Contains(t *testing.T) {func TestIRI_IsCollection(t *testing.T) { t.Skip("TODO") } func TestIRIs_UnmarshalJSON(t *testing.T) { value1 := []byte("http://example.com") value2 := []byte("http://example.net") value3 := []byte("http://example.org") i := make(IRIs, 0) err := i.UnmarshalJSON([]byte(fmt.Sprintf("[%q, %q, %q]", value1, value2, value3))) if err != nil { t.Error(err) } expected:= IRIs{ IRI(value1), IRI(value2), IRI(value3), } if !reflect.DeepEqual(i, expected) { t.Errorf("%T invalid value after UnmarshalJSON %#v, expected %#v", i, i, expected) } } 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) } }
-