prefix_test.go 1.0 KB

12345678910111213141516171819202122232425262728293031323334353637
  1. // +build windows linux darwin openbsd freebsd netbsd
  2. package liner
  3. import "testing"
  4. type testItem struct {
  5. list []string
  6. prefix string
  7. }
  8. func TestPrefix(t *testing.T) {
  9. list := []testItem{
  10. {[]string{"food", "foot"}, "foo"},
  11. {[]string{"foo", "foot"}, "foo"},
  12. {[]string{"food", "foo"}, "foo"},
  13. {[]string{"food", "foe", "foot"}, "fo"},
  14. {[]string{"food", "foot", "barbeque"}, ""},
  15. {[]string{"cafeteria", "café"}, "caf"},
  16. {[]string{"cafe", "café"}, "caf"},
  17. {[]string{"cafè", "café"}, "caf"},
  18. {[]string{"cafés", "café"}, "café"},
  19. {[]string{"áéíóú", "áéíóú"}, "áéíóú"},
  20. {[]string{"éclairs", "éclairs"}, "éclairs"},
  21. {[]string{"éclairs are the best", "éclairs are great", "éclairs"}, "éclairs"},
  22. {[]string{"éclair", "éclairs"}, "éclair"},
  23. {[]string{"éclairs", "éclair"}, "éclair"},
  24. {[]string{"éclair", "élan"}, "é"},
  25. }
  26. for _, test := range list {
  27. lcp := longestCommonPrefix(test.list)
  28. if lcp != test.prefix {
  29. t.Errorf("%s != %s for %+v", lcp, test.prefix, test.list)
  30. }
  31. }
  32. }