initial commits
parent
34532b32d5
commit
141be61623
|
@ -0,0 +1,28 @@
|
|||
package frameproto
|
||||
|
||||
// AppendFrame will append the HTML <meta/> element for the Frame-Protocol's (i.e., Farcaster Frame's) "fc:frame" name-value pair.
|
||||
//
|
||||
// For example, this call:
|
||||
//
|
||||
// var p []byte
|
||||
//
|
||||
// // ...
|
||||
//
|
||||
// var version string = "vNext"
|
||||
//
|
||||
// p = frameproto.AppendFrame(p, version)
|
||||
//
|
||||
// Would append this HTML <meta/> element:
|
||||
//
|
||||
// <meta property="fc:frame" content="vNext" />
|
||||
//
|
||||
// Note that this package provides some constants to use with AppendFrame.
|
||||
// Namely: VersionVNext (for "vNext").
|
||||
//
|
||||
// Which in code would be used as:
|
||||
//
|
||||
// p = frameproto.AppendFrame(p, frameproto.VersionVNext)
|
||||
func AppendFrame(p []byte, version string) []byte {
|
||||
const property string = MetaPropertyFrame
|
||||
return appendMetaPropertyContent(p, property, version)
|
||||
}
|
|
@ -0,0 +1,96 @@
|
|||
package frameproto
|
||||
|
||||
import (
|
||||
"testing"
|
||||
)
|
||||
|
||||
func TestAppendFrame(t *testing.T) {
|
||||
|
||||
tests := []struct{
|
||||
Version string
|
||||
Expected string
|
||||
}{
|
||||
{
|
||||
Version: "",
|
||||
Expected: `<meta property="fc:frame" content="" />`+"\n",
|
||||
},
|
||||
|
||||
|
||||
|
||||
{
|
||||
Version: "something",
|
||||
Expected: `<meta property="fc:frame" content="something" />`+"\n",
|
||||
},
|
||||
|
||||
|
||||
|
||||
{
|
||||
Version: "Hello world! 🙂",
|
||||
Expected: `<meta property="fc:frame" content="Hello world! 🙂" />`+"\n",
|
||||
},
|
||||
|
||||
|
||||
|
||||
{
|
||||
Version: "vNext",
|
||||
Expected: `<meta property="fc:frame" content="vNext" />`+"\n",
|
||||
},
|
||||
|
||||
|
||||
|
||||
{
|
||||
Version: "2020-01-01",
|
||||
Expected: `<meta property="fc:frame" content="2020-01-01" />`+"\n",
|
||||
},
|
||||
}
|
||||
|
||||
for testNumber, test := range tests {
|
||||
|
||||
{
|
||||
var buffer [256]byte
|
||||
var p []byte = buffer[0:0]
|
||||
|
||||
p = AppendFrame(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 = AppendFrame(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
|
||||
}
|
||||
}
|
||||
}
|
||||
}
|
Loading…
Reference in New Issue