db_service_test.go 837 B

12345678910111213141516171819202122232425262728293031323334353637
  1. // Copyright (C) 2025 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 sqlite
  7. import (
  8. "bytes"
  9. "fmt"
  10. "strings"
  11. "testing"
  12. )
  13. func TestBlobRange(t *testing.T) {
  14. exp := `
  15. hash < x'249249'
  16. hash >= x'249249' AND hash < x'492492'
  17. hash >= x'492492' AND hash < x'6db6db'
  18. hash >= x'6db6db' AND hash < x'924924'
  19. hash >= x'924924' AND hash < x'b6db6d'
  20. hash >= x'b6db6d' AND hash < x'db6db6'
  21. hash >= x'db6db6'
  22. `
  23. ranges := blobRanges(7)
  24. buf := new(bytes.Buffer)
  25. for _, r := range ranges {
  26. fmt.Fprintln(buf, r.SQL("hash"))
  27. }
  28. if strings.TrimSpace(buf.String()) != strings.TrimSpace(exp) {
  29. t.Log(buf.String())
  30. t.Error("unexpected output")
  31. }
  32. }