util_test.go 420 B

123456789101112131415161718192021222324252627
  1. package diffview
  2. import (
  3. "testing"
  4. )
  5. func TestPad(t *testing.T) {
  6. tests := []struct {
  7. input any
  8. width int
  9. expected string
  10. }{
  11. {7, 2, " 7"},
  12. {7, 3, " 7"},
  13. {"a", 2, " a"},
  14. {"a", 3, " a"},
  15. {"…", 2, " …"},
  16. {"…", 3, " …"},
  17. }
  18. for _, tt := range tests {
  19. result := pad(tt.input, tt.width)
  20. if result != tt.expected {
  21. t.Errorf("expected %q, got %q", tt.expected, result)
  22. }
  23. }
  24. }