initial commits

master
Charles Iliya Krempeaux 2024-02-15 07:18:41 -08:00
parent ac6d9d2f99
commit c22e57f699
8 changed files with 564 additions and 0 deletions

View File

@ -0,0 +1,40 @@
package frameproto
// AppendFrameButton1Action will append the HTML <meta/> element for the Frame-Protocol's (i.e., Farcaster Frame's) "fc:frame:button:1:action" name-value pair.
//
// For example, this call:
//
// var p []byte
//
// // ..
//
// var buttonAction string = "post"
//
// p = frameproto.AppendFrameButton1Action(p, aspectRatio)
//
// Would append this HTML <meta/> element:
//
// <meta property="fc:frame:button:1:action" content="post" />
//
// Note that this package provides some constants to use with AppendFrameButton1Action.
// Namely: ButtonActionLink (for "link"), ButtonActionMint (for "mint"), ButtonActionPost (for "post"), and ButtonActionPostRedirect (for "post_redirect").
//
// Which in code would be used as:
//
// p = frameproto.AppendFrameButton1Action(p, frameproto.ButtonActionLink)
//
// And:
//
// p = frameproto.AppendFrameButton1Action(p, frameproto.ButtonActionMint)
//
// And:
//
// str :+ frameproto.AppendFrameButton1Action(p, frameproto.ButtonActionPost)
//
// And:
//
// p = frameproto.AppendFrameButton1Action(p, frameproto.ButtonActionPostRedirect)
func AppendFrameButton1Action(p []byte, action string) []byte {
const property string = MetaPropertyFrameButton1Action
return appendMetaPropertyContent(p, property, action)
}

View File

@ -0,0 +1,101 @@
package frameproto
import (
"testing"
)
func TestAppendFrameButton1Action(t *testing.T) {
tests := []struct{
Label string
Expected string
}{
{
Label: "",
Expected: `<meta property="fc:frame:button:1:action" content="" />`+"\n",
},
{
Label: "something",
Expected: `<meta property="fc:frame:button:1:action" content="something" />`+"\n",
},
{
Label: "Hello world! 🙂",
Expected: `<meta property="fc:frame:button:1:action" content="Hello world! 🙂" />`+"\n",
},
{
Label: "link",
Expected: `<meta property="fc:frame:button:1:action" content="link" />`+"\n",
},
{
Label: "mint",
Expected: `<meta property="fc:frame:button:1:action" content="mint" />`+"\n",
},
{
Label: "post",
Expected: `<meta property="fc:frame:button:1:action" content="post" />`+"\n",
},
{
Label: "post_redirect",
Expected: `<meta property="fc:frame:button:1:action" content="post_redirect" />`+"\n",
},
}
for testNumber, test := range tests {
{
var buffer [256]byte
var p []byte = buffer[0:0]
p = AppendFrameButton1Action(p, test.Label)
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.Label)
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 = AppendFrameButton1Action(p, test.Label)
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.Label)
continue
}
}
}
}

View File

@ -0,0 +1,40 @@
package frameproto
// AppendFrameButton2Action will append the HTML <meta/> element for the Frame-Protocol's (i.e., Farcaster Frame's) "fc:frame:button:2:action" name-value pair.
//
// For example, this call:
//
// var p []byte
//
// // ..
//
// var buttonAction string = "post"
//
// p = frameproto.AppendFrameButton2Action(p, aspectRatio)
//
// Would append this HTML <meta/> element:
//
// <meta property="fc:frame:button:2:action" content="post" />
//
// Note that this package provides some constants to use with AppendFrameButton2Action.
// Namely: ButtonActionLink (for "link"), ButtonActionMint (for "mint"), ButtonActionPost (for "post"), and ButtonActionPostRedirect (for "post_redirect").
//
// Which in code would be used as:
//
// p = frameproto.AppendFrameButton2Action(p, frameproto.ButtonActionLink)
//
// And:
//
// p = frameproto.AppendFrameButton2Action(p, frameproto.ButtonActionMint)
//
// And:
//
// str :+ frameproto.AppendFrameButton2Action(p, frameproto.ButtonActionPost)
//
// And:
//
// p = frameproto.AppendFrameButton2Action(p, frameproto.ButtonActionPostRedirect)
func AppendFrameButton2Action(p []byte, action string) []byte {
const property string = MetaPropertyFrameButton2Action
return appendMetaPropertyContent(p, property, action)
}

View File

@ -0,0 +1,101 @@
package frameproto
import (
"testing"
)
func TestAppendFrameButton2Action(t *testing.T) {
tests := []struct{
Label string
Expected string
}{
{
Label: "",
Expected: `<meta property="fc:frame:button:2:action" content="" />`+"\n",
},
{
Label: "something",
Expected: `<meta property="fc:frame:button:2:action" content="something" />`+"\n",
},
{
Label: "Hello world! 🙂",
Expected: `<meta property="fc:frame:button:2:action" content="Hello world! 🙂" />`+"\n",
},
{
Label: "link",
Expected: `<meta property="fc:frame:button:2:action" content="link" />`+"\n",
},
{
Label: "mint",
Expected: `<meta property="fc:frame:button:2:action" content="mint" />`+"\n",
},
{
Label: "post",
Expected: `<meta property="fc:frame:button:2:action" content="post" />`+"\n",
},
{
Label: "post_redirect",
Expected: `<meta property="fc:frame:button:2:action" content="post_redirect" />`+"\n",
},
}
for testNumber, test := range tests {
{
var buffer [256]byte
var p []byte = buffer[0:0]
p = AppendFrameButton2Action(p, test.Label)
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.Label)
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 = AppendFrameButton2Action(p, test.Label)
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.Label)
continue
}
}
}
}

View File

@ -0,0 +1,40 @@
package frameproto
// AppendFrameButton3Action will append the HTML <meta/> element for the Frame-Protocol's (i.e., Farcaster Frame's) "fc:frame:button:3:action" name-value pair.
//
// For example, this call:
//
// var p []byte
//
// // ..
//
// var buttonAction string = "post"
//
// p = frameproto.AppendFrameButton3Action(p, aspectRatio)
//
// Would append this HTML <meta/> element:
//
// <meta property="fc:frame:button:3:action" content="post" />
//
// Note that this package provides some constants to use with AppendFrameButton3Action.
// Namely: ButtonActionLink (for "link"), ButtonActionMint (for "mint"), ButtonActionPost (for "post"), and ButtonActionPostRedirect (for "post_redirect").
//
// Which in code would be used as:
//
// p = frameproto.AppendFrameButton3Action(p, frameproto.ButtonActionLink)
//
// And:
//
// p = frameproto.AppendFrameButton3Action(p, frameproto.ButtonActionMint)
//
// And:
//
// str :+ frameproto.AppendFrameButton3Action(p, frameproto.ButtonActionPost)
//
// And:
//
// p = frameproto.AppendFrameButton3Action(p, frameproto.ButtonActionPostRedirect)
func AppendFrameButton3Action(p []byte, action string) []byte {
const property string = MetaPropertyFrameButton3Action
return appendMetaPropertyContent(p, property, action)
}

View File

@ -0,0 +1,101 @@
package frameproto
import (
"testing"
)
func TestAppendFrameButton3Action(t *testing.T) {
tests := []struct{
Label string
Expected string
}{
{
Label: "",
Expected: `<meta property="fc:frame:button:3:action" content="" />`+"\n",
},
{
Label: "something",
Expected: `<meta property="fc:frame:button:3:action" content="something" />`+"\n",
},
{
Label: "Hello world! 🙂",
Expected: `<meta property="fc:frame:button:3:action" content="Hello world! 🙂" />`+"\n",
},
{
Label: "link",
Expected: `<meta property="fc:frame:button:3:action" content="link" />`+"\n",
},
{
Label: "mint",
Expected: `<meta property="fc:frame:button:3:action" content="mint" />`+"\n",
},
{
Label: "post",
Expected: `<meta property="fc:frame:button:3:action" content="post" />`+"\n",
},
{
Label: "post_redirect",
Expected: `<meta property="fc:frame:button:3:action" content="post_redirect" />`+"\n",
},
}
for testNumber, test := range tests {
{
var buffer [256]byte
var p []byte = buffer[0:0]
p = AppendFrameButton3Action(p, test.Label)
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.Label)
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 = AppendFrameButton3Action(p, test.Label)
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.Label)
continue
}
}
}
}

View File

@ -0,0 +1,40 @@
package frameproto
// AppendFrameButton4Action will append the HTML <meta/> element for the Frame-Protocol's (i.e., Farcaster Frame's) "fc:frame:button:4:action" name-value pair.
//
// For example, this call:
//
// var p []byte
//
// // ..
//
// var buttonAction string = "post"
//
// p = frameproto.AppendFrameButton4Action(p, aspectRatio)
//
// Would append this HTML <meta/> element:
//
// <meta property="fc:frame:button:4:action" content="post" />
//
// Note that this package provides some constants to use with AppendFrameButton4Action.
// Namely: ButtonActionLink (for "link"), ButtonActionMint (for "mint"), ButtonActionPost (for "post"), and ButtonActionPostRedirect (for "post_redirect").
//
// Which in code would be used as:
//
// p = frameproto.AppendFrameButton4Action(p, frameproto.ButtonActionLink)
//
// And:
//
// p = frameproto.AppendFrameButton4Action(p, frameproto.ButtonActionMint)
//
// And:
//
// str :+ frameproto.AppendFrameButton4Action(p, frameproto.ButtonActionPost)
//
// And:
//
// p = frameproto.AppendFrameButton4Action(p, frameproto.ButtonActionPostRedirect)
func AppendFrameButton4Action(p []byte, action string) []byte {
const property string = MetaPropertyFrameButton4Action
return appendMetaPropertyContent(p, property, action)
}

View File

@ -0,0 +1,101 @@
package frameproto
import (
"testing"
)
func TestAppendFrameButton4Action(t *testing.T) {
tests := []struct{
Label string
Expected string
}{
{
Label: "",
Expected: `<meta property="fc:frame:button:4:action" content="" />`+"\n",
},
{
Label: "something",
Expected: `<meta property="fc:frame:button:4:action" content="something" />`+"\n",
},
{
Label: "Hello world! 🙂",
Expected: `<meta property="fc:frame:button:4:action" content="Hello world! 🙂" />`+"\n",
},
{
Label: "link",
Expected: `<meta property="fc:frame:button:4:action" content="link" />`+"\n",
},
{
Label: "mint",
Expected: `<meta property="fc:frame:button:4:action" content="mint" />`+"\n",
},
{
Label: "post",
Expected: `<meta property="fc:frame:button:4:action" content="post" />`+"\n",
},
{
Label: "post_redirect",
Expected: `<meta property="fc:frame:button:4:action" content="post_redirect" />`+"\n",
},
}
for testNumber, test := range tests {
{
var buffer [256]byte
var p []byte = buffer[0:0]
p = AppendFrameButton4Action(p, test.Label)
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.Label)
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 = AppendFrameButton4Action(p, test.Label)
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.Label)
continue
}
}
}
}