initial commits

master
Charles Iliya Krempeaux 2023-09-26 14:29:10 +09:00
parent 3a2cac064f
commit 41c553b90a
8 changed files with 30 additions and 30 deletions

View File

@ -1,4 +1,4 @@
package mstdn
package ent
import (
"encoding/json"
@ -10,10 +10,10 @@ import (
var _ json.Marshaler = CustomEmoji{}
const (
errCannotMashalCustomEmojiAsJSONNoShortCode = erorr.Error("cannot marshal mstdn.CustomEmoji to JSON — no shortcode set")
errCannotMashalCustomEmojiAsJSONNoURL = erorr.Error("cannot marshal mstdn.CustomEmoji to JSON — no url set")
errCannotMashalCustomEmojiAsJSONNoStaticURL = erorr.Error("cannot marshal mstdn.CustomEmoji to JSON — no static_url set")
errCannotMashalCustomEmojiAsJSONNoVisibleInPicker = erorr.Error("cannot marshal mstdn.CustomEmoji to JSON — no visible_in_picker set")
errCannotMashalCustomEmojiAsJSONNoShortCode = erorr.Error("cannot marshal ent.CustomEmoji to JSON — no shortcode set")
errCannotMashalCustomEmojiAsJSONNoURL = erorr.Error("cannot marshal ent.CustomEmoji to JSON — no url set")
errCannotMashalCustomEmojiAsJSONNoStaticURL = erorr.Error("cannot marshal ent.CustomEmoji to JSON — no static_url set")
errCannotMashalCustomEmojiAsJSONNoVisibleInPicker = erorr.Error("cannot marshal ent.CustomEmoji to JSON — no visible_in_picker set")
)
// CustomEmoji represents a Mastodon API "CustomEmoji".

View File

@ -1,4 +1,4 @@
package mstdn
package ent
import (
"testing"

View File

@ -1,4 +1,4 @@
package mstdn
package ent
import (
"sourcecode.social/reiver/go-erorr"

View File

@ -1,4 +1,4 @@
package mstdn
package ent
import (
"encoding/json"
@ -12,8 +12,8 @@ var _ json.Marshaler = Field{}
var _ json.Unmarshaler = &Field{}
const (
errCannotMashalFieldAsJSONNoName = erorr.Error("cannot marshal mstdn.Field to JSON — no name set")
errCannotMashalFieldAsJSONNoValue = erorr.Error("cannot marshal mstdn.Field to JSON — no value set")
errCannotMashalFieldAsJSONNoName = erorr.Error("cannot marshal ent.Field to JSON — no name set")
errCannotMashalFieldAsJSONNoValue = erorr.Error("cannot marshal ent.Field to JSON — no value set")
)
// Field represents a Mastodon API "Field".

View File

@ -1,4 +1,4 @@
package mstdn_test
package ent_test
import (
"testing"
@ -6,17 +6,17 @@ import (
"bytes"
"encoding/json"
"sourcecode.social/reiver/go-mstdn"
"sourcecode.social/reiver/go-mstdn/ent"
)
func TestField_MarshalJSON(t *testing.T) {
tests := []struct{
Value mstdn.Field
Value ent.Field
Expected string
}{
{
Value: mstdn.FieldNameValue("", ""),
Value: ent.FieldNameValue("", ""),
Expected:
"{" +"\n"+
"\t"+ `"name":` +`""` +"," +"\n"+
@ -28,7 +28,7 @@ func TestField_MarshalJSON(t *testing.T) {
{
Value: mstdn.FieldNameValue("NAME", ""),
Value: ent.FieldNameValue("NAME", ""),
Expected:
"{" +"\n"+
"\t"+ `"name":` +`"NAME"` +"," +"\n"+
@ -37,7 +37,7 @@ func TestField_MarshalJSON(t *testing.T) {
"}" +"\n",
},
{
Value: mstdn.FieldNameValue("", "VALUE"),
Value: ent.FieldNameValue("", "VALUE"),
Expected:
"{" +"\n"+
"\t"+ `"name":` +`""` +"," +"\n"+
@ -46,7 +46,7 @@ func TestField_MarshalJSON(t *testing.T) {
"}" +"\n",
},
{
Value: mstdn.FieldNameValue("NAME", "VALUE"),
Value: ent.FieldNameValue("NAME", "VALUE"),
Expected:
"{" +"\n"+
"\t"+ `"name":` +`"NAME"` +"," +"\n"+
@ -58,7 +58,7 @@ func TestField_MarshalJSON(t *testing.T) {
{
Value: mstdn.FieldNameValue("age", "47"),
Value: ent.FieldNameValue("age", "47"),
Expected:
"{" +"\n"+
"\t"+ `"name":` +`"age"` +"," +"\n"+
@ -70,7 +70,7 @@ func TestField_MarshalJSON(t *testing.T) {
{
Value: mstdn.FieldVerifiedNameValue("2023-09-22T22:45:22Z", "NAME", ""),
Value: ent.FieldVerifiedNameValue("2023-09-22T22:45:22Z", "NAME", ""),
Expected:
"{" +"\n"+
"\t"+ `"name":` +`"NAME"` +"," +"\n"+
@ -79,7 +79,7 @@ func TestField_MarshalJSON(t *testing.T) {
"}" +"\n",
},
{
Value: mstdn.FieldVerifiedNameValue("2023-09-22T22:45:22Z", "", "VALUE"),
Value: ent.FieldVerifiedNameValue("2023-09-22T22:45:22Z", "", "VALUE"),
Expected:
"{" +"\n"+
"\t"+ `"name":` +`""` +"," +"\n"+
@ -88,7 +88,7 @@ func TestField_MarshalJSON(t *testing.T) {
"}" +"\n",
},
{
Value: mstdn.FieldVerifiedNameValue("2023-09-22T22:45:22Z", "NAME", "VALUE"),
Value: ent.FieldVerifiedNameValue("2023-09-22T22:45:22Z", "NAME", "VALUE"),
Expected:
"{" +"\n"+
"\t"+ `"name":` +`"NAME"` +"," +"\n"+
@ -100,7 +100,7 @@ func TestField_MarshalJSON(t *testing.T) {
{
Value: mstdn.FieldVerifiedNameValue("2023-09-22T22:45:22Z", "age", "47"),
Value: ent.FieldVerifiedNameValue("2023-09-22T22:45:22Z", "age", "47"),
Expected:
"{" +"\n"+
"\t"+ `"name":` +`"age"` +"," +"\n"+

View File

@ -1,36 +1,36 @@
package mstdn_test
package ent_test
import (
"testing"
"encoding/json"
"sourcecode.social/reiver/go-mstdn"
"sourcecode.social/reiver/go-mstdn/ent"
)
func TestField_UnmarshalJSON(t *testing.T) {
tests := []struct{
JSON string
Expected mstdn.Field
Expected ent.Field
}{
{
JSON: `{"name":"Location","value":"Metro Vancouver"}`,
Expected: mstdn.FieldNameValue("Location", "Metro Vancouver"),
Expected: ent.FieldNameValue("Location", "Metro Vancouver"),
},
{
JSON: `{"name":"Location","value":"Metro Vancouver", "verified_at":null}`,
Expected: mstdn.FieldNameValue("Location", "Metro Vancouver"),
Expected: ent.FieldNameValue("Location", "Metro Vancouver"),
},
{
JSON: `{"name":"Location","value":"Metro Vancouver", "verified_at":"2023-09-22T22:45:22Z"}`,
Expected: mstdn.FieldVerifiedNameValue("2023-09-22T22:45:22Z", "Location", "Metro Vancouver"),
Expected: ent.FieldVerifiedNameValue("2023-09-22T22:45:22Z", "Location", "Metro Vancouver"),
},
}
for testNumber, test := range tests {
var actual mstdn.Field
var actual ent.Field
err := json.Unmarshal([]byte(test.JSON), &actual)
if nil != err {

View File

@ -1,4 +1,4 @@
package mstdn
package ent
import (
"sourcecode.social/reiver/go-opt"