zori_test.go 1.2 KB

12345678910111213141516171819202122232425262728293031323334353637383940414243444546474849505152535455565758596061
  1. // zori_test.go
  2. package zori
  3. import (
  4. // "strings"
  5. "testing"
  6. "gitlab.com/beoran/ebsgo/zori/event"
  7. . "gitlab.com/beoran/ebsgo/zori/types"
  8. _ "gitlab.com/beoran/ebsgo/zori/backend"
  9. // _ "gitlab.com/beoran/woe/monolog"
  10. // "gitlab.com/beoran/woe/tree"
  11. )
  12. func Assert(test *testing.T, ok bool, text string) bool {
  13. if !ok {
  14. test.Error(text)
  15. }
  16. return ok
  17. }
  18. type TestKeyboardEvent struct {
  19. event.Basic
  20. stamp float64
  21. unichar rune
  22. }
  23. func (ke TestKeyboardEvent) IsKeyChar() {
  24. }
  25. func (ke TestKeyboardEvent) KeyCode() int {
  26. return int(ke.unichar)
  27. }
  28. func (ke TestKeyboardEvent) Unichar() rune {
  29. return ke.unichar
  30. }
  31. func (ke TestKeyboardEvent) Modifiers() int {
  32. return 0
  33. }
  34. func (ke TestKeyboardEvent) Repeat() bool {
  35. return false
  36. }
  37. func (ke TestKeyboardEvent) Display() Display {
  38. return nil
  39. }
  40. func TestDispatch(test *testing.T) {
  41. bw := &BasicWidget{}
  42. cw := &ConsoleWidget{}
  43. ev := &TestKeyboardEvent{}
  44. Assert(test, bool(event.Dispatch(ev, bw)), "Dispatch bw failed")
  45. Assert(test, bool(event.Dispatch(ev, cw)), "Dispatch cw failed")
  46. Assert(test, bool(bw.Dispatch(ev)), "Dispatch bw failed")
  47. Assert(test, bool(cw.Dispatch(ev)), "Dispatch cw failed")
  48. }