initial commits

master
Charles Iliya Krempeaux 2024-02-14 16:21:28 -08:00
parent b6bf3ab0c2
commit 4ae1dccf55
2 changed files with 117 additions and 0 deletions

View File

@ -0,0 +1,21 @@
package frameproto
// AppendFrameInputText will append the HTML <meta/> 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 <meta/> element:
//
// <meta property="fc:frame:input:text" content="enter your username" />
func AppendFrameInputText(p []byte, url string) []byte {
const property string = MetaPropertyFrameInputText
return appendMetaPropertyContent(p, property, url)
}

View File

@ -0,0 +1,96 @@
package frameproto
import (
"testing"
)
func TestAppendFrameInputText(t *testing.T) {
tests := []struct{
Version string
Expected string
}{
{
Version: "",
Expected: `<meta property="fc:frame:input:text" content="" />`+"\n",
},
{
Version: "something",
Expected: `<meta property="fc:frame:input:text" content="something" />`+"\n",
},
{
Version: "Hello world! 🙂",
Expected: `<meta property="fc:frame:input:text" content="Hello world! 🙂" />`+"\n",
},
{
Version: "enter your username",
Expected: `<meta property="fc:frame:input:text" content="enter your username" />`+"\n",
},
{
Version: "I like to eat, eat, eat, apples and banana",
Expected: `<meta property="fc:frame:input:text" content="I like to eat, eat, eat, apples and banana" />`+"\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 = "<html>\n<head>\n"
const bottom string = "</head>\n<body>\n</body>\n</html>\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
}
}
}
}