main_test.go 766 B

123456789101112131415161718192021222324252627
  1. /*
  2. * This Source Code Form is subject to the terms of the Mozilla Public
  3. * License, v. 2.0. If a copy of the MPL was not distributed with this
  4. * file, You can obtain one at https://mozilla.org/MPL/2.0/.
  5. */
  6. package main
  7. import (
  8. "testing"
  9. )
  10. func TestScrubName(t *testing.T) {
  11. table := []struct{ descr, input, expected string }{
  12. {"Does the needful", "lr", "lr"},
  13. {"Trims leading underscores", "_lr", "lr"},
  14. {"Trims trailing underscores", "lr_", "lr"},
  15. {"Sends hyphens to underscores", "lr-1", "lr_1"},
  16. {"Sends spaces to underscores", "lr 1", "lr_1"},
  17. }
  18. for _, row := range table {
  19. t.Run(row.descr, func(t *testing.T) {
  20. if s := scrubName(row.input); s != row.expected {
  21. t.Errorf("expected '%s'; got '%s'\n", row.expected, s)
  22. }
  23. })
  24. }
  25. }