versioner_test.go 1.6 KB

1234567891011121314151617181920212223242526272829303132333435363738394041424344454647484950515253
  1. // Copyright (C) 2014 The Syncthing Authors.
  2. //
  3. // This program is free software: you can redistribute it and/or modify it
  4. // under the terms of the GNU General Public License as published by the Free
  5. // Software Foundation, either version 3 of the License, or (at your option)
  6. // any later version.
  7. //
  8. // This program is distributed in the hope that it will be useful, but WITHOUT
  9. // ANY WARRANTY; without even the implied warranty of MERCHANTABILITY or
  10. // FITNESS FOR A PARTICULAR PURPOSE. See the GNU General Public License for
  11. // more details.
  12. //
  13. // You should have received a copy of the GNU General Public License along
  14. // with this program. If not, see <http://www.gnu.org/licenses/>.
  15. package versioner
  16. import (
  17. "path/filepath"
  18. "testing"
  19. )
  20. func TestTaggedFilename(t *testing.T) {
  21. cases := [][3]string{
  22. {filepath.Join("foo", "bar.baz"), "tag", filepath.Join("foo", "bar~tag.baz")},
  23. {"bar.baz", "tag", "bar~tag.baz"},
  24. {"bar", "tag", "bar~tag"},
  25. {"~$ufheft2.docx", "20140612-200554", "~$ufheft2~20140612-200554.docx"},
  26. {"alle~4.mgz", "20141106-094415", "alle~4~20141106-094415.mgz"},
  27. // Parsing test only
  28. {"", "tag-only", "foo/bar.baz~tag-only"},
  29. {"", "tag-only", "bar.baz~tag-only"},
  30. {"", "20140612-200554", "~$ufheft2.docx~20140612-200554"},
  31. {"", "20141106-094415", "alle~4.mgz~20141106-094415"},
  32. }
  33. for _, tc := range cases {
  34. if tc[0] != "" {
  35. // Test tagger
  36. tf := taggedFilename(tc[0], tc[1])
  37. if tf != tc[2] {
  38. t.Errorf("%s != %s", tf, tc[2])
  39. }
  40. }
  41. // Test parser
  42. tag := filenameTag(tc[2])
  43. if tag != tc[1] {
  44. t.Errorf("%s != %s", tag, tc[1])
  45. }
  46. }
  47. }