Пример #1
0
        public void Compare_And_CompareTo()
        {
            for (var i = 0; i < Versions.Length - 1; i++)
            {
                var a = Versions[i];

                Assert.Equal(a, a);
                if (a != null)
                {
                    Assert.Equal(a, SemVer.Parse(a.ToString()));
                }

                Assert.False(a < null);
                Assert.False(a > null);
                Assert.False(a <= null);
                Assert.False(a >= null);

                for (var j = i + 1; j < Versions.Length; j++)
                {
                    var b = Versions[j];

                    Assert.NotEqual(a, b);

                    Assert.True(SemVer.Compare(a, b) < 0, $"{ a } is not smaller than { b }");
                    if (a != null)
                    {
                        Assert.True(a.CompareTo(b) < 0);
                    }
                }
            }

            Assert.Equal(Versions, Versions.OrderBy(x => x, Comparer <SemVer> .Default));
        }
Пример #2
0
        public IModel Load(PropertyBag modelData)
        {
            try
            {
                var model = new Model(
                    modelData["name"] as string,
                    SemVer.Parse(modelData["version"] as string),
                    new ModelFactories(_valueTypeFactory, _validatorFactory, _entityFactory))
                {
                    PropertyBag = modelData
                };
                model.EntitiesBySingleName = (modelData["entities"] as PropertyBag[])
                                             .Safe()
                                             .ToImmutableDictionary(x => x["singlename"] as string, x => MapEntityDefinition(model, x),
                                                                    StringComparer.OrdinalIgnoreCase);
                model.EntitiesByPluralName = model.EntitiesBySingleName.Values.ToImmutableDictionary(x => x.PluralName);

                model.ModelLoaded();

                return(model);
            }
            catch (Exception ex) when(!(ex is ModelLoadingException))
            {
                throw new ModelLoadingException($"There has been an error while loading the model {modelData["name"]}", ex);
            }
        }
Пример #3
0
        public void CanParseSemverString(string input, int major, int minor, int patch, string suffix)
        {
            var result = SemVer.Parse(input);

            Assert.Equal(result.Major, major);
            Assert.Equal(result.Minor, minor);
            Assert.Equal(result.Patch, patch);
            Assert.Equal(result.Suffix, suffix);
        }
Пример #4
0
 private void Awake()
 {
     if (version != null &&
         (version.autoBuild != SemVerAutoBuild.Type.Manual || version != new SemVer()))
     {
         return;
     }
     version = SemVer.Parse(Application.version);
 }
Пример #5
0
        public void Parse_Invalid_With_Best_Guess(string str, string expectedGuess,
                                                  int expectedIndex, string expectedError)
        {
            Assert.Throws <FormatException>(() => SemVer.Parse(str));
            var success = SemVer.TryParse(str, out var version, out var error);

            Assert.False(success);
            Assert.Equal(expectedGuess, version.ToString());
            Assert.Equal($"Error parsing version string '{ str }' at index { expectedIndex }: { expectedError }", error);
        }
Пример #6
0
        public static void Main()
        {
            // This project exists to validate the c# that psake uses for version management
            SemVer semanticVersion = null;

            semanticVersion = SemVer.Parse("1.2.3");
            semanticVersion = SemVer.Parse("1.2.3-pre");
            semanticVersion = SemVer.Parse("1.2.3+meta");
            semanticVersion = SemVer.Parse("1.2.3-pre+meta");
        }
Пример #7
0
        public void ParseVersionWorks()
        {
            SemVer.Parse("1.0.0").Should().Be(new SemVer(1, 0, 0));
            SemVer.Parse("1.0.0-alpha").Should().Be(new SemVer(1, 0, 0, "alpha"));
            SemVer.Parse("1.0.0-alpha+info").Should().Be(new SemVer(1, 0, 0, "alpha", "info"));
            SemVer.Parse("1.0.0-alpha.1").Should().Be(new SemVer(1, 0, 0, "alpha.1", "info"));
            SemVer.Parse("1.0.0-alpha.2").Should().Be(new SemVer(1, 0, 0, "alpha.2", "info"));
            SemVer.Parse("1.0.0-alpha.1.2").Should().Be(new SemVer(1, 0, 0, "alpha.1.2", "info"));
            SemVer.Parse("1.2.3-alpha.4.5+6").Should().Be(new SemVer(1, 2, 3, "alpha.4.5", "6"));
            SemVer.Parse("1.2.3-Beta.4.5+6").Should().Be(new SemVer(1, 2, 3, "Beta.4.5", "6"));

            SemVer.Parse("1.2.3---alpha-abc.4.5+6").Should().Be(new SemVer(1, 2, 3, "--alpha-abc.4.5", "6"));
        }
        public void NextVersion(string versionStr, VersionPart part, string expectedNextStr)
        {
            var version      = SemVer.Parse(versionStr);
            var expectedNext = SemVer.Parse(expectedNextStr);
            var opts         = new VersionCalculationOptions()
            {
                AutoIncrement = part,
            };

            var actualNext = VersionCalculator.NextVersion(version, opts);

            actualNext.Should().Be(expectedNext);
        }
        internal static bool ValidateVersion(string version)
        {
            SemVer currentVersion        = SemVer.Parse(version);
            SemVerValidationResult valid = currentVersion.Validate();

            if (valid.IsValid)
            {
                return(valid.Corrected.ToString() == version);
            }
            else
            {
                return(false);
            }
        }
        public void CheckVersionBumps(string?versionStr, string?minVer, int height, string resultStr)
        {
            var options = new VersionCalculationOptions()
            {
                MinimumVersion = SemVer.Parse(minVer ?? "0.1.0"),
            };

            var version = versionStr is null ? (SemVer?)null: SemVer.Parse(versionStr);
            var result  = SemVer.Parse(resultStr);

            var gotVersion = VersionCalculator.FromTagInfomation(version, options, height);

            gotVersion.Should().Be(result);
            gotVersion.ToString().Should().Be(resultStr);
        }
Пример #11
0
        public override void OnGUI(Rect position, SerializedProperty property, GUIContent label)
        {
            if (property.type == "string")
            {
                Target = SemVer.Parse(property.stringValue);
                var corrected = DrawSemVer(position, property, label);
                property.stringValue = corrected.ToString();
                return;
            }

            Debug.LogWarning($"{property.type} is not supported by {this}");
            EditorGUI.BeginProperty(position, label, property);
            EditorGUI.PropertyField(position, property);
            EditorGUI.EndProperty();
        }
        private void AddRegistryPackage(UnityEditor.PackageManager.PackageInfo info)
        {
            try
            {
                SemVer latestVersion  = SemVer.Parse(GetLatestVersion(info));
                SemVer currentVersion = SemVer.Parse(info.version);

                if (currentVersion < latestVersion)
                {
                    UpgradeablePackages.Add(info);
                }
            }
            catch (System.Exception)
            {
                Debug.LogError("Invalid version for package " + info.displayName + ". Current: " + info.version + ", Latest: " + GetLatestVersion(info));
            }
        }
Пример #13
0
        private static void UpdateManifest(UnityEditor.PackageManager.PackageInfo package)
        {
            JObject manifestJSON = JObject.Parse(AssetDatabaseUtilities.ReadTextFile(Paths.PackagesFolder, Paths.ProjectManifest));

            var dependencies = (JObject)manifestJSON["dependencies"];

            bool   changed = false;
            string changes = "";

            if (dependencies.ContainsKey(package.name))
            {
                string version = dependencies[package.name].ToObject <string>();

                if (SemVer.Parse(version).ToString() == version)
                {
                    if (package.version != version)
                    {
                        changes += "\t" + package.name + "@" + version + "=>" + package.version;

                        dependencies[package.name] = package.version;
                        changed = true;
                    }
                }
            }
            else
            {
                changes += "+\t" + package.name + "@" + package.version;

                JProperty property = new JProperty(package.name, package.version);
                dependencies.Add(property);

                changed = true;
            }
            if (changed)
            {
                AssetDatabaseUtilities.CreateTextFile(manifestJSON.ToString(), Paths.PackagesFolder, Paths.ProjectManifest);
                Debug.Log("Updated project dependencies" + Environment.NewLine + changes);
            }
        }
            public PackageUpgradeState(UnityEditor.PackageManager.PackageInfo info)
            {
                this.info         = info;
                previewAvailable  = false;
                stableAvailable   = false;
                verifiedAvailable = false;
                hasVerified       = false;
                stableVersion     = SemVer.Parse(info.version);
                previewVersion    = SemVer.Parse(info.version);



                try
                {
                    current = SemVer.Parse(info.version);
                }
                catch
                {
                    Debug.LogError("Cannot parse version for package " + info.displayName + ": " + info.version);
                }

                if (info.source == PackageSource.Git)
                {
                    previewAvailable = true;
                    preview          = info.packageId;

                    stableAvailable = true;
                    stable          = info.packageId;
                }
                else if (info.source == PackageSource.Registry)
                {
                    string[] compatible = info.versions.compatible;

                    foreach (string ver in compatible)
                    {
                        try
                        {
                            SemVer version = SemVer.Parse(ver);

                            if (string.IsNullOrWhiteSpace(version.preRelease))
                            {
                                if (version > stableVersion)
                                {
                                    stableVersion   = version;
                                    stableAvailable = true;
                                    stable          = info.name + "@" + ver;
                                }
                            }
                            else
                            {
                                // This is a pre-release
                                if (version > previewVersion)
                                {
                                    previewVersion   = version;
                                    previewAvailable = true;
                                    preview          = info.name + "@" + ver;
                                }
                            }
                        }
                        catch
                        {
                            Debug.LogError("Invalid version for package " + info.displayName + ": " + ver);
                        }
                    }

                    hasVerified = !String.IsNullOrWhiteSpace(info.versions.verified);
                    if (hasVerified)
                    {
                        try
                        {
                            verifiedVersion = SemVer.Parse(info.versions.verified);
                            if (verifiedVersion > current)
                            {
                                verifiedAvailable = verifiedVersion > current;
                                verified          = info.name + "@" + info.versions.verified;
                            }
                        }
                        catch
                        {
                            Debug.LogError("Cannot parse version for package " + info.displayName + ": " + info.versions.verified);
                        }
                    }
                }
            }
Пример #15
0
 public void Parse(string value, SemVer expected)
 {
     SemVer.Parse(value).ShouldBeEquivalentTo(expected);
 }
Пример #16
0
        public void ToStringOutputsTheSemverString()
        {
            var semver = SemVer.Parse("1.2.3-pre1");

            Assert.Equal("1.2.3-pre1", semver.ToString());
        }
Пример #17
0
 public void ThrowsWhenNotMatch()
 {
     Assert.Throws <InvalidOperationException>(() => SemVer.Parse("this is not a semver string"));
 }
Пример #18
0
 public void ValidVersionsParse(string version)
 {
     _ = SemVer.Parse(version);
 }
Пример #19
0
 public void InvalidVersionsFailParse(string version)
 {
     SemVer.TryParse(version, out _).Should().BeFalse();
     Assert.Throws <FormatException>(() => SemVer.Parse(version));
 }
Пример #20
0
 public void Parse_ToString(string str)
 {
     Assert.Equal(str, SemVer.Parse(str).ToString());
 }
Пример #21
0
 public void Parse_Methods_ThrowOnNull()
 {
     Assert.Throws <ArgumentNullException>(() => SemVer.Parse(null));
     Assert.Throws <ArgumentNullException>(() => SemVer.TryParse(null, out var v));
     Assert.Throws <ArgumentNullException>(() => SemVer.TryParse(null, out var v, out var e));
 }