From a22d4dbcf3f776037f49ff848506be0509b25634 Mon Sep 17 00:00:00 2001 From: Charles Iliya Krempeaux Date: Thu, 15 Feb 2024 08:33:53 -0800 Subject: [PATCH] initial commits --- appendframebutton1target.go | 21 +++++++ appendframebutton1target_test.go | 96 ++++++++++++++++++++++++++++++++ appendframebutton2target.go | 21 +++++++ appendframebutton2target_test.go | 96 ++++++++++++++++++++++++++++++++ appendframebutton3target.go | 21 +++++++ appendframebutton3target_test.go | 96 ++++++++++++++++++++++++++++++++ appendframebutton4target.go | 21 +++++++ appendframebutton4target_test.go | 96 ++++++++++++++++++++++++++++++++ 8 files changed, 468 insertions(+) create mode 100644 appendframebutton1target.go create mode 100644 appendframebutton1target_test.go create mode 100644 appendframebutton2target.go create mode 100644 appendframebutton2target_test.go create mode 100644 appendframebutton3target.go create mode 100644 appendframebutton3target_test.go create mode 100644 appendframebutton4target.go create mode 100644 appendframebutton4target_test.go diff --git a/appendframebutton1target.go b/appendframebutton1target.go new file mode 100644 index 0000000..5725534 --- /dev/null +++ b/appendframebutton1target.go @@ -0,0 +1,21 @@ +package frameproto + +// AppendFrameButton1Target will append the HTML element for the Frame-Protocol's (i.e., Farcaster Frame's) "fc:frame:button:1:target" name-value pair. +// +// For example, this call: +// +// var p []byte +// +// // ... +// +// var target string = "https://example.com/thing/do-it" +// +// p = frameproto.AppendFrameButton1Target(p, target) +// +// Would append this HTML element: +// +// +func AppendFrameButton1Target(p []byte, target string) []byte { + const property string = MetaPropertyFrameButton1Target + return appendMetaPropertyContent(p, property, target) +} diff --git a/appendframebutton1target_test.go b/appendframebutton1target_test.go new file mode 100644 index 0000000..3f78369 --- /dev/null +++ b/appendframebutton1target_test.go @@ -0,0 +1,96 @@ +package frameproto + +import ( + "testing" +) + +func TestAppendFrameButton1Target(t *testing.T) { + + tests := []struct{ + Target string + Expected string + }{ + { + Target: "", + Expected: ``+"\n", + }, + + + + { + Target: "something", + Expected: ``+"\n", + }, + + + + { + Target: "Hello world! 🙂", + Expected: ``+"\n", + }, + + + + { + Target: "https://example.com/path/to/post/to.php", + Expected: ``+"\n", + }, + + + + { + Target: "x-proto:apple/banana/cherry", + Expected: ``+"\n", + }, + } + + for testNumber, test := range tests { + + { + var buffer [256]byte + var p []byte = buffer[0:0] + + p = AppendFrameButton1Target(p, test.Target) + + 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("Target: %q", test.Target) + continue + } + } + + { + const top string = "\n\n" + const bottom string = "\n\n\n\n" + + var buffer [256]byte + var p []byte = buffer[0:0] + + p = append(p, top...) + + p = AppendFrameButton1Target(p, test.Target) + + 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("Target: %q", test.Target) + continue + } + } + } +} diff --git a/appendframebutton2target.go b/appendframebutton2target.go new file mode 100644 index 0000000..643ef67 --- /dev/null +++ b/appendframebutton2target.go @@ -0,0 +1,21 @@ +package frameproto + +// AppendFrameButton2Target will append the HTML element for the Frame-Protocol's (i.e., Farcaster Frame's) "fc:frame:button:2:target" name-value pair. +// +// For example, this call: +// +// var p []byte +// +// // ... +// +// var target string = "https://example.com/thing/do-it" +// +// p = frameproto.AppendFrameButton2Target(p, target) +// +// Would append this HTML element: +// +// +func AppendFrameButton2Target(p []byte, target string) []byte { + const property string = MetaPropertyFrameButton2Target + return appendMetaPropertyContent(p, property, target) +} diff --git a/appendframebutton2target_test.go b/appendframebutton2target_test.go new file mode 100644 index 0000000..56b0ba3 --- /dev/null +++ b/appendframebutton2target_test.go @@ -0,0 +1,96 @@ +package frameproto + +import ( + "testing" +) + +func TestAppendFrameButton2Target(t *testing.T) { + + tests := []struct{ + Target string + Expected string + }{ + { + Target: "", + Expected: ``+"\n", + }, + + + + { + Target: "something", + Expected: ``+"\n", + }, + + + + { + Target: "Hello world! 🙂", + Expected: ``+"\n", + }, + + + + { + Target: "https://example.com/path/to/post/to.php", + Expected: ``+"\n", + }, + + + + { + Target: "x-proto:apple/banana/cherry", + Expected: ``+"\n", + }, + } + + for testNumber, test := range tests { + + { + var buffer [256]byte + var p []byte = buffer[0:0] + + p = AppendFrameButton2Target(p, test.Target) + + 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("Target: %q", test.Target) + continue + } + } + + { + const top string = "\n\n" + const bottom string = "\n\n\n\n" + + var buffer [256]byte + var p []byte = buffer[0:0] + + p = append(p, top...) + + p = AppendFrameButton2Target(p, test.Target) + + 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("Target: %q", test.Target) + continue + } + } + } +} diff --git a/appendframebutton3target.go b/appendframebutton3target.go new file mode 100644 index 0000000..d7ffa03 --- /dev/null +++ b/appendframebutton3target.go @@ -0,0 +1,21 @@ +package frameproto + +// AppendFrameButton3Target will append the HTML element for the Frame-Protocol's (i.e., Farcaster Frame's) "fc:frame:button:3:target" name-value pair. +// +// For example, this call: +// +// var p []byte +// +// // ... +// +// var target string = "https://example.com/thing/do-it" +// +// p = frameproto.AppendFrameButton3Target(p, target) +// +// Would append this HTML element: +// +// +func AppendFrameButton3Target(p []byte, target string) []byte { + const property string = MetaPropertyFrameButton3Target + return appendMetaPropertyContent(p, property, target) +} diff --git a/appendframebutton3target_test.go b/appendframebutton3target_test.go new file mode 100644 index 0000000..0c0d908 --- /dev/null +++ b/appendframebutton3target_test.go @@ -0,0 +1,96 @@ +package frameproto + +import ( + "testing" +) + +func TestAppendFrameButton3Target(t *testing.T) { + + tests := []struct{ + Target string + Expected string + }{ + { + Target: "", + Expected: ``+"\n", + }, + + + + { + Target: "something", + Expected: ``+"\n", + }, + + + + { + Target: "Hello world! 🙂", + Expected: ``+"\n", + }, + + + + { + Target: "https://example.com/path/to/post/to.php", + Expected: ``+"\n", + }, + + + + { + Target: "x-proto:apple/banana/cherry", + Expected: ``+"\n", + }, + } + + for testNumber, test := range tests { + + { + var buffer [256]byte + var p []byte = buffer[0:0] + + p = AppendFrameButton3Target(p, test.Target) + + 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("Target: %q", test.Target) + continue + } + } + + { + const top string = "\n\n" + const bottom string = "\n\n\n\n" + + var buffer [256]byte + var p []byte = buffer[0:0] + + p = append(p, top...) + + p = AppendFrameButton3Target(p, test.Target) + + 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("Target: %q", test.Target) + continue + } + } + } +} diff --git a/appendframebutton4target.go b/appendframebutton4target.go new file mode 100644 index 0000000..b3ad214 --- /dev/null +++ b/appendframebutton4target.go @@ -0,0 +1,21 @@ +package frameproto + +// AppendFrameButton4Target will append the HTML element for the Frame-Protocol's (i.e., Farcaster Frame's) "fc:frame:button:4:target" name-value pair. +// +// For example, this call: +// +// var p []byte +// +// // ... +// +// var target string = "https://example.com/thing/do-it" +// +// p = frameproto.AppendFrameButton4Target(p, target) +// +// Would append this HTML element: +// +// +func AppendFrameButton4Target(p []byte, target string) []byte { + const property string = MetaPropertyFrameButton4Target + return appendMetaPropertyContent(p, property, target) +} diff --git a/appendframebutton4target_test.go b/appendframebutton4target_test.go new file mode 100644 index 0000000..c02e12c --- /dev/null +++ b/appendframebutton4target_test.go @@ -0,0 +1,96 @@ +package frameproto + +import ( + "testing" +) + +func TestAppendFrameButton4Target(t *testing.T) { + + tests := []struct{ + Target string + Expected string + }{ + { + Target: "", + Expected: ``+"\n", + }, + + + + { + Target: "something", + Expected: ``+"\n", + }, + + + + { + Target: "Hello world! 🙂", + Expected: ``+"\n", + }, + + + + { + Target: "https://example.com/path/to/post/to.php", + Expected: ``+"\n", + }, + + + + { + Target: "x-proto:apple/banana/cherry", + Expected: ``+"\n", + }, + } + + for testNumber, test := range tests { + + { + var buffer [256]byte + var p []byte = buffer[0:0] + + p = AppendFrameButton4Target(p, test.Target) + + 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("Target: %q", test.Target) + continue + } + } + + { + const top string = "\n\n" + const bottom string = "\n\n\n\n" + + var buffer [256]byte + var p []byte = buffer[0:0] + + p = append(p, top...) + + p = AppendFrameButton4Target(p, test.Target) + + 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("Target: %q", test.Target) + continue + } + } + } +}