From 4ae1dccf5531c3c586439f63ffa5c7896c8f9ddb Mon Sep 17 00:00:00 2001 From: Charles Iliya Krempeaux Date: Wed, 14 Feb 2024 16:21:28 -0800 Subject: [PATCH] initial commits --- appendframeinputtext.go | 21 ++++++++ appendframeinputtext_test.go | 96 ++++++++++++++++++++++++++++++++++++ 2 files changed, 117 insertions(+) create mode 100644 appendframeinputtext.go create mode 100644 appendframeinputtext_test.go diff --git a/appendframeinputtext.go b/appendframeinputtext.go new file mode 100644 index 0000000..ac521fd --- /dev/null +++ b/appendframeinputtext.go @@ -0,0 +1,21 @@ +package frameproto + +// AppendFrameInputText will append the HTML element for the Frame-Protocol's (i.e., Farcaster Frame's) "fc:frame:input:text" name-value pair. +// +// For example, this call: +// +// var p []byte +// +// // ... +// +// var label string = "enter your username +// +// p = frameproto.AppendFrameInputText(p, label) +// +// Would append this HTML element: +// +// +func AppendFrameInputText(p []byte, url string) []byte { + const property string = MetaPropertyFrameInputText + return appendMetaPropertyContent(p, property, url) +} diff --git a/appendframeinputtext_test.go b/appendframeinputtext_test.go new file mode 100644 index 0000000..7de1e02 --- /dev/null +++ b/appendframeinputtext_test.go @@ -0,0 +1,96 @@ +package frameproto + +import ( + "testing" +) + +func TestAppendFrameInputText(t *testing.T) { + + tests := []struct{ + Version string + Expected string + }{ + { + Version: "", + Expected: ``+"\n", + }, + + + + { + Version: "something", + Expected: ``+"\n", + }, + + + + { + Version: "Hello world! 🙂", + Expected: ``+"\n", + }, + + + + { + Version: "enter your username", + Expected: ``+"\n", + }, + + + + { + Version: "I like to eat, eat, eat, apples and banana", + Expected: ``+"\n", + }, + } + + for testNumber, test := range tests { + + { + var buffer [256]byte + var p []byte = buffer[0:0] + + p = AppendFrameInputText(p, test.Version) + + expected := test.Expected + actual := string(p) + + 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("LABEL: %q", test.Version) + continue + } + } + + { + const top string = "\n\n" + const bottom string = "\n\n\n\n" + + var buffer [256]byte + var p []byte = buffer[0:0] + + p = append(p, top...) + + p = AppendFrameInputText(p, test.Version) + + p = append(p, bottom...) + + expected := top + test.Expected + bottom + actual := string(p) + + 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("LABEL: %q", test.Version) + continue + } + } + } +}