badger_test.go 900 B

1234567891011121314151617181920212223242526272829303132333435363738
  1. // Copyright (C) 2019 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 backend
  7. import "testing"
  8. func TestCommonPrefix(t *testing.T) {
  9. cases := []struct {
  10. a string
  11. b string
  12. common string
  13. }{
  14. {"", "", ""},
  15. {"a", "b", ""},
  16. {"aa", "ab", "a"},
  17. {"aa", "a", "a"},
  18. {"a", "aa", "a"},
  19. {"aabab", "ab", "a"},
  20. {"ab", "aabab", "a"},
  21. {"abac", "ababab", "aba"},
  22. {"ababab", "abac", "aba"},
  23. }
  24. for _, tc := range cases {
  25. pref := string(commonPrefix([]byte(tc.a), []byte(tc.b)))
  26. if pref != tc.common {
  27. t.Errorf("commonPrefix(%q, %q) => %q, expected %q", tc.a, tc.b, pref, tc.common)
  28. }
  29. }
  30. }
  31. func TestBadgerBackendBehavior(t *testing.T) {
  32. testBackendBehavior(t, OpenBadgerMemory)
  33. }