mirror of
https://github.com/tiennm99/tiennm99bot.git
synced 2026-10-14 02:16:31 +00:00
feat(commands): improve discovery and normalize parameters
This commit is contained in:
1 parent
3316eec74c
commit
f5ba9d4032
31 files changed
+479
-56
No files matched your search
@@ -0,0 +1,59 @@
|
||||
package modules
|
||||
|
||||
import "testing"
|
||||
|
||||
func TestCommandPresentation(t *testing.T) {
|
||||
tests := []struct {
|
||||
name string
|
||||
command Command
|
||||
invocation string
|
||||
example string
|
||||
menu string
|
||||
}{
|
||||
{
|
||||
name: "parameters and explicit example",
|
||||
command: Command{
|
||||
Name: "stock_buy",
|
||||
Parameters: "<quantity> <ticker>",
|
||||
Description: "Buy VN stock at market price",
|
||||
Example: "/stock_buy 100 TCB",
|
||||
},
|
||||
invocation: "/stock_buy <quantity> <ticker>",
|
||||
example: "/stock_buy 100 TCB",
|
||||
menu: "<quantity> <ticker>. Buy VN stock at market price. Example: /stock_buy 100 TCB",
|
||||
},
|
||||
{
|
||||
name: "no parameters uses command as example",
|
||||
command: Command{Name: "ping", Description: "Health check!"},
|
||||
invocation: "/ping",
|
||||
example: "/ping",
|
||||
menu: "Health check! Example: /ping",
|
||||
},
|
||||
{
|
||||
name: "variadic parameters keep ellipsis",
|
||||
command: Command{
|
||||
Name: "random",
|
||||
Parameters: "<options(comma-separated)>",
|
||||
Description: "Pick one option",
|
||||
Example: "/random pizza, sushi",
|
||||
},
|
||||
invocation: "/random <options(comma-separated)>",
|
||||
example: "/random pizza, sushi",
|
||||
menu: "<options(comma-separated)>. Pick one option. Example: /random pizza, sushi",
|
||||
},
|
||||
}
|
||||
|
||||
for _, tc := range tests {
|
||||
t.Run(tc.name, func(t *testing.T) {
|
||||
if got := tc.command.Invocation(); got != tc.invocation {
|
||||
t.Errorf("Invocation() = %q, want %q", got, tc.invocation)
|
||||
}
|
||||
if got := tc.command.ExampleInvocation(); got != tc.example {
|
||||
t.Errorf("ExampleInvocation() = %q, want %q", got, tc.example)
|
||||
}
|
||||
if got := tc.command.TelegramMenuDescription(); got != tc.menu {
|
||||
t.Errorf("TelegramMenuDescription() = %q, want %q", got, tc.menu)
|
||||
}
|
||||
})
|
||||
}
|
||||
}
|
||||
Reference in new issue
Block a user