mirror of
https://github.com/tiennm99/tiennm99bot.git
synced 2026-10-18 00:15:36 +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
@@ -51,7 +51,8 @@ func TestRenderHelp_GroupsByModuleAndSkipsNonPublic(t *testing.T) {
|
||||
for _, want := range []string{
|
||||
"<b>alpha</b>",
|
||||
"<b>beta</b>",
|
||||
"/a_pub — alpha public",
|
||||
"/a_pub. alpha public.",
|
||||
"<pre>/a_pub</pre>",
|
||||
// HTML in user descriptions must be escaped.
|
||||
"beta <i>desc</i>",
|
||||
// Locks html.EscapeString contract: & → &, " → ".
|
||||
@@ -71,6 +72,34 @@ func TestRenderHelp_GroupsByModuleAndSkipsNonPublic(t *testing.T) {
|
||||
}
|
||||
}
|
||||
|
||||
func TestRenderHelp_ShowsParametersAndCopyableExample(t *testing.T) {
|
||||
command := modules.Command{
|
||||
Name: "buy",
|
||||
Visibility: modules.VisibilityPublic,
|
||||
Description: "Buy & hold",
|
||||
Parameters: "<quantity> <ticker>",
|
||||
Example: "/buy 100 TCB",
|
||||
Handler: helpTestNoop,
|
||||
}
|
||||
reg, err := modules.Build(
|
||||
[]string{"stock"},
|
||||
map[string]modules.Factory{"stock": fakeFactory("stock", []modules.Command{command})},
|
||||
storage.NewMemoryProvider(),
|
||||
modules.BuildOptions{},
|
||||
)
|
||||
if err != nil {
|
||||
t.Fatalf("Build: %v", err)
|
||||
}
|
||||
|
||||
out := util.RenderHelp(reg)
|
||||
if !strings.Contains(out, "/buy <quantity> <ticker>. Buy & hold.") {
|
||||
t.Fatalf("help missing formatted invocation and summary:\n%s", out)
|
||||
}
|
||||
if !strings.Contains(out, "<pre>/buy 100 TCB</pre>") {
|
||||
t.Fatalf("help missing copyable example:\n%s", out)
|
||||
}
|
||||
}
|
||||
|
||||
func TestRenderHelp_ModuleOrderMatchesEnvOrder(t *testing.T) {
|
||||
cmd := func(name string) modules.Command {
|
||||
return modules.Command{Name: name, Visibility: modules.VisibilityPublic, Description: name, Handler: helpTestNoop}
|
||||
|
||||
Reference in new issue
Block a user