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

View File

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

View File

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

View File

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

View File

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

View File

@ -1,36 +1,36 @@
package mstdn_test package ent_test
import ( import (
"testing" "testing"
"encoding/json" "encoding/json"
"sourcecode.social/reiver/go-mstdn" "sourcecode.social/reiver/go-mstdn/ent"
) )
func TestField_UnmarshalJSON(t *testing.T) { func TestField_UnmarshalJSON(t *testing.T) {
tests := []struct{ tests := []struct{
JSON string JSON string
Expected mstdn.Field Expected ent.Field
}{ }{
{ {
JSON: `{"name":"Location","value":"Metro Vancouver"}`, 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}`, 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"}`, 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 { for testNumber, test := range tests {
var actual mstdn.Field var actual ent.Field
err := json.Unmarshal([]byte(test.JSON), &actual) err := json.Unmarshal([]byte(test.JSON), &actual)
if nil != err { if nil != err {

View File

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