From 37b9f5d181f92f1b3462dab8fb848948cb04496a Mon Sep 17 00:00:00 2001 From: Charles Iliya Krempeaux Date: Tue, 26 Sep 2023 13:49:02 +0900 Subject: [PATCH] initial commits --- field_unmarshaljson_test.go | 54 +++++++++++++++++++++++++++++++++++++ 1 file changed, 54 insertions(+) create mode 100644 field_unmarshaljson_test.go diff --git a/field_unmarshaljson_test.go b/field_unmarshaljson_test.go new file mode 100644 index 0000000..0d30d7a --- /dev/null +++ b/field_unmarshaljson_test.go @@ -0,0 +1,54 @@ +package mstdn_test + +import ( + "testing" + + "encoding/json" + + "sourcecode.social/reiver/go-mstdn" +) + +func TestField_UnmarshalJSON(t *testing.T) { + + tests := []struct{ + JSON string + Expected mstdn.Field + }{ + { + JSON: `{"name":"Location","value":"Metro Vancouver"}`, + Expected: mstdn.FieldNameValue("Location", "Metro Vancouver"), + }, + { + JSON: `{"name":"Location","value":"Metro Vancouver", "verified_at":null}`, + Expected: mstdn.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"), + }, + } + + for testNumber, test := range tests { + + var actual mstdn.Field + + err := json.Unmarshal([]byte(test.JSON), &actual) + if nil != err { + t.Errorf("For test #%d,did not expect an error but actually got one." , testNumber) + t.Logf("ERROR: (%T) %s", err, err) + t.Logf("JSON: %q", test.JSON) + t.Logf("EXPECTED %#v", test.Expected) + continue + } + + expected := test.Expected + + if expected != actual { + t.Errorf("For test #%d, the actual value is not what was expected.", testNumber) + t.Logf("EXPECTED: %#v", expected) + t.Logf("ACTUAL: %#v", actual) + t.Logf("JSON: %q", test.JSON) + continue + } + } +}