initial commits

master
Charles Iliya Krempeaux 2024-02-15 06:38:13 -08:00
parent 26047f706d
commit ac6d9d2f99
8 changed files with 468 additions and 0 deletions

View File

@ -0,0 +1,21 @@
package frameproto
// AppendFrameButton1 will append the HTML <meta/> element for the Frame-Protocol's (i.e., Farcaster Frame's) "fc:frame:button:1" name-value pair.
//
// For example, this call:
//
// var p []byte
//
// // ...
//
// var label string = "go forward"
//
// p = frameproto.AppendFrameButton1(p, label)
//
// Would append this HTML <meta/> element:
//
// <meta property="fc:frame:button:1" content="go forward" />
func AppendFrameButton1(p []byte, label string) []byte {
const property string = MetaPropertyFrameButton1
return appendMetaPropertyContent(p, property, label)
}

View File

@ -0,0 +1,96 @@
package frameproto
import (
"testing"
)
func TestAppendFrameButton1(t *testing.T) {
tests := []struct{
Label string
Expected string
}{
{
Label: "",
Expected: `<meta property="fc:frame:button:1" content="" />`+"\n",
},
{
Label: "something",
Expected: `<meta property="fc:frame:button:1" content="something" />`+"\n",
},
{
Label: "Hello world! 🙂",
Expected: `<meta property="fc:frame:button:1" content="Hello world! 🙂" />`+"\n",
},
{
Label: "go forward",
Expected: `<meta property="fc:frame:button:1" content="go forward" />`+"\n",
},
{
Label: "I like to eat, eat, eat, apples and bananas",
Expected: `<meta property="fc:frame:button:1" content="I like to eat, eat, eat, apples and bananas" />`+"\n",
},
}
for testNumber, test := range tests {
{
var buffer [256]byte
var p []byte = buffer[0:0]
p = AppendFrameButton1(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 = AppendFrameButton1(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,21 @@
package frameproto
// AppendFrameButton2 will append the HTML <meta/> element for the Frame-Protocol's (i.e., Farcaster Frame's) "fc:frame:button:2" name-value pair.
//
// For example, this call:
//
// var p []byte
//
// // ...
//
// var label string = "go forward"
//
// p = frameproto.AppendFrameButton2(p, label)
//
// Would append this HTML <meta/> element:
//
// <meta property="fc:frame:button:2" content="go forward" />
func AppendFrameButton2(p []byte, label string) []byte {
const property string = MetaPropertyFrameButton2
return appendMetaPropertyContent(p, property, label)
}

View File

@ -0,0 +1,96 @@
package frameproto
import (
"testing"
)
func TestAppendFrameButton2(t *testing.T) {
tests := []struct{
Label string
Expected string
}{
{
Label: "",
Expected: `<meta property="fc:frame:button:2" content="" />`+"\n",
},
{
Label: "something",
Expected: `<meta property="fc:frame:button:2" content="something" />`+"\n",
},
{
Label: "Hello world! 🙂",
Expected: `<meta property="fc:frame:button:2" content="Hello world! 🙂" />`+"\n",
},
{
Label: "go forward",
Expected: `<meta property="fc:frame:button:2" content="go forward" />`+"\n",
},
{
Label: "I like to eat, eat, eat, apples and bananas",
Expected: `<meta property="fc:frame:button:2" content="I like to eat, eat, eat, apples and bananas" />`+"\n",
},
}
for testNumber, test := range tests {
{
var buffer [256]byte
var p []byte = buffer[0:0]
p = AppendFrameButton2(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 = AppendFrameButton2(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,21 @@
package frameproto
// AppendFrameButton3 will append the HTML <meta/> element for the Frame-Protocol's (i.e., Farcaster Frame's) "fc:frame:button:3" name-value pair.
//
// For example, this call:
//
// var p []byte
//
// // ...
//
// var label string = "go forward"
//
// p = frameproto.AppendFrameButton3(p, label)
//
// Would append this HTML <meta/> element:
//
// <meta property="fc:frame:button:3" content="go forward" />
func AppendFrameButton3(p []byte, label string) []byte {
const property string = MetaPropertyFrameButton3
return appendMetaPropertyContent(p, property, label)
}

View File

@ -0,0 +1,96 @@
package frameproto
import (
"testing"
)
func TestAppendFrameButton3(t *testing.T) {
tests := []struct{
Label string
Expected string
}{
{
Label: "",
Expected: `<meta property="fc:frame:button:3" content="" />`+"\n",
},
{
Label: "something",
Expected: `<meta property="fc:frame:button:3" content="something" />`+"\n",
},
{
Label: "Hello world! 🙂",
Expected: `<meta property="fc:frame:button:3" content="Hello world! 🙂" />`+"\n",
},
{
Label: "go forward",
Expected: `<meta property="fc:frame:button:3" content="go forward" />`+"\n",
},
{
Label: "I like to eat, eat, eat, apples and bananas",
Expected: `<meta property="fc:frame:button:3" content="I like to eat, eat, eat, apples and bananas" />`+"\n",
},
}
for testNumber, test := range tests {
{
var buffer [256]byte
var p []byte = buffer[0:0]
p = AppendFrameButton3(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 = AppendFrameButton3(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,21 @@
package frameproto
// AppendFrameButton4 will append the HTML <meta/> element for the Frame-Protocol's (i.e., Farcaster Frame's) "fc:frame:button:4" name-value pair.
//
// For example, this call:
//
// var p []byte
//
// // ...
//
// var label string = "go forward"
//
// p = frameproto.AppendFrameButton4(p, label)
//
// Would append this HTML <meta/> element:
//
// <meta property="fc:frame:button:4" content="go forward" />
func AppendFrameButton4(p []byte, label string) []byte {
const property string = MetaPropertyFrameButton4
return appendMetaPropertyContent(p, property, label)
}

View File

@ -0,0 +1,96 @@
package frameproto
import (
"testing"
)
func TestAppendFrameButton4(t *testing.T) {
tests := []struct{
Label string
Expected string
}{
{
Label: "",
Expected: `<meta property="fc:frame:button:4" content="" />`+"\n",
},
{
Label: "something",
Expected: `<meta property="fc:frame:button:4" content="something" />`+"\n",
},
{
Label: "Hello world! 🙂",
Expected: `<meta property="fc:frame:button:4" content="Hello world! 🙂" />`+"\n",
},
{
Label: "go forward",
Expected: `<meta property="fc:frame:button:4" content="go forward" />`+"\n",
},
{
Label: "I like to eat, eat, eat, apples and bananas",
Expected: `<meta property="fc:frame:button:4" content="I like to eat, eat, eat, apples and bananas" />`+"\n",
},
}
for testNumber, test := range tests {
{
var buffer [256]byte
var p []byte = buffer[0:0]
p = AppendFrameButton4(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 = AppendFrameButton4(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
}
}
}
}