box_test.go 1.8 KB

1234567891011121314151617181920212223242526272829303132333435363738394041424344454647484950515253545556575859606162636465666768
  1. package door
  2. import (
  3. "reflect"
  4. "testing"
  5. )
  6. func TestBoxUnicode(t *testing.T) {
  7. // verify that the BOXES_CP437 matches BOXES_UNICODE
  8. for idx, bs := range BOXES_CP437 {
  9. fields := reflect.VisibleFields(reflect.TypeOf(bs))
  10. bs_value := reflect.ValueOf(bs)
  11. u_value := reflect.ValueOf(BOXES_UNICODE[idx])
  12. for _, sf := range fields {
  13. name := sf.Name
  14. // cp437 := reflect.ValueOf(bs).FieldByName(name).String()
  15. cp437 := bs_value.FieldByName(name).String()
  16. convert := CP437_to_Unicode(cp437)
  17. // unicode := reflect.ValueOf(BOXES_UNICODE[idx]).FieldByName(name).String()
  18. unicode := u_value.FieldByName(name).String()
  19. if convert != unicode {
  20. t.Errorf("BOXES %s [%d]: %#v != %#v\n", name, idx, convert, unicode)
  21. }
  22. // t.Fatalf("Name: %s, v: %s\n", name, cp437)
  23. }
  24. }
  25. }
  26. func TestBoxes(t *testing.T) {
  27. // Normally done in door.init.
  28. Unicode = true
  29. BOXES = BOXES_UNICODE
  30. box := Box{5, 0}
  31. got := box.Top()
  32. expected := "\u250c\u2500\u2500\u2500\u2500\u2500\u2510"
  33. if got != expected {
  34. t.Errorf("Boxes Top (0): Expected %#v, got %#v", got, expected)
  35. }
  36. got = box.Middle()
  37. expected = "\u251c\u2500\u2500\u2500\u2500\u2500\u2524"
  38. if got != expected {
  39. t.Errorf("Boxes Middle (0): Expected %#v, got %#v", got, expected)
  40. }
  41. got = box.Bottom()
  42. expected = "\u2514\u2500\u2500\u2500\u2500\u2500\u2518"
  43. if got != expected {
  44. t.Errorf("Boxes Bottom (0): Expected %#v, got %#v", got, expected)
  45. }
  46. got = box.Row("12345")
  47. expected = "\u250212345\u2502"
  48. if got != expected {
  49. t.Errorf("Boxes Row (0): Expected %#v, got %#v", got, expected)
  50. }
  51. alert := AlertBox("ALERT", 1)
  52. lines := []string{"\u2554\u2550\u2550\u2550\u2550\u2550\u2557", "\u2551ALERT\u2551", "\u255a\u2550\u2550\u2550\u2550\u2550\u255d"}
  53. for idx, line := range alert {
  54. if line != lines[idx] {
  55. t.Errorf("AlertBox (%d): Expected %#v, got %#v", idx, line, lines[idx])
  56. }
  57. }
  58. }