build_test.go 1.4 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657
  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 build
  7. import (
  8. "testing"
  9. )
  10. func TestAllowedVersions(t *testing.T) {
  11. testcases := []struct {
  12. ver string
  13. allowed bool
  14. }{
  15. {"v0.13.0", true},
  16. {"v0.12.11+22-gabcdef0", true},
  17. {"v0.13.0-beta0", true},
  18. {"v0.13.0-beta47", true},
  19. {"v0.13.0-beta47+1-gabcdef0", true},
  20. {"v0.13.0-beta.0", true},
  21. {"v0.13.0-beta.47", true},
  22. {"v0.13.0-beta.0+1-gabcdef0", true},
  23. {"v0.13.0-beta.47+1-gabcdef0", true},
  24. {"v0.13.0-some-weird-but-allowed-tag", true},
  25. {"v0.13.0-allowed.to.do.this", true},
  26. {"v0.13.0+not.allowed.to.do.this", false},
  27. }
  28. for i, c := range testcases {
  29. if allowed := allowedVersionExp.MatchString(c.ver); allowed != c.allowed {
  30. t.Errorf("%d: incorrect result %v != %v for %q", i, allowed, c.allowed, c.ver)
  31. }
  32. }
  33. }
  34. func TestFilterString(t *testing.T) {
  35. cases := []struct {
  36. input string
  37. filter string
  38. output string
  39. }{
  40. {"abcba", "abc", "abcba"},
  41. {"abcba", "ab", "abba"},
  42. {"abcba", "c", "c"},
  43. {"abcba", "!", ""},
  44. {"Foo (v1.5)", versionExtraAllowedChars, "Foo v1.5"},
  45. }
  46. for i, c := range cases {
  47. if out := filterString(c.input, c.filter); out != c.output {
  48. t.Errorf("%d: %q != %q", i, out, c.output)
  49. }
  50. }
  51. }