main_test.go 556 B

12345678910111213141516171819202122
  1. package main
  2. import (
  3. "testing"
  4. )
  5. func TestScrubName(t *testing.T) {
  6. table := []struct{ descr, input, expected string }{
  7. {"Does the needful", "lr", "lr"},
  8. {"Trims leading underscores", "_lr", "lr"},
  9. {"Trims trailing underscores", "lr_", "lr"},
  10. {"Sends hyphens to underscores", "lr-1", "lr_1"},
  11. {"Sends spaces to underscores", "lr 1", "lr_1"},
  12. }
  13. for _, row := range table {
  14. t.Run(row.descr, func(t *testing.T) {
  15. if s := scrubName(row.input); s != row.expected {
  16. t.Errorf("expected '%s'; got '%s'\n", row.expected, s)
  17. }
  18. })
  19. }
  20. }