From c22e57f699042cafa5dc98e7953b3b4a1e864e0e Mon Sep 17 00:00:00 2001 From: Charles Iliya Krempeaux Date: Thu, 15 Feb 2024 07:18:41 -0800 Subject: [PATCH] initial commits --- appendframebutton1action.go | 40 ++++++++++++ appendframebutton1action_test.go | 101 +++++++++++++++++++++++++++++++ appendframebutton2action.go | 40 ++++++++++++ appendframebutton2action_test.go | 101 +++++++++++++++++++++++++++++++ appendframebutton3action.go | 40 ++++++++++++ appendframebutton3action_test.go | 101 +++++++++++++++++++++++++++++++ appendframebutton4action.go | 40 ++++++++++++ appendframebutton4action_test.go | 101 +++++++++++++++++++++++++++++++ 8 files changed, 564 insertions(+) create mode 100644 appendframebutton1action.go create mode 100644 appendframebutton1action_test.go create mode 100644 appendframebutton2action.go create mode 100644 appendframebutton2action_test.go create mode 100644 appendframebutton3action.go create mode 100644 appendframebutton3action_test.go create mode 100644 appendframebutton4action.go create mode 100644 appendframebutton4action_test.go diff --git a/appendframebutton1action.go b/appendframebutton1action.go new file mode 100644 index 0000000..7231f11 --- /dev/null +++ b/appendframebutton1action.go @@ -0,0 +1,40 @@ +package frameproto + +// AppendFrameButton1Action will append the HTML 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 element: +// +// +// +// 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) +} diff --git a/appendframebutton1action_test.go b/appendframebutton1action_test.go new file mode 100644 index 0000000..c423c4b --- /dev/null +++ b/appendframebutton1action_test.go @@ -0,0 +1,101 @@ +package frameproto + +import ( + "testing" +) + +func TestAppendFrameButton1Action(t *testing.T) { + + tests := []struct{ + Label string + Expected string + }{ + { + Label: "", + Expected: ``+"\n", + }, + + + + { + Label: "something", + Expected: ``+"\n", + }, + + + + { + Label: "Hello world! 🙂", + Expected: ``+"\n", + }, + + + + { + Label: "link", + Expected: ``+"\n", + }, + { + Label: "mint", + Expected: ``+"\n", + }, + { + Label: "post", + Expected: ``+"\n", + }, + { + Label: "post_redirect", + Expected: ``+"\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 = "\n\n" + const bottom string = "\n\n\n\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 + } + } + } +} diff --git a/appendframebutton2action.go b/appendframebutton2action.go new file mode 100644 index 0000000..9a2bcb9 --- /dev/null +++ b/appendframebutton2action.go @@ -0,0 +1,40 @@ +package frameproto + +// AppendFrameButton2Action will append the HTML 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 element: +// +// +// +// 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) +} diff --git a/appendframebutton2action_test.go b/appendframebutton2action_test.go new file mode 100644 index 0000000..7e7b26e --- /dev/null +++ b/appendframebutton2action_test.go @@ -0,0 +1,101 @@ +package frameproto + +import ( + "testing" +) + +func TestAppendFrameButton2Action(t *testing.T) { + + tests := []struct{ + Label string + Expected string + }{ + { + Label: "", + Expected: ``+"\n", + }, + + + + { + Label: "something", + Expected: ``+"\n", + }, + + + + { + Label: "Hello world! 🙂", + Expected: ``+"\n", + }, + + + + { + Label: "link", + Expected: ``+"\n", + }, + { + Label: "mint", + Expected: ``+"\n", + }, + { + Label: "post", + Expected: ``+"\n", + }, + { + Label: "post_redirect", + Expected: ``+"\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 = "\n\n" + const bottom string = "\n\n\n\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 + } + } + } +} diff --git a/appendframebutton3action.go b/appendframebutton3action.go new file mode 100644 index 0000000..d3fecc7 --- /dev/null +++ b/appendframebutton3action.go @@ -0,0 +1,40 @@ +package frameproto + +// AppendFrameButton3Action will append the HTML 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 element: +// +// +// +// 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) +} diff --git a/appendframebutton3action_test.go b/appendframebutton3action_test.go new file mode 100644 index 0000000..b8f963e --- /dev/null +++ b/appendframebutton3action_test.go @@ -0,0 +1,101 @@ +package frameproto + +import ( + "testing" +) + +func TestAppendFrameButton3Action(t *testing.T) { + + tests := []struct{ + Label string + Expected string + }{ + { + Label: "", + Expected: ``+"\n", + }, + + + + { + Label: "something", + Expected: ``+"\n", + }, + + + + { + Label: "Hello world! 🙂", + Expected: ``+"\n", + }, + + + + { + Label: "link", + Expected: ``+"\n", + }, + { + Label: "mint", + Expected: ``+"\n", + }, + { + Label: "post", + Expected: ``+"\n", + }, + { + Label: "post_redirect", + Expected: ``+"\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 = "\n\n" + const bottom string = "\n\n\n\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 + } + } + } +} diff --git a/appendframebutton4action.go b/appendframebutton4action.go new file mode 100644 index 0000000..7402e1e --- /dev/null +++ b/appendframebutton4action.go @@ -0,0 +1,40 @@ +package frameproto + +// AppendFrameButton4Action will append the HTML 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 element: +// +// +// +// 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) +} diff --git a/appendframebutton4action_test.go b/appendframebutton4action_test.go new file mode 100644 index 0000000..282a9df --- /dev/null +++ b/appendframebutton4action_test.go @@ -0,0 +1,101 @@ +package frameproto + +import ( + "testing" +) + +func TestAppendFrameButton4Action(t *testing.T) { + + tests := []struct{ + Label string + Expected string + }{ + { + Label: "", + Expected: ``+"\n", + }, + + + + { + Label: "something", + Expected: ``+"\n", + }, + + + + { + Label: "Hello world! 🙂", + Expected: ``+"\n", + }, + + + + { + Label: "link", + Expected: ``+"\n", + }, + { + Label: "mint", + Expected: ``+"\n", + }, + { + Label: "post", + Expected: ``+"\n", + }, + { + Label: "post_redirect", + Expected: ``+"\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 = "\n\n" + const bottom string = "\n\n\n\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 + } + } + } +}