initial commits

master
Charles Iliya Krempeaux 2024-02-13 15:19:32 -08:00
parent a7d8ce73b9
commit b8a09bf0f7
8 changed files with 356 additions and 0 deletions

View File

@ -0,0 +1,21 @@
package frameproto
import (
"io"
)
// WriteFrameButton1Target will write the HTML <meta/> element for the Frame-Protocol's (i.e., Farcaster Frame's) "fc:frame:button:1:target" name-value pair.
//
// For example, this call:
//
// var target string = "https://example.com/thing/do-it"
//
// frameproto.WriteFrameButton1Target(writer, target)
//
// Would write this HTML <meta/> element:
//
// <meta property="fc:frame:button:1:target" content="https://example.com/thing/do-it" />
func WriteFrameButton1Target(writer io.Writer, url string) {
const property string = MetaPropertyFrameButton1Target
writeMetaPropertyContent(writer, property, url)
}

View File

@ -0,0 +1,68 @@
package frameproto
import (
"testing"
"strings"
)
func TestWriteFrameButton1Target(t *testing.T) {
tests := []struct{
Target string
Expected string
}{
{
Target: "",
Expected: `<meta property="fc:frame:button:1:target" content="" />`+"\n",
},
{
Target: "something",
Expected: `<meta property="fc:frame:button:1:target" content="something" />`+"\n",
},
{
Target: "Hello world! 🙂",
Expected: `<meta property="fc:frame:button:1:target" content="Hello world! 🙂" />`+"\n",
},
{
Target: "https://example.com/path/to/post/to.php",
Expected: `<meta property="fc:frame:button:1:target" content="https://example.com/path/to/post/to.php" />`+"\n",
},
{
Target: "x-proto:apple/banana/cherry",
Expected: `<meta property="fc:frame:button:1:target" content="x-proto:apple/banana/cherry" />`+"\n",
},
}
for testNumber, test := range tests {
var buffer strings.Builder
WriteFrameButton1Target(&buffer, test.Target)
expected := test.Expected
actual := buffer.String()
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("Target: %q", test.Target)
continue
}
}
}

View File

@ -0,0 +1,21 @@
package frameproto
import (
"io"
)
// WriteFrameButton2Target will write the HTML <meta/> element for the Frame-Protocol's (i.e., Farcaster Frame's) "fc:frame:button:2:target" name-value pair.
//
// For example, this call:
//
// var target string = "https://example.com/thing/do-it"
//
// frameproto.WriteFrameButton2Target(writer, target)
//
// Would write this HTML <meta/> element:
//
// <meta property="fc:frame:button:2:target" content="https://example.com/thing/do-it" />
func WriteFrameButton2Target(writer io.Writer, url string) {
const property string = MetaPropertyFrameButton2Target
writeMetaPropertyContent(writer, property, url)
}

View File

@ -0,0 +1,68 @@
package frameproto
import (
"testing"
"strings"
)
func TestWriteFrameButton2Target(t *testing.T) {
tests := []struct{
Target string
Expected string
}{
{
Target: "",
Expected: `<meta property="fc:frame:button:2:target" content="" />`+"\n",
},
{
Target: "something",
Expected: `<meta property="fc:frame:button:2:target" content="something" />`+"\n",
},
{
Target: "Hello world! 🙂",
Expected: `<meta property="fc:frame:button:2:target" content="Hello world! 🙂" />`+"\n",
},
{
Target: "https://example.com/path/to/post/to.php",
Expected: `<meta property="fc:frame:button:2:target" content="https://example.com/path/to/post/to.php" />`+"\n",
},
{
Target: "x-proto:apple/banana/cherry",
Expected: `<meta property="fc:frame:button:2:target" content="x-proto:apple/banana/cherry" />`+"\n",
},
}
for testNumber, test := range tests {
var buffer strings.Builder
WriteFrameButton2Target(&buffer, test.Target)
expected := test.Expected
actual := buffer.String()
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("Target: %q", test.Target)
continue
}
}
}

View File

@ -0,0 +1,21 @@
package frameproto
import (
"io"
)
// WriteFrameButton3Target will write the HTML <meta/> element for the Frame-Protocol's (i.e., Farcaster Frame's) "fc:frame:button:3:target" name-value pair.
//
// For example, this call:
//
// var target string = "https://example.com/thing/do-it"
//
// frameproto.WriteFrameButton3Target(writer, target)
//
// Would write this HTML <meta/> element:
//
// <meta property="fc:frame:button:3:target" content="https://example.com/thing/do-it" />
func WriteFrameButton3Target(writer io.Writer, url string) {
const property string = MetaPropertyFrameButton3Target
writeMetaPropertyContent(writer, property, url)
}

View File

@ -0,0 +1,68 @@
package frameproto
import (
"testing"
"strings"
)
func TestWriteFrameButton3Target(t *testing.T) {
tests := []struct{
Target string
Expected string
}{
{
Target: "",
Expected: `<meta property="fc:frame:button:3:target" content="" />`+"\n",
},
{
Target: "something",
Expected: `<meta property="fc:frame:button:3:target" content="something" />`+"\n",
},
{
Target: "Hello world! 🙂",
Expected: `<meta property="fc:frame:button:3:target" content="Hello world! 🙂" />`+"\n",
},
{
Target: "https://example.com/path/to/post/to.php",
Expected: `<meta property="fc:frame:button:3:target" content="https://example.com/path/to/post/to.php" />`+"\n",
},
{
Target: "x-proto:apple/banana/cherry",
Expected: `<meta property="fc:frame:button:3:target" content="x-proto:apple/banana/cherry" />`+"\n",
},
}
for testNumber, test := range tests {
var buffer strings.Builder
WriteFrameButton3Target(&buffer, test.Target)
expected := test.Expected
actual := buffer.String()
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("Target: %q", test.Target)
continue
}
}
}

View File

@ -0,0 +1,21 @@
package frameproto
import (
"io"
)
// WriteFrameButton4Target will write the HTML <meta/> element for the Frame-Protocol's (i.e., Farcaster Frame's) "fc:frame:button:4:target" name-value pair.
//
// For example, this call:
//
// var target string = "https://example.com/thing/do-it"
//
// frameproto.WriteFrameButton4Target(writer, target)
//
// Would write this HTML <meta/> element:
//
// <meta property="fc:frame:button:4:target" content="https://example.com/thing/do-it" />
func WriteFrameButton4Target(writer io.Writer, url string) {
const property string = MetaPropertyFrameButton4Target
writeMetaPropertyContent(writer, property, url)
}

View File

@ -0,0 +1,68 @@
package frameproto
import (
"testing"
"strings"
)
func TestWriteFrameButton4Target(t *testing.T) {
tests := []struct{
Target string
Expected string
}{
{
Target: "",
Expected: `<meta property="fc:frame:button:4:target" content="" />`+"\n",
},
{
Target: "something",
Expected: `<meta property="fc:frame:button:4:target" content="something" />`+"\n",
},
{
Target: "Hello world! 🙂",
Expected: `<meta property="fc:frame:button:4:target" content="Hello world! 🙂" />`+"\n",
},
{
Target: "https://example.com/path/to/post/to.php",
Expected: `<meta property="fc:frame:button:4:target" content="https://example.com/path/to/post/to.php" />`+"\n",
},
{
Target: "x-proto:apple/banana/cherry",
Expected: `<meta property="fc:frame:button:4:target" content="x-proto:apple/banana/cherry" />`+"\n",
},
}
for testNumber, test := range tests {
var buffer strings.Builder
WriteFrameButton4Target(&buffer, test.Target)
expected := test.Expected
actual := buffer.String()
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("Target: %q", test.Target)
continue
}
}
}