github.com/bazelbuild/bazel-gazelle@v0.36.1-0.20240520142334-61b277ba6fed/tests/bzlmod/semver_test.bzl (about) 1 load("@bazel_skylib//lib:unittest.bzl", "asserts", "unittest") 2 load("//internal/bzlmod:semver.bzl", "semver") 3 4 _SORTED_TEST_VERSIONS = [ 5 "0.1-a", 6 "0.1", 7 "1.0.0-0.3.7", 8 "1.0.0-alpha", 9 "1.0.0-alpha+001", 10 "1.0.0-alpha.1", 11 "1.0.0-alpha.beta", 12 "1.0.0-beta+exp.sha.5114f85", 13 "1.0.0-beta", 14 "1.0.0-beta.2", 15 "1.0.0-beta.11", 16 "1.0.0-rc.1", 17 "1.0.0-x.7.z.92", 18 "1.0.0-x-y-z.--", 19 "1.0.0+21AF26D3----117B344092BD", 20 "1.0.0+20130313144700", 21 "1.0.0", 22 "2.0.0", 23 "2.1.0", 24 "2.1.1-0", 25 "2.1.1", 26 "2.1.1.0", 27 "2.1.1.1-a", 28 "2.1.1.1", 29 "2.1.1.a", 30 "2.1.2", 31 "3", 32 "a", 33 ] 34 35 _SCRAMBLED_TEST_VERSIONS = { 36 "a": True, 37 "3": True, 38 "2.1.2": False, 39 "2.1.1.a": True, 40 "2.1.1.1": True, 41 "2.1.1.1-a": True, 42 "2.1.1.0": True, 43 "2.1.1": False, 44 "2.1.1-0": False, 45 "2.1.0": False, 46 "2.0.0": False, 47 "1.0.0+21AF26D3----117B344092BD": False, 48 "1.0.0+20130313144700": False, 49 "1.0.0": False, 50 "1.0.0-x.7.z.92": False, 51 "1.0.0-x-y-z.--": False, 52 "1.0.0-rc.1": False, 53 "1.0.0-beta.11": False, 54 "1.0.0-beta.2": False, 55 "1.0.0-beta+exp.sha.5114f85": False, 56 "1.0.0-beta": False, 57 "1.0.0-alpha.beta": False, 58 "1.0.0-alpha.1": False, 59 "1.0.0-alpha": False, 60 "1.0.0-alpha+001": False, 61 "1.0.0-0.3.7": False, 62 "0.1-a": True, 63 "0.1": True, 64 } 65 66 def _semver_test_impl(ctx): 67 env = unittest.begin(ctx) 68 asserts.equals( 69 env, 70 _SORTED_TEST_VERSIONS, 71 sorted( 72 _SCRAMBLED_TEST_VERSIONS.keys(), 73 key = lambda x: semver.to_comparable(x, relaxed = _SCRAMBLED_TEST_VERSIONS[x]), 74 ), 75 ) 76 return unittest.end(env) 77 78 semver_test = unittest.make(_semver_test_impl) 79 80 def semver_test_suite(name): 81 unittest.suite( 82 name, 83 semver_test, 84 )