From 5e83d940acfc9306a12a30dc77a68caa098c89b5 Mon Sep 17 00:00:00 2001 From: Charles Iliya Krempeaux Date: Tue, 13 Feb 2024 09:02:16 -0800 Subject: [PATCH] initial commits --- writeframeposturl.go | 21 ++++++++++++ writeframeposturl_test.go | 68 +++++++++++++++++++++++++++++++++++++++ 2 files changed, 89 insertions(+) create mode 100644 writeframeposturl.go create mode 100644 writeframeposturl_test.go diff --git a/writeframeposturl.go b/writeframeposturl.go new file mode 100644 index 0000000..0dbe6ec --- /dev/null +++ b/writeframeposturl.go @@ -0,0 +1,21 @@ +package frameproto + +import ( + "io" +) + +// WriteFramePostURL will write the HTML element for the Frame-Protocol's (i.e., Farcaster Frame's) "fc:frame:post_url" name-value pair. +// +// For example, this call: +// +// var url string = "https://example.com/my/post/path.php" +// +// WriteFramePostURL(writer, url) +// +// Would write this HTML element: +// +// +func WriteFramePostURL(writer io.Writer, url string) { + const property string = MetaPropertyFramePostURL + writeMetaPropertyContent(writer, property, url) +} diff --git a/writeframeposturl_test.go b/writeframeposturl_test.go new file mode 100644 index 0000000..450119e --- /dev/null +++ b/writeframeposturl_test.go @@ -0,0 +1,68 @@ +package frameproto + +import ( + "testing" + + "strings" +) + +func TestWriteFramePostURL(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.php", + Expected: ``+"\n", + }, + + + + { + URL: "x-proto:apple/banana/cherry", + Expected: ``+"\n", + }, + } + + for testNumber, test := range tests { + + var buffer strings.Builder + + WriteFramePostURL(&buffer, test.URL) + + expected := test.Expected + actual := buffer.String() + + 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 + } + } +}