Golang framework for developing Telegram Bots
You can not select more than 25 topics Topics must start with a letter or number, can include dashes ('-') and can be up to 35 characters long.

commands_test.go 1.3KB

1234567891011121314151617181920212223242526272829303132333435363738394041424344454647484950515253545556
  1. package finch
  2. import (
  3. "testing"
  4. )
  5. func TestSimpleCommand(t *testing.T) {
  6. goodMessage := "/start"
  7. goodMessage2 := "/start param1 param2"
  8. goodMessage3 := "/start@FinchExampleBot"
  9. goodMessage4 := "/start@FinchExampleBot param1 param2"
  10. badMessage := "/stop"
  11. if !SimpleCommand("start", goodMessage) {
  12. t.Error("goodMessage did not return true")
  13. }
  14. if !SimpleCommand("start", goodMessage2) {
  15. t.Error("goodMessage2 did not return true")
  16. }
  17. if !SimpleCommand("start", goodMessage3) {
  18. t.Error("goodMessage3 did not return true")
  19. }
  20. if !SimpleCommand("start", goodMessage4) {
  21. t.Error("goodMessage4 did not return true")
  22. }
  23. if SimpleCommand("start", badMessage) {
  24. t.Error("badMessage did not return false")
  25. }
  26. }
  27. func TestSimpleArgCommand(t *testing.T) {
  28. goodMessage := "/start arg1 arg2"
  29. goodMessage2 := "/start@FinchExampleBot arg1 arg2"
  30. badMessage := "/start arg1"
  31. badMessage2 := "/start arg1 arg2 arg3"
  32. if !SimpleArgCommand("start", 2, goodMessage) {
  33. t.Error("goodMessage did not return true")
  34. }
  35. if !SimpleArgCommand("start", 2, goodMessage2) {
  36. t.Error("goodMessage2 did not return true")
  37. }
  38. if SimpleArgCommand("start", 2, badMessage) {
  39. t.Error("badMessage did not return false")
  40. }
  41. if SimpleArgCommand("start", 2, badMessage2) {
  42. t.Error("badMessage2 did not return false")
  43. }
  44. }