stringutil_test.go 982 B

12345678910111213141516171819202122232425262728293031323334353637383940414243444546474849505152
  1. // Copyright (C) 2016 The Syncthing Authors.
  2. //
  3. // This Source Code Form is subject to the terms of the Mozilla Public
  4. // License, v. 2.0. If a copy of the MPL was not distributed with this file,
  5. // You can obtain one at https://mozilla.org/MPL/2.0/.
  6. package stringutil
  7. import (
  8. "testing"
  9. )
  10. func TestUniqueStrings(t *testing.T) {
  11. tests := []struct {
  12. input []string
  13. expected []string
  14. }{
  15. {
  16. []string{"a", "b"},
  17. []string{"a", "b"},
  18. },
  19. {
  20. []string{"a", "a"},
  21. []string{"a"},
  22. },
  23. {
  24. []string{"a", "a", "a", "a"},
  25. []string{"a"},
  26. },
  27. {
  28. nil,
  29. nil,
  30. },
  31. {
  32. []string{" a ", " a ", "b ", " b"},
  33. []string{"a", "b"},
  34. },
  35. }
  36. for _, test := range tests {
  37. result := UniqueTrimmedStrings(test.input)
  38. if len(result) != len(test.expected) {
  39. t.Errorf("%s != %s", result, test.expected)
  40. }
  41. for i := range result {
  42. if test.expected[i] != result[i] {
  43. t.Errorf("%s != %s", result, test.expected)
  44. }
  45. }
  46. }
  47. }