From ff90f59879ba94cefd15458c9813a4c486a3a75d Mon Sep 17 00:00:00 2001 From: Charles Iliya Krempeaux Date: Thu, 15 Feb 2024 05:00:36 -0800 Subject: [PATCH] initial commits --- stringframeimage.go | 18 ++++++++++++ stringframeimage_test.go | 63 ++++++++++++++++++++++++++++++++++++++++ 2 files changed, 81 insertions(+) create mode 100644 stringframeimage.go create mode 100644 stringframeimage_test.go diff --git a/stringframeimage.go b/stringframeimage.go new file mode 100644 index 0000000..8735b94 --- /dev/null +++ b/stringframeimage.go @@ -0,0 +1,18 @@ +package frameproto + +// StringFrameImage will return the HTML element for the Frame-Protocol's (i.e., Farcaster Frame's) "fc:frame:image" name-value pair. +// +// For example, this call: +// +// var url string = "https://example.com/images/screen.png" +// +// str := frameproto.StringFrameImage(url) +// +// Would return this HTML element: +// +// +func StringFrameImage(url string) string { + const property string = MetaPropertyFrameImage + return stringMetaPropertyContent(property, url) +} + diff --git a/stringframeimage_test.go b/stringframeimage_test.go new file mode 100644 index 0000000..fcbc4c9 --- /dev/null +++ b/stringframeimage_test.go @@ -0,0 +1,63 @@ +package frameproto + +import ( + "testing" +) + +func TestStringFrameImage(t *testing.T) { + + tests := []struct{ + URL string + Expected string + }{ + { + URL: "", + Expected: ``+"\n", + }, + + + + { + URL: "something", + Expected: ``+"\n", + }, + + + + { + URL: "Hello world! 🙂", + Expected: ``+"\n", + }, + + + + { + URL: "https://example.com/path/to/post/to.png", + Expected: ``+"\n", + }, + + + + { + URL: "x-proto:apple/banana/cherry", + Expected: ``+"\n", + }, + } + + for testNumber, test := range tests { + + actual := StringFrameImage(test.URL) + + expected := test.Expected + + if expected != actual { + t.Errorf("For test #%d, the actual written meta-tag is not what was expected." ,testNumber) + t.Logf("EXPECTED: %s", expected) + t.Logf("ACTUAL: %s", actual) + t.Logf("EXPECTED: %q", expected) + t.Logf("ACTUAL: %q", actual) + t.Logf("URL: %q", test.URL) + continue + } + } +}