\d+))?" +
- @"(\-(?[0-9A-Za-z\-\.]+))?" +
- @"(\+(?[0-9A-Za-z\-\.]+))?$",
- RegexOptions.CultureInvariant | RegexOptions.Compiled | RegexOptions.ExplicitCapture);
-
- ///
- /// Initializes a new instance of the class.
- ///
- ///
- ///
- ///
- private SemVersion(SerializationInfo info, StreamingContext context)
- {
- if (info == null) throw new ArgumentNullException("info");
- var semVersion = Parse(info.GetString("SemVersion"));
- Major = semVersion.Major;
- Minor = semVersion.Minor;
- Patch = semVersion.Patch;
- Prerelease = semVersion.Prerelease;
- Build = semVersion.Build;
- }
-
- ///
- /// Initializes a new instance of the class.
- ///
- /// The major version.
- /// The minor version.
- /// The patch version.
- /// The prerelease version (eg. "alpha").
- /// The build eg ("nightly.232").
- public SemVersion(int major, int minor = 0, int patch = 0, string prerelease = "", string build = "")
- {
- this.Major = major;
- this.Minor = minor;
- this.Patch = patch;
-
- // strings are interned to be able to compare by reference in equals method
- this.Prerelease = String.Intern(prerelease ?? "");
- this.Build = String.Intern(build ?? "");
- }
-
- ///
- /// Initializes a new instance of the class.
- ///
- /// The that is used to initialize
- /// the Major, Minor, Patch and Build properties.
- public SemVersion(Version version)
- {
- version = version ?? new Version();
-
- this.Major = version.Major;
- this.Minor = version.Minor;
-
- if (version.Revision >= 0)
- {
- this.Patch = version.Revision;
- }
-
- this.Prerelease = String.Intern("");
-
- if (version.Build > 0)
- {
- this.Build = String.Intern(version.Build.ToString());
- }
- else
- {
- this.Build = String.Intern("");
- }
- }
-
- ///
- /// Parses the specified string to a semantic version.
- ///
- /// The version string.
- /// If set to true minor and patch version are required, else they default to 0.
- /// The SemVersion object.
- /// When a invalid version string is passed.
- public static SemVersion Parse(string version, bool strict = false)
- {
- var match = parseEx.Match(version);
- if (!match.Success)
- throw new ArgumentException("Invalid version.", "version");
-
- var major = Int32.Parse(match.Groups["major"].Value, CultureInfo.InvariantCulture);
-
- var minorMatch = match.Groups["minor"];
- int minor = 0;
- if (minorMatch.Success)
- minor = Int32.Parse(minorMatch.Value, CultureInfo.InvariantCulture);
- else if (strict)
- throw new InvalidOperationException("Invalid version (no minor version given in strict mode)");
-
- var patchMatch = match.Groups["patch"];
- int patch = 0;
- if (patchMatch.Success)
- patch = Int32.Parse(patchMatch.Value, CultureInfo.InvariantCulture);
- else if (strict)
- throw new InvalidOperationException("Invalid version (no patch version given in strict mode)");
-
- var prerelease = match.Groups["pre"].Value;
- var build = match.Groups["build"].Value;
-
- return new SemVersion(major, minor, patch, prerelease, build);
- }
-
- ///
- /// Parses the specified string to a semantic version.
- ///
- /// The version string.
- /// When the method returns, contains a SemVersion instance equivalent
- /// to the version string passed in, if the version string was valid, or null if the
- /// version string was not valid.
- /// If set to true minor and patch version are required, else they default to 0.
- /// False when a invalid version string is passed, otherwise true.
- public static bool TryParse(string version, out SemVersion semver, bool strict = false)
- {
- try
- {
- semver = Parse(version, strict);
- return true;
- }
- catch (Exception)
- {
- semver = null;
- return false;
- }
- }
-
- ///
- /// Tests the specified versions for equality.
- ///
- /// The first version.
- /// The second version.
- /// If versionA is equal to versionB true, else false.
- public static bool Equals(SemVersion versionA, SemVersion versionB)
- {
- if (ReferenceEquals(versionA, null))
- return ReferenceEquals(versionB, null);
- return versionA.Equals(versionB);
- }
-
- ///
- /// Compares the specified versions.
- ///
- /// The version to compare to.
- /// The version to compare against.
- /// If versionA < versionB < 0, if versionA > versionB > 0,
- /// if versionA is equal to versionB 0.
- public static int Compare(SemVersion versionA, SemVersion versionB)
- {
- if (ReferenceEquals(versionA, null))
- return ReferenceEquals(versionB, null) ? 0 : -1;
- return versionA.CompareTo(versionB);
- }
-
- ///
- /// Make a copy of the current instance with optional altered fields.
- ///
- /// The major version.
- /// The minor version.
- /// The patch version.
- /// The prerelease text.
- /// The build text.
- /// The new version object.
- public SemVersion Change(int? major = null, int? minor = null, int? patch = null,
- string prerelease = null, string build = null)
- {
- return new SemVersion(
- major ?? this.Major,
- minor ?? this.Minor,
- patch ?? this.Patch,
- prerelease ?? this.Prerelease,
- build ?? this.Build);
- }
-
- ///
- /// Gets the major version.
- ///
- ///
- /// The major version.
- ///
- public int Major { get; private set; }
-
- ///
- /// Gets the minor version.
- ///
- ///
- /// The minor version.
- ///
- public int Minor { get; private set; }
-
- ///
- /// Gets the patch version.
- ///
- ///
- /// The patch version.
- ///
- public int Patch { get; private set; }
-
- ///
- /// Gets the pre-release version.
- ///
- ///
- /// The pre-release version.
- ///
- public string Prerelease { get; private set; }
-
- ///
- /// Gets the build version.
- ///
- ///
- /// The build version.
- ///
- public string Build { get; private set; }
-
- ///
- /// Returns a that represents this instance.
- ///
- ///
- /// A that represents this instance.
- ///
- public override string ToString()
- {
- var version = "" + Major + "." + Minor + "." + Patch;
- if (!String.IsNullOrEmpty(Prerelease))
- version += "-" + Prerelease;
- if (!String.IsNullOrEmpty(Build))
- version += "+" + Build;
- return version;
- }
-
- ///
- /// Compares the current instance with another object of the same type and returns an integer that indicates
- /// whether the current instance precedes, follows, or occurs in the same position in the sort order as the
- /// other object.
- ///
- /// An object to compare with this instance.
- ///
- /// A value that indicates the relative order of the objects being compared.
- /// The return value has these meanings: Value Meaning Less than zero
- /// This instance precedes in the sort order.
- /// Zero This instance occurs in the same position in the sort order as . i
- /// Greater than zero This instance follows in the sort order.
- ///
- public int CompareTo(object obj)
- {
- return CompareTo((SemVersion)obj);
- }
-
- ///
- /// Compares the current instance with another object of the same type and returns an integer that indicates
- /// whether the current instance precedes, follows, or occurs in the same position in the sort order as the
- /// other object.
- ///
- /// An object to compare with this instance.
- ///
- /// A value that indicates the relative order of the objects being compared.
- /// The return value has these meanings: Value Meaning Less than zero
- /// This instance precedes in the sort order.
- /// Zero This instance occurs in the same position in the sort order as . i
- /// Greater than zero This instance follows in the sort order.
- ///
- public int CompareTo(SemVersion other)
- {
- if (ReferenceEquals(other, null))
- return 1;
-
- var r = this.CompareByPrecedence(other);
- if (r != 0)
- return r;
-
- r = CompareComponent(this.Build, other.Build);
- return r;
- }
-
- ///
- /// Compares to semantic versions by precedence. This does the same as a Equals, but ignores the build information.
- ///
- /// The semantic version.
- /// true if the version precedence matches.
- public bool PrecedenceMatches(SemVersion other)
- {
- return CompareByPrecedence(other) == 0;
- }
-
- ///
- /// Compares to semantic versions by precedence. This does the same as a Equals, but ignores the build information.
- ///
- /// The semantic version.
- ///
- /// A value that indicates the relative order of the objects being compared.
- /// The return value has these meanings: Value Meaning Less than zero
- /// This instance precedes in the version precedence.
- /// Zero This instance has the same precedence as . i
- /// Greater than zero This instance has creater precedence as .
- ///
- public int CompareByPrecedence(SemVersion other)
- {
- if (ReferenceEquals(other, null))
- return 1;
-
- var r = this.Major.CompareTo(other.Major);
- if (r != 0) return r;
-
- r = this.Minor.CompareTo(other.Minor);
- if (r != 0) return r;
-
- r = this.Patch.CompareTo(other.Patch);
- if (r != 0) return r;
-
- r = CompareComponent(this.Prerelease, other.Prerelease, true);
- return r;
- }
-
- static int CompareComponent(string a, string b, bool lower = false)
- {
- var aEmpty = String.IsNullOrEmpty(a);
- var bEmpty = String.IsNullOrEmpty(b);
- if (aEmpty && bEmpty)
- return 0;
-
- if (aEmpty)
- return lower ? 1 : -1;
- if (bEmpty)
- return lower ? -1 : 1;
-
- var aComps = a.Split('.');
- var bComps = b.Split('.');
-
- var minLen = Math.Min(aComps.Length, bComps.Length);
- for (int i = 0; i < minLen; i++)
- {
- var ac = aComps[i];
- var bc = bComps[i];
- int anum, bnum;
- var isanum = Int32.TryParse(ac, out anum);
- var isbnum = Int32.TryParse(bc, out bnum);
- int r;
- if (isanum && isbnum)
- {
- r = anum.CompareTo(bnum);
- if (r != 0) return anum.CompareTo(bnum);
- }
- else
- {
- if (isanum)
- return -1;
- if (isbnum)
- return 1;
- r = String.CompareOrdinal(ac, bc);
- if (r != 0)
- return r;
- }
- }
-
- return aComps.Length.CompareTo(bComps.Length);
- }
-
- ///
- /// Determines whether the specified is equal to this instance.
- ///
- /// The to compare with this instance.
- ///
- /// true if the specified is equal to this instance; otherwise, false.
- ///
- public override bool Equals(object obj)
- {
- if (ReferenceEquals(obj, null))
- return false;
-
- if (ReferenceEquals(this, obj))
- return true;
-
- var other = (SemVersion)obj;
-
- // do string comparison by reference (possible because strings are interned in ctor)
- return this.Major == other.Major &&
- this.Minor == other.Minor &&
- this.Patch == other.Patch &&
- ReferenceEquals(this.Prerelease, other.Prerelease) &&
- ReferenceEquals(this.Build, other.Build);
- }
-
- ///
- /// Returns a hash code for this instance.
- ///
- ///
- /// A hash code for this instance, suitable for use in hashing algorithms and data structures like a hash table.
- ///
- public override int GetHashCode()
- {
- unchecked
- {
- int result = this.Major.GetHashCode();
- result = result * 31 + this.Minor.GetHashCode();
- result = result * 31 + this.Patch.GetHashCode();
- result = result * 31 + this.Prerelease.GetHashCode();
- result = result * 31 + this.Build.GetHashCode();
- return result;
- }
- }
-
- [SecurityPermission(SecurityAction.Demand, SerializationFormatter = true)]
- public void GetObjectData(SerializationInfo info, StreamingContext context)
- {
- if (info == null) throw new ArgumentNullException("info");
- info.AddValue("SemVersion", ToString());
- }
-
- ///
- /// Implicit conversion from string to SemVersion.
- ///
- /// The semantic version.
- /// The SemVersion object.
- public static implicit operator SemVersion(string version)
- {
- return SemVersion.Parse(version);
- }
-
- ///
- /// The override of the equals operator.
- ///
- /// The left value.
- /// The right value.
- /// If left is equal to right true, else false.
- public static bool operator ==(SemVersion left, SemVersion right)
- {
- return SemVersion.Equals(left, right);
- }
-
- ///
- /// The override of the un-equal operator.
- ///
- /// The left value.
- /// The right value.
- /// If left is not equal to right true, else false.
- public static bool operator !=(SemVersion left, SemVersion right)
- {
- return !SemVersion.Equals(left, right);
- }
-
- ///
- /// The override of the greater operator.
- ///
- /// The left value.
- /// The right value.
- /// If left is greater than right true, else false.
- public static bool operator >(SemVersion left, SemVersion right)
- {
- return SemVersion.Compare(left, right) > 0;
- }
-
- ///
- /// The override of the greater than or equal operator.
- ///
- /// The left value.
- /// The right value.
- /// If left is greater than or equal to right true, else false.
- public static bool operator >=(SemVersion left, SemVersion right)
- {
- return left == right || left > right;
- }
-
- ///
- /// The override of the less operator.
- ///
- /// The left value.
- /// The right value.
- /// If left is less than right true, else false.
- public static bool operator <(SemVersion left, SemVersion right)
- {
- return SemVersion.Compare(left, right) < 0;
- }
-
- ///
- /// The override of the less than or equal operator.
- ///
- /// The left value.
- /// The right value.
- /// If left is less than or equal to right true, else false.
- public static bool operator <=(SemVersion left, SemVersion right)
- {
- return left == right || left < right;
- }
- }
-}
+using System;
+#if !NETSTANDARD
+using System.Globalization;
+using System.Runtime.Serialization;
+using System.Security.Permissions;
+#endif
+using System.Text.RegularExpressions;
+
+namespace Semver
+{
+ ///
+ /// A semantic version implementation.
+ /// Conforms to v2.0.0 of http://semver.org/
+ ///
+#if NETSTANDARD
+ public sealed class SemVersion : IComparable, IComparable
+#else
+ [Serializable]
+ public sealed class SemVersion : IComparable, IComparable, ISerializable
+#endif
+ {
+ static Regex parseEx =
+ new Regex(@"^(?\d+)" +
+ @"(\.(?\d+))?" +
+ @"(\.(?\d+))?" +
+ @"(\-(?[0-9A-Za-z\-\.]+))?" +
+ @"(\+(?[0-9A-Za-z\-\.]+))?$",
+#if NETSTANDARD
+ RegexOptions.CultureInvariant | RegexOptions.ExplicitCapture);
+#else
+ RegexOptions.CultureInvariant | RegexOptions.Compiled | RegexOptions.ExplicitCapture);
+#endif
+
+#if !NETSTANDARD
+ ///
+ /// Initializes a new instance of the class.
+ ///
+ ///
+ ///
+ ///
+ private SemVersion(SerializationInfo info, StreamingContext context)
+ {
+ if (info == null) throw new ArgumentNullException("info");
+ var semVersion = Parse(info.GetString("SemVersion"));
+ Major = semVersion.Major;
+ Minor = semVersion.Minor;
+ Patch = semVersion.Patch;
+ Prerelease = semVersion.Prerelease;
+ Build = semVersion.Build;
+ }
+#endif
+
+ ///
+ /// Initializes a new instance of the class.
+ ///
+ /// The major version.
+ /// The minor version.
+ /// The patch version.
+ /// The prerelease version (eg. "alpha").
+ /// The build eg ("nightly.232").
+ public SemVersion(int major, int minor = 0, int patch = 0, string prerelease = "", string build = "")
+ {
+ this.Major = major;
+ this.Minor = minor;
+ this.Patch = patch;
+
+ this.Prerelease = prerelease ?? "";
+ this.Build = build ?? "";
+ }
+
+ ///
+ /// Initializes a new instance of the class.
+ ///
+ /// The that is used to initialize
+ /// the Major, Minor, Patch and Build properties.
+ public SemVersion(Version version)
+ {
+ if (version == null)
+ throw new ArgumentNullException("version");
+
+ this.Major = version.Major;
+ this.Minor = version.Minor;
+
+ if (version.Revision >= 0)
+ {
+ this.Patch = version.Revision;
+ }
+
+ this.Prerelease = String.Empty;
+
+ if (version.Build > 0)
+ {
+ this.Build = version.Build.ToString();
+ }
+ else
+ {
+ this.Build = String.Empty;
+ }
+ }
+
+ ///
+ /// Parses the specified string to a semantic version.
+ ///
+ /// The version string.
+ /// If set to true minor and patch version are required, else they default to 0.
+ /// The SemVersion object.
+ /// When a invalid version string is passed.
+ public static SemVersion Parse(string version, bool strict = false)
+ {
+ var match = parseEx.Match(version);
+ if (!match.Success)
+ throw new ArgumentException("Invalid version.", "version");
+
+#if NETSTANDARD
+ var major = int.Parse(match.Groups["major"].Value);
+#else
+ var major = int.Parse(match.Groups["major"].Value, CultureInfo.InvariantCulture);
+#endif
+
+ var minorMatch = match.Groups["minor"];
+ int minor = 0;
+ if (minorMatch.Success)
+ {
+#if NETSTANDARD
+ minor = int.Parse(minorMatch.Value);
+#else
+ minor = int.Parse(minorMatch.Value, CultureInfo.InvariantCulture);
+#endif
+ }
+ else if (strict)
+ {
+ throw new InvalidOperationException("Invalid version (no minor version given in strict mode)");
+ }
+
+ var patchMatch = match.Groups["patch"];
+ int patch = 0;
+ if (patchMatch.Success)
+ {
+#if NETSTANDARD
+ patch = int.Parse(patchMatch.Value);
+#else
+ patch = int.Parse(patchMatch.Value, CultureInfo.InvariantCulture);
+#endif
+ }
+ else if (strict)
+ {
+ throw new InvalidOperationException("Invalid version (no patch version given in strict mode)");
+ }
+
+ var prerelease = match.Groups["pre"].Value;
+ var build = match.Groups["build"].Value;
+
+ return new SemVersion(major, minor, patch, prerelease, build);
+ }
+
+ ///
+ /// Parses the specified string to a semantic version.
+ ///
+ /// The version string.
+ /// When the method returns, contains a SemVersion instance equivalent
+ /// to the version string passed in, if the version string was valid, or null if the
+ /// version string was not valid.
+ /// If set to true minor and patch version are required, else they default to 0.
+ /// False when a invalid version string is passed, otherwise true.
+ public static bool TryParse(string version, out SemVersion semver, bool strict = false)
+ {
+ try
+ {
+ semver = Parse(version, strict);
+ return true;
+ }
+ catch (Exception)
+ {
+ semver = null;
+ return false;
+ }
+ }
+
+ ///
+ /// Tests the specified versions for equality.
+ ///
+ /// The first version.
+ /// The second version.
+ /// If versionA is equal to versionB true, else false.
+ public static bool Equals(SemVersion versionA, SemVersion versionB)
+ {
+ if (ReferenceEquals(versionA, null))
+ return ReferenceEquals(versionB, null);
+ return versionA.Equals(versionB);
+ }
+
+ ///
+ /// Compares the specified versions.
+ ///
+ /// The version to compare to.
+ /// The version to compare against.
+ /// If versionA < versionB < 0, if versionA > versionB > 0,
+ /// if versionA is equal to versionB 0.
+ public static int Compare(SemVersion versionA, SemVersion versionB)
+ {
+ if (ReferenceEquals(versionA, null))
+ return ReferenceEquals(versionB, null) ? 0 : -1;
+ return versionA.CompareTo(versionB);
+ }
+
+ ///
+ /// Make a copy of the current instance with optional altered fields.
+ ///
+ /// The major version.
+ /// The minor version.
+ /// The patch version.
+ /// The prerelease text.
+ /// The build text.
+ /// The new version object.
+ public SemVersion Change(int? major = null, int? minor = null, int? patch = null,
+ string prerelease = null, string build = null)
+ {
+ return new SemVersion(
+ major ?? this.Major,
+ minor ?? this.Minor,
+ patch ?? this.Patch,
+ prerelease ?? this.Prerelease,
+ build ?? this.Build);
+ }
+
+ ///
+ /// Gets the major version.
+ ///
+ ///
+ /// The major version.
+ ///
+ public int Major { get; private set; }
+
+ ///
+ /// Gets the minor version.
+ ///
+ ///
+ /// The minor version.
+ ///
+ public int Minor { get; private set; }
+
+ ///
+ /// Gets the patch version.
+ ///
+ ///
+ /// The patch version.
+ ///
+ public int Patch { get; private set; }
+
+ ///
+ /// Gets the pre-release version.
+ ///
+ ///
+ /// The pre-release version.
+ ///
+ public string Prerelease { get; private set; }
+
+ ///
+ /// Gets the build version.
+ ///
+ ///
+ /// The build version.
+ ///
+ public string Build { get; private set; }
+
+ ///
+ /// Returns a that represents this instance.
+ ///
+ ///
+ /// A that represents this instance.
+ ///
+ public override string ToString()
+ {
+ var version = "" + Major + "." + Minor + "." + Patch;
+ if (!String.IsNullOrEmpty(Prerelease))
+ version += "-" + Prerelease;
+ if (!String.IsNullOrEmpty(Build))
+ version += "+" + Build;
+ return version;
+ }
+
+ ///
+ /// Compares the current instance with another object of the same type and returns an integer that indicates
+ /// whether the current instance precedes, follows, or occurs in the same position in the sort order as the
+ /// other object.
+ ///
+ /// An object to compare with this instance.
+ ///
+ /// A value that indicates the relative order of the objects being compared.
+ /// The return value has these meanings: Value Meaning Less than zero
+ /// This instance precedes in the sort order.
+ /// Zero This instance occurs in the same position in the sort order as . i
+ /// Greater than zero This instance follows in the sort order.
+ ///
+ public int CompareTo(object obj)
+ {
+ return CompareTo((SemVersion)obj);
+ }
+
+ ///
+ /// Compares the current instance with another object of the same type and returns an integer that indicates
+ /// whether the current instance precedes, follows, or occurs in the same position in the sort order as the
+ /// other object.
+ ///
+ /// An object to compare with this instance.
+ ///
+ /// A value that indicates the relative order of the objects being compared.
+ /// The return value has these meanings: Value Meaning Less than zero
+ /// This instance precedes in the sort order.
+ /// Zero This instance occurs in the same position in the sort order as . i
+ /// Greater than zero This instance follows in the sort order.
+ ///
+ public int CompareTo(SemVersion other)
+ {
+ if (ReferenceEquals(other, null))
+ return 1;
+
+ var r = this.CompareByPrecedence(other);
+ if (r != 0)
+ return r;
+
+ r = CompareComponent(this.Build, other.Build);
+ return r;
+ }
+
+ ///
+ /// Compares to semantic versions by precedence. This does the same as a Equals, but ignores the build information.
+ ///
+ /// The semantic version.
+ /// true if the version precedence matches.
+ public bool PrecedenceMatches(SemVersion other)
+ {
+ return CompareByPrecedence(other) == 0;
+ }
+
+ ///
+ /// Compares to semantic versions by precedence. This does the same as a Equals, but ignores the build information.
+ ///
+ /// The semantic version.
+ ///
+ /// A value that indicates the relative order of the objects being compared.
+ /// The return value has these meanings: Value Meaning Less than zero
+ /// This instance precedes in the version precedence.
+ /// Zero This instance has the same precedence as . i
+ /// Greater than zero This instance has creater precedence as .
+ ///
+ public int CompareByPrecedence(SemVersion other)
+ {
+ if (ReferenceEquals(other, null))
+ return 1;
+
+ var r = this.Major.CompareTo(other.Major);
+ if (r != 0) return r;
+
+ r = this.Minor.CompareTo(other.Minor);
+ if (r != 0) return r;
+
+ r = this.Patch.CompareTo(other.Patch);
+ if (r != 0) return r;
+
+ r = CompareComponent(this.Prerelease, other.Prerelease, true);
+ return r;
+ }
+
+ static int CompareComponent(string a, string b, bool lower = false)
+ {
+ var aEmpty = String.IsNullOrEmpty(a);
+ var bEmpty = String.IsNullOrEmpty(b);
+ if (aEmpty && bEmpty)
+ return 0;
+
+ if (aEmpty)
+ return lower ? 1 : -1;
+ if (bEmpty)
+ return lower ? -1 : 1;
+
+ var aComps = a.Split('.');
+ var bComps = b.Split('.');
+
+ var minLen = Math.Min(aComps.Length, bComps.Length);
+ for (int i = 0; i < minLen; i++)
+ {
+ var ac = aComps[i];
+ var bc = bComps[i];
+ int anum, bnum;
+ var isanum = Int32.TryParse(ac, out anum);
+ var isbnum = Int32.TryParse(bc, out bnum);
+ int r;
+ if (isanum && isbnum)
+ {
+ r = anum.CompareTo(bnum);
+ if (r != 0) return anum.CompareTo(bnum);
+ }
+ else
+ {
+ if (isanum)
+ return -1;
+ if (isbnum)
+ return 1;
+ r = String.CompareOrdinal(ac, bc);
+ if (r != 0)
+ return r;
+ }
+ }
+
+ return aComps.Length.CompareTo(bComps.Length);
+ }
+
+ ///
+ /// Determines whether the specified is equal to this instance.
+ ///
+ /// The to compare with this instance.
+ ///
+ /// true if the specified is equal to this instance; otherwise, false.
+ ///
+ public override bool Equals(object obj)
+ {
+ if (ReferenceEquals(obj, null))
+ return false;
+
+ if (ReferenceEquals(this, obj))
+ return true;
+
+ var other = (SemVersion)obj;
+
+ return this.Major == other.Major &&
+ this.Minor == other.Minor &&
+ this.Patch == other.Patch &&
+ string.Equals(this.Prerelease, other.Prerelease, StringComparison.Ordinal) &&
+ string.Equals(this.Build, other.Build, StringComparison.Ordinal);
+ }
+
+ ///
+ /// Returns a hash code for this instance.
+ ///
+ ///
+ /// A hash code for this instance, suitable for use in hashing algorithms and data structures like a hash table.
+ ///
+ public override int GetHashCode()
+ {
+ unchecked
+ {
+ int result = this.Major.GetHashCode();
+ result = result * 31 + this.Minor.GetHashCode();
+ result = result * 31 + this.Patch.GetHashCode();
+ result = result * 31 + this.Prerelease.GetHashCode();
+ result = result * 31 + this.Build.GetHashCode();
+ return result;
+ }
+ }
+
+#if !NETSTANDARD
+ [SecurityPermission(SecurityAction.Demand, SerializationFormatter = true)]
+ public void GetObjectData(SerializationInfo info, StreamingContext context)
+ {
+ if (info == null) throw new ArgumentNullException("info");
+ info.AddValue("SemVersion", ToString());
+ }
+#endif
+
+ ///
+ /// Implicit conversion from string to SemVersion.
+ ///
+ /// The semantic version.
+ /// The SemVersion object.
+ public static implicit operator SemVersion(string version)
+ {
+ return SemVersion.Parse(version);
+ }
+
+ ///
+ /// The override of the equals operator.
+ ///
+ /// The left value.
+ /// The right value.
+ /// If left is equal to right true, else false.
+ public static bool operator ==(SemVersion left, SemVersion right)
+ {
+ return SemVersion.Equals(left, right);
+ }
+
+ ///
+ /// The override of the un-equal operator.
+ ///
+ /// The left value.
+ /// The right value.
+ /// If left is not equal to right true, else false.
+ public static bool operator !=(SemVersion left, SemVersion right)
+ {
+ return !SemVersion.Equals(left, right);
+ }
+
+ ///
+ /// The override of the greater operator.
+ ///
+ /// The left value.
+ /// The right value.
+ /// If left is greater than right true, else false.
+ public static bool operator >(SemVersion left, SemVersion right)
+ {
+ return SemVersion.Compare(left, right) > 0;
+ }
+
+ ///
+ /// The override of the greater than or equal operator.
+ ///
+ /// The left value.
+ /// The right value.
+ /// If left is greater than or equal to right true, else false.
+ public static bool operator >=(SemVersion left, SemVersion right)
+ {
+ return left == right || left > right;
+ }
+
+ ///
+ /// The override of the less operator.
+ ///
+ /// The left value.
+ /// The right value.
+ /// If left is less than right true, else false.
+ public static bool operator <(SemVersion left, SemVersion right)
+ {
+ return SemVersion.Compare(left, right) < 0;
+ }
+
+ ///
+ /// The override of the less than or equal operator.
+ ///
+ /// The left value.
+ /// The right value.
+ /// If left is less than or equal to right true, else false.
+ public static bool operator <=(SemVersion left, SemVersion right)
+ {
+ return left == right || left < right;
+ }
+ }
+}
diff --git a/src/Semver/Semver.xproj b/src/Semver/Semver.xproj
new file mode 100644
index 0000000..ccdb9b3
--- /dev/null
+++ b/src/Semver/Semver.xproj
@@ -0,0 +1,19 @@
+
+
+
+ 14.0
+ $(MSBuildExtensionsPath32)\Microsoft\VisualStudio\v$(VisualStudioVersion)
+
+
+
+ da3e84c8-a960-420c-a85a-718005aacc36
+ Semver
+ .\obj
+ .\bin\
+
+
+
+ 2.0
+
+
+
\ No newline at end of file
diff --git a/src/Semver/project.json b/src/Semver/project.json
new file mode 100644
index 0000000..931da6c
--- /dev/null
+++ b/src/Semver/project.json
@@ -0,0 +1,53 @@
+{
+ "version": "99.99.99-dev",
+ "title": "Semantic versioning",
+ "description": "A semver implementation in .Net based on the v2.0.0 of the spec found at http://semver.org/.",
+ "authors": [ "Max Hauser" ],
+ "copyright": "Copyright (c) 2013",
+ "packOptions": {
+ "tags": [ "semver", "semantic", "version" ],
+ "owners": [ "Max Hauser" ],
+ "projectUrl": "https://github.com/maxhauser/semver",
+ "releaseNotes": "https://github.com/maxhauser/semver/releases",
+ "licenseUrl": "http://max.mit-license.org/",
+ "repository": {
+ "type": "git",
+ "url": "https://github.com/maxhauser/semver"
+ }
+ },
+ "buildOptions": {
+ "debugType": "portable",
+ "nowarn": [
+ "CS1591"
+ ],
+ "optimize": true,
+ "warningsAsErrors": true,
+ "xmlDoc": true
+ },
+ "frameworks": {
+ "netstandard1.1": {
+ "buildOptions": {
+ "define": [ "NETSTANDARD", "NETSTANDARD1_1" ]
+ },
+ "dependencies": {
+ "System.Runtime": "4.1.0",
+ "System.Runtime.Extensions": "4.1.0",
+ "System.Runtime.InteropServices": "4.1.0",
+ "System.Text.RegularExpressions": "4.1.0"
+ }
+ },
+ "net452": {
+ "buildOptions": {
+ "define": [ "NET45" ]
+ },
+ "frameworkAssemblies": {
+ "System.Runtime": {
+ "type": "build"
+ },
+ "System.Threading.Tasks": {
+ "type": "build"
+ }
+ }
+ }
+ }
+}
\ No newline at end of file
diff --git a/Semver.Test/Properties/AssemblyInfo.cs b/test/Semver.Test/Properties/AssemblyInfo.cs
similarity index 100%
rename from Semver.Test/Properties/AssemblyInfo.cs
rename to test/Semver.Test/Properties/AssemblyInfo.cs
diff --git a/Semver.Test/SemVersionTest.cs b/test/Semver.Test/SemVersionTest.cs
similarity index 54%
rename from Semver.Test/SemVersionTest.cs
rename to test/Semver.Test/SemVersionTest.cs
index 153528f..d3c6e6c 100644
--- a/Semver.Test/SemVersionTest.cs
+++ b/test/Semver.Test/SemVersionTest.cs
@@ -1,796 +1,777 @@
-using System;
-using System.IO;
-using System.Runtime.Serialization;
-using System.Runtime.Serialization.Formatters.Binary;
-using Microsoft.VisualStudio.TestTools.UnitTesting;
-
-namespace Semver.Test
-{
- [TestClass]
- public class SemverTests
- {
- [TestMethod]
- public void CompareTestWithStrings1()
- {
- Assert.IsTrue(SemVersion.Equals("1.0.0", "1"));
- }
-
- [TestMethod]
- public void CompareTestWithStrings2()
- {
- var v = new SemVersion(1, 0, 0);
- Assert.IsTrue(v < "1.1");
- }
-
- [TestMethod]
- public void CompareTestWithStrings3()
- {
- var v = new SemVersion(1, 2);
- Assert.IsTrue(v > "1.0.0");
- }
-
- [TestMethod]
- public void CreateVersionTest()
- {
- var v = new SemVersion(1, 2, 3, "a", "b");
-
- Assert.AreEqual(1, v.Major);
- Assert.AreEqual(2, v.Minor);
- Assert.AreEqual(3, v.Patch);
- Assert.AreEqual("a", v.Prerelease);
- Assert.AreEqual("b", v.Build);
- }
-
- [TestMethod]
- public void CreateVersionTestWithNulls()
- {
- var v = new SemVersion(1, 2, 3, null, null);
-
- Assert.AreEqual(1, v.Major);
- Assert.AreEqual(2, v.Minor);
- Assert.AreEqual(3, v.Patch);
- Assert.AreEqual("", v.Prerelease);
- Assert.AreEqual("", v.Build);
- }
-
- [TestMethod]
- public void CreateVersionTestWithSystemVersion1()
- {
- var nonSemanticVersion = new Version();
- var v = new SemVersion(nonSemanticVersion);
-
- Assert.AreEqual(0, v.Major);
- Assert.AreEqual(0, v.Minor);
- Assert.AreEqual(0, v.Patch);
- Assert.AreEqual("", v.Build);
- Assert.AreEqual("", v.Prerelease);
- }
-
- [TestMethod]
- public void CreateVersionTestWithSystemVersion2()
- {
- var v = new SemVersion(null);
-
- Assert.AreEqual(0, v.Major);
- Assert.AreEqual(0, v.Minor);
- Assert.AreEqual(0, v.Patch);
- Assert.AreEqual("", v.Build);
- Assert.AreEqual("", v.Prerelease);
- }
-
- [TestMethod]
- public void CreateVersionTestWithSystemVersion3()
- {
- var nonSemanticVersion = new Version(1, 2, 0, 3);
- var v = new SemVersion(nonSemanticVersion);
-
- Assert.AreEqual(1, v.Major);
- Assert.AreEqual(2, v.Minor);
- Assert.AreEqual(3, v.Patch);
- Assert.AreEqual("", v.Build);
- Assert.AreEqual("", v.Prerelease);
- }
-
- [TestMethod]
- public void CreateVersionTestWithSystemVersion4()
- {
- var nonSemanticVersion = new Version(1, 2, 4, 3);
- var v = new SemVersion(nonSemanticVersion);
-
- Assert.AreEqual(1, v.Major);
- Assert.AreEqual(2, v.Minor);
- Assert.AreEqual(3, v.Patch);
- Assert.AreEqual("4", v.Build);
- Assert.AreEqual("", v.Prerelease);
- }
-
- [TestMethod]
- public void ParseTest1()
- {
- var version = SemVersion.Parse("1.2.45-alpha+nightly.23");
-
- Assert.AreEqual(1, version.Major);
- Assert.AreEqual(2, version.Minor);
- Assert.AreEqual(45, version.Patch);
- Assert.AreEqual("alpha", version.Prerelease);
- Assert.AreEqual("nightly.23", version.Build);
- }
-
- [TestMethod]
- public void ParseTest2()
- {
- var version = SemVersion.Parse("1");
-
- Assert.AreEqual(1, version.Major);
- Assert.AreEqual(0, version.Minor);
- Assert.AreEqual(0, version.Patch);
- Assert.AreEqual("", version.Prerelease);
- Assert.AreEqual("", version.Build);
- }
-
- [TestMethod]
- public void ParseTest3()
- {
- var version = SemVersion.Parse("1.2.45-alpha-beta+nightly.23.43-bla");
-
- Assert.AreEqual(1, version.Major);
- Assert.AreEqual(2, version.Minor);
- Assert.AreEqual(45, version.Patch);
- Assert.AreEqual("alpha-beta", version.Prerelease);
- Assert.AreEqual("nightly.23.43-bla", version.Build);
- }
-
- [TestMethod]
- public void ParseTest4()
- {
- var version = SemVersion.Parse("2.0.0+nightly.23.43-bla");
-
- Assert.AreEqual(2, version.Major);
- Assert.AreEqual(0, version.Minor);
- Assert.AreEqual(0, version.Patch);
- Assert.AreEqual("", version.Prerelease);
- Assert.AreEqual("nightly.23.43-bla", version.Build);
- }
-
- [TestMethod]
- public void ParseTest5()
- {
- var version = SemVersion.Parse("2.0+nightly.23.43-bla");
-
- Assert.AreEqual(2, version.Major);
- Assert.AreEqual(0, version.Minor);
- Assert.AreEqual(0, version.Patch);
- Assert.AreEqual("", version.Prerelease);
- Assert.AreEqual("nightly.23.43-bla", version.Build);
- }
-
- [TestMethod]
- public void ParseTest6()
- {
- var version = SemVersion.Parse("2.1-alpha");
-
- Assert.AreEqual(2, version.Major);
- Assert.AreEqual(1, version.Minor);
- Assert.AreEqual(0, version.Patch);
- Assert.AreEqual("alpha", version.Prerelease);
- Assert.AreEqual("", version.Build);
- }
-
- [TestMethod]
- [ExpectedException(typeof(ArgumentException))]
- public void ParseTest7()
- {
- var version = SemVersion.Parse("ui-2.1-alpha");
- }
-
- [TestMethod]
- public void ParseTestStrict1()
- {
- var version = SemVersion.Parse("1.3.4", true);
-
- Assert.AreEqual(1, version.Major);
- Assert.AreEqual(3, version.Minor);
- Assert.AreEqual(4, version.Patch);
- Assert.AreEqual("", version.Prerelease);
- Assert.AreEqual("", version.Build);
- }
-
- [TestMethod]
- [ExpectedException(typeof(InvalidOperationException))]
- public void ParseTestStrict2()
- {
- var version = SemVersion.Parse("1", true);
- }
-
- [TestMethod]
- [ExpectedException(typeof(InvalidOperationException))]
- public void ParseTestStrict3()
- {
- var version = SemVersion.Parse("1.3", true);
- }
-
- [TestMethod]
- [ExpectedException(typeof(InvalidOperationException))]
- public void ParseTestStrict4()
- {
- var version = SemVersion.Parse("1.3-alpha", true);
- }
-
- [TestMethod]
- public void TryParseTest1()
- {
- SemVersion v;
- Assert.IsTrue(SemVersion.TryParse("1.2.45-alpha-beta+nightly.23.43-bla", out v));
- }
-
- [TestMethod]
- public void TryParseTest2()
- {
- SemVersion v;
- Assert.IsFalse(SemVersion.TryParse("ui-2.1-alpha", out v));
- }
-
- [TestMethod]
- public void TryParseTest3()
- {
- SemVersion v;
- Assert.IsFalse(SemVersion.TryParse("", out v));
- }
-
- [TestMethod]
- public void TryParseTest4()
- {
- SemVersion v;
- Assert.IsFalse(SemVersion.TryParse(null, out v));
- }
-
- [TestMethod]
- public void TryParseTest5()
- {
- SemVersion v;
- Assert.IsTrue(SemVersion.TryParse("1.2", out v, false));
- }
-
- [TestMethod]
- public void TryParseTest6()
- {
- SemVersion v;
- Assert.IsFalse(SemVersion.TryParse("1.2", out v, true));
- }
-
- [TestMethod]
- public void ToStringTest()
- {
- var version = new SemVersion(1, 2, 0, "beta", "dev-mha.120");
-
- Assert.AreEqual("1.2.0-beta+dev-mha.120", version.ToString());
- }
-
- [TestMethod]
- public void EqualTest1()
- {
- var v1 = new SemVersion(1, 2, build: "nightly");
- var v2 = new SemVersion(1, 2, build: "nightly");
-
- var r = v1.Equals(v2);
- Assert.IsTrue(r);
- }
-
- [TestMethod]
- public void EqualTest2()
- {
- var v1 = new SemVersion(1, 2, prerelease: "alpha", build: "dev");
- var v2 = new SemVersion(1, 2, prerelease: "alpha", build: "dev");
-
- var r = v1.Equals(v2);
- Assert.IsTrue(r);
- }
-
- [TestMethod]
- public void EqualTest3()
- {
- var v1 = SemVersion.Parse("1.2-nightly+dev");
- var v2 = SemVersion.Parse("1.2.0-nightly");
-
- var r = v1.Equals(v2);
- Assert.IsFalse(r);
- }
-
- [TestMethod]
- public void EqualTest4()
- {
- var v1 = SemVersion.Parse("1.2-nightly");
- var v2 = SemVersion.Parse("1.2.0-nightly2");
-
- var r = v1.Equals(v2);
- Assert.IsFalse(r);
- }
-
- [TestMethod]
- public void EqualTest5()
- {
- var v1 = SemVersion.Parse("1.2.1");
- var v2 = SemVersion.Parse("1.2.0");
-
- var r = v1.Equals(v2);
- Assert.IsFalse(r);
- }
-
- [TestMethod]
- public void EqualTest6()
- {
- var v1 = SemVersion.Parse("1.4.0");
- var v2 = SemVersion.Parse("1.2.0");
-
- var r = v1.Equals(v2);
- Assert.IsFalse(r);
- }
-
- [TestMethod]
- public void EqualByReferenceTest()
- {
- var v1 = SemVersion.Parse("1.2-nightly");
-
- var r = v1.Equals(v1);
- Assert.IsTrue(r);
- }
-
- [TestMethod]
- public void CompareTest1()
- {
- var v1 = SemVersion.Parse("1.0.0");
- var v2 = SemVersion.Parse("2.0.0");
-
- var r = v1.CompareTo(v2);
- Assert.AreEqual(-1, r);
- }
-
- [TestMethod]
- public void CompareTest2()
- {
- var v1 = SemVersion.Parse("1.0.0-beta+dev.123");
- var v2 = SemVersion.Parse("1-beta+dev.123");
-
- var r = v1.CompareTo(v2);
- Assert.AreEqual(0, r);
- }
-
- [TestMethod]
- public void CompareTest3()
- {
- var v1 = SemVersion.Parse("1.0.0-alpha+dev.123");
- var v2 = SemVersion.Parse("1-beta+dev.123");
-
- var r = v1.CompareTo(v2);
- Assert.AreEqual(-1, r);
- }
-
- [TestMethod]
- public void CompareTest4()
- {
- var v1 = SemVersion.Parse("1.0.0-alpha");
- var v2 = SemVersion.Parse("1.0.0");
-
- var r = v1.CompareTo(v2);
- Assert.AreEqual(-1, r);
- }
-
- [TestMethod]
- public void CompareTest5()
- {
- var v1 = SemVersion.Parse("1.0.0");
- var v2 = SemVersion.Parse("1.0.0-alpha");
-
- var r = v1.CompareTo(v2);
- Assert.AreEqual(1, r);
- }
-
- [TestMethod]
- public void CompareTest6()
- {
- var v1 = SemVersion.Parse("1.0.0");
- var v2 = SemVersion.Parse("1.0.1-alpha");
-
- var r = v1.CompareTo(v2);
- Assert.AreEqual(-1, r);
- }
-
- [TestMethod]
- public void CompareTest7()
- {
- var v1 = SemVersion.Parse("0.0.1");
- var v2 = SemVersion.Parse("0.0.1+build.12");
-
- var r = v1.CompareTo(v2);
- Assert.AreEqual(-1, r);
- }
-
- [TestMethod]
- public void CompareTest8()
- {
- var v1 = SemVersion.Parse("0.0.1+build.13");
- var v2 = SemVersion.Parse("0.0.1+build.12.2");
-
- var r = v1.CompareTo(v2);
- Assert.AreEqual(1, r);
- }
-
- [TestMethod]
- public void CompareTest9()
- {
- var v1 = SemVersion.Parse("0.0.1-13");
- var v2 = SemVersion.Parse("0.0.1-b");
-
- var r = v1.CompareTo(v2);
- Assert.AreEqual(-1, r);
- }
-
- [TestMethod]
- public void CompareTest10()
- {
- var v1 = SemVersion.Parse("0.0.1+uiui");
- var v2 = SemVersion.Parse("0.0.1+12");
-
- var r = v1.CompareTo(v2);
- Assert.AreEqual(1, r);
- }
-
- [TestMethod]
- public void CompareTest11()
- {
- var v1 = SemVersion.Parse("0.0.1+bu");
- var v2 = SemVersion.Parse("0.0.1");
-
- var r = v1.CompareTo(v2);
- Assert.AreEqual(1, r);
- }
-
- [TestMethod]
- public void CompareTest12()
- {
- var v1 = SemVersion.Parse("0.1.1+bu");
- var v2 = SemVersion.Parse("0.2.1");
-
- var r = v1.CompareTo(v2);
- Assert.AreEqual(-1, r);
- }
-
- [TestMethod]
- public void CompareTest13()
- {
- var v1 = SemVersion.Parse("0.1.1-gamma.12.87");
- var v2 = SemVersion.Parse("0.1.1-gamma.12.88");
-
- var r = v1.CompareTo(v2);
- Assert.AreEqual(-1, r);
- }
-
- [TestMethod]
- public void CompareTest14()
- {
- var v1 = SemVersion.Parse("0.1.1-gamma.12.87");
- var v2 = SemVersion.Parse("0.1.1-gamma.12.87.1");
-
- var r = v1.CompareTo(v2);
- Assert.AreEqual(-1, r);
- }
-
- [TestMethod]
- public void CompareTest15()
- {
- var v1 = SemVersion.Parse("0.1.1-gamma.12.87.99");
- var v2 = SemVersion.Parse("0.1.1-gamma.12.87.X");
-
- var r = v1.CompareTo(v2);
- Assert.AreEqual(-1, r);
- }
-
- [TestMethod]
- public void CompareTest16()
- {
- var v1 = SemVersion.Parse("0.1.1-gamma.12.87");
- var v2 = SemVersion.Parse("0.1.1-gamma.12.87.X");
-
- var r = v1.CompareTo(v2);
- Assert.AreEqual(-1, r);
- }
-
- [TestMethod]
- public void CompareNullTest()
- {
- var v1 = SemVersion.Parse("0.0.1+bu");
- var r = v1.CompareTo(null);
- Assert.AreEqual(1, r);
- }
-
- [TestMethod]
- public void TestHashCode()
- {
- var v1 = SemVersion.Parse("1.0.0-1+b");
- var v2 = SemVersion.Parse("1.0.0-1+c");
-
- var h1 = v1.GetHashCode();
- var h2 = v2.GetHashCode();
-
- Assert.AreNotEqual(h1, h2);
- }
-
- [TestMethod]
- public void TestStringConversion()
- {
- SemVersion v = "1.0.0";
- Assert.AreEqual(1, v.Major);
- }
-
- [TestMethod]
- public void TestUntypedCompareTo()
- {
- var v1 = new SemVersion(1);
- var c = v1.CompareTo((object)v1);
-
- Assert.AreEqual(0, c);
- }
-
- [TestMethod]
- public void StaticEqualsTest1()
- {
- var v1 = new SemVersion(1, 2, 3);
- var v2 = new SemVersion(1, 2, 3);
-
- var r = SemVersion.Equals(v1, v2);
- Assert.IsTrue(r);
- }
-
- [TestMethod]
- public void StaticEqualsTest2()
- {
- var r = SemVersion.Equals(null, null);
- Assert.IsTrue(r);
- }
-
- [TestMethod]
- public void StaticEqualsTest3()
- {
- var v1 = new SemVersion(1);
-
- var r = SemVersion.Equals(v1, null);
- Assert.IsFalse(r);
- }
-
- [TestMethod]
- public void StaticCompareTest1()
- {
- var v1 = new SemVersion(1);
- var v2 = new SemVersion(2);
-
- var r = SemVersion.Compare(v1, v2);
- Assert.AreEqual(-1, r);
- }
-
- [TestMethod]
- public void StaticCompareTest2()
- {
- var v1 = new SemVersion(1);
-
- var r = SemVersion.Compare(v1, null);
- Assert.AreEqual(1, r);
- }
-
- [TestMethod]
- public void StaticCompareTest3()
- {
- var v1 = new SemVersion(1);
-
- var r = SemVersion.Compare(null, v1);
- Assert.AreEqual(-1, r);
- }
-
- [TestMethod]
- public void StaticCompareTest4()
- {
- var r = SemVersion.Compare(null, null);
- Assert.AreEqual(0, r);
- }
-
- [TestMethod]
- public void EqualsOperatorTest()
- {
- var v1 = new SemVersion(1);
- var v2 = new SemVersion(1);
-
- var r = v1 == v2;
- Assert.IsTrue(r);
- }
-
- [TestMethod]
- public void UnequalOperatorTest()
- {
- var v1 = new SemVersion(1);
- var v2 = new SemVersion(2);
-
- var r = v1 != v2;
- Assert.IsTrue(r);
- }
-
- [TestMethod]
- public void GreaterOperatorTest()
- {
- var v1 = new SemVersion(1);
- var v2 = new SemVersion(2);
-
- var r = v2 > v1;
- Assert.IsTrue(r);
- }
-
- [TestMethod]
- public void GreaterOperatorTest2()
- {
- var v1 = new SemVersion( 1, 0, 0, "alpha" );
- var v2 = new SemVersion( 1, 0, 0, "rc" );
-
- var r = v2 > v1;
- Assert.IsTrue( r );
- }
-
- [TestMethod]
- public void GreaterOperatorTest3()
- {
- var v1 = new SemVersion( 1, 0, 0, "-ci.1" );
- var v2 = new SemVersion( 1, 0, 0, "alpha" );
-
- var r = v2 > v1;
- Assert.IsTrue( r );
- }
-
- [TestMethod]
- public void GreaterOrEqualOperatorTest1()
- {
- var v1 = new SemVersion(1);
- var v2 = new SemVersion(1);
-
- var r = v1 >= v2;
- Assert.IsTrue(r);
- }
-
- [TestMethod]
- public void GreaterOrEqualOperatorTest2()
- {
- var v1 = new SemVersion(2);
- var v2 = new SemVersion(1);
-
- var r = v1 >= v2;
- Assert.IsTrue(r);
- }
-
- [TestMethod]
- public void LessOperatorTest()
- {
- var v1 = new SemVersion(1);
- var v2 = new SemVersion(2);
-
- var r = v1 < v2;
- Assert.IsTrue(r);
- }
-
- [TestMethod]
- public void LessOperatorTest2()
- {
- var v1 = new SemVersion( 1, 0, 0, "alpha" );
- var v2 = new SemVersion( 1, 0, 0, "rc" );
-
- var r = v1 < v2;
- Assert.IsTrue( r );
- }
-
- [TestMethod]
- public void LessOperatorTest3()
- {
- var v1 = new SemVersion( 1, 0, 0, "-ci.1" );
- var v2 = new SemVersion( 1, 0, 0, "alpha" );
-
- var r = v1 < v2;
- Assert.IsTrue( r );
- }
-
- [TestMethod]
- public void LessOrEqualOperatorTest1()
- {
- var v1 = new SemVersion(1);
- var v2 = new SemVersion(1);
-
- var r = v1 <= v2;
- Assert.IsTrue(r);
- }
-
- [TestMethod]
- public void LessOrEqualOperatorTest2()
- {
- var v1 = new SemVersion(1);
- var v2 = new SemVersion(2);
-
- var r = v1 <= v2;
- Assert.IsTrue(r);
- }
-
- [TestMethod]
- public void TestChangeMajor()
- {
- var v1 = new SemVersion(1, 2, 3, "alpha", "dev");
- var v2 = v1.Change(major: 5);
-
- Assert.AreEqual(5, v2.Major);
- Assert.AreEqual(2, v2.Minor);
- Assert.AreEqual(3, v2.Patch);
- Assert.AreEqual("alpha", v2.Prerelease);
- Assert.AreEqual("dev", v2.Build);
- }
-
- [TestMethod]
- public void TestChangeMinor()
- {
- var v1 = new SemVersion(1, 2, 3, "alpha", "dev");
- var v2 = v1.Change(minor: 5);
-
- Assert.AreEqual(1, v2.Major);
- Assert.AreEqual(5, v2.Minor);
- Assert.AreEqual(3, v2.Patch);
- Assert.AreEqual("alpha", v2.Prerelease);
- Assert.AreEqual("dev", v2.Build);
- }
-
- [TestMethod]
- public void TestChangePatch()
- {
- var v1 = new SemVersion(1, 2, 3, "alpha", "dev");
- var v2 = v1.Change(patch: 5);
-
- Assert.AreEqual(1, v2.Major);
- Assert.AreEqual(2, v2.Minor);
- Assert.AreEqual(5, v2.Patch);
- Assert.AreEqual("alpha", v2.Prerelease);
- Assert.AreEqual("dev", v2.Build);
- }
-
- [TestMethod]
- public void TestChangePrerelease()
- {
- var v1 = new SemVersion(1, 2, 3, "alpha", "dev");
- var v2 = v1.Change(prerelease: "beta");
-
- Assert.AreEqual(1, v2.Major);
- Assert.AreEqual(2, v2.Minor);
- Assert.AreEqual(3, v2.Patch);
- Assert.AreEqual("beta", v2.Prerelease);
- Assert.AreEqual("dev", v2.Build);
- }
-
- [TestMethod]
- public void TestChangeBuild()
- {
- var v1 = new SemVersion(1, 2, 3, "alpha", "dev");
- var v2 = v1.Change(build: "rel");
-
- Assert.AreEqual(1, v2.Major);
- Assert.AreEqual(2, v2.Minor);
- Assert.AreEqual(3, v2.Patch);
- Assert.AreEqual("alpha", v2.Prerelease);
- Assert.AreEqual("rel", v2.Build);
- }
-
- [TestMethod]
- public void TestSerialization()
- {
- var semVer = new SemVersion(1, 2, 3, "alpha", "dev");
- SemVersion semVerSerializedDeserialized;
- using (var ms = new MemoryStream())
- {
- var bf = new BinaryFormatter();
- bf.Serialize(ms, semVer);
- ms.Position = 0;
- semVerSerializedDeserialized = (SemVersion) bf.Deserialize(ms);
- }
- Assert.AreEqual(semVer, semVerSerializedDeserialized);
- }
-
- }
-}
+using System;
+using System.IO;
+#if !NETSTANDARD
+using System.Runtime.Serialization.Formatters.Binary;
+#endif
+using Xunit;
+
+namespace Semver.Test
+{
+ public class SemverTests
+ {
+ [Fact]
+ public void CompareTestWithStrings1()
+ {
+ Assert.True(SemVersion.Equals("1.0.0", "1"));
+ }
+
+ [Fact]
+ public void CompareTestWithStrings2()
+ {
+ var v = new SemVersion(1, 0, 0);
+ Assert.True(v < "1.1");
+ }
+
+ [Fact]
+ public void CompareTestWithStrings3()
+ {
+ var v = new SemVersion(1, 2);
+ Assert.True(v > "1.0.0");
+ }
+
+ [Fact]
+ public void CreateVersionTest()
+ {
+ var v = new SemVersion(1, 2, 3, "a", "b");
+
+ Assert.Equal(1, v.Major);
+ Assert.Equal(2, v.Minor);
+ Assert.Equal(3, v.Patch);
+ Assert.Equal("a", v.Prerelease);
+ Assert.Equal("b", v.Build);
+ }
+
+ [Fact]
+ public void CreateVersionTestWithNulls()
+ {
+ var v = new SemVersion(1, 2, 3, null, null);
+
+ Assert.Equal(1, v.Major);
+ Assert.Equal(2, v.Minor);
+ Assert.Equal(3, v.Patch);
+ Assert.Equal("", v.Prerelease);
+ Assert.Equal("", v.Build);
+ }
+
+ [Fact]
+ public void CreateVersionTestWithSystemVersion1()
+ {
+ var nonSemanticVersion = new Version(0, 0);
+ var v = new SemVersion(nonSemanticVersion);
+
+ Assert.Equal(0, v.Major);
+ Assert.Equal(0, v.Minor);
+ Assert.Equal(0, v.Patch);
+ Assert.Equal("", v.Build);
+ Assert.Equal("", v.Prerelease);
+ }
+
+ [Fact]
+ public void CreateVersionTestWithSystemVersion2()
+ {
+ Assert.Throws(typeof(ArgumentNullException), () =>
+ {
+ var v = new SemVersion(null);
+ });
+ }
+
+ [Fact]
+ public void CreateVersionTestWithSystemVersion3()
+ {
+ var nonSemanticVersion = new Version(1, 2, 0, 3);
+ var v = new SemVersion(nonSemanticVersion);
+
+ Assert.Equal(1, v.Major);
+ Assert.Equal(2, v.Minor);
+ Assert.Equal(3, v.Patch);
+ Assert.Equal("", v.Build);
+ Assert.Equal("", v.Prerelease);
+ }
+
+ [Fact]
+ public void CreateVersionTestWithSystemVersion4()
+ {
+ var nonSemanticVersion = new Version(1, 2, 4, 3);
+ var v = new SemVersion(nonSemanticVersion);
+
+ Assert.Equal(1, v.Major);
+ Assert.Equal(2, v.Minor);
+ Assert.Equal(3, v.Patch);
+ Assert.Equal("4", v.Build);
+ Assert.Equal("", v.Prerelease);
+ }
+
+ [Fact]
+ public void ParseTest1()
+ {
+ var version = SemVersion.Parse("1.2.45-alpha+nightly.23");
+
+ Assert.Equal(1, version.Major);
+ Assert.Equal(2, version.Minor);
+ Assert.Equal(45, version.Patch);
+ Assert.Equal("alpha", version.Prerelease);
+ Assert.Equal("nightly.23", version.Build);
+ }
+
+ [Fact]
+ public void ParseTest2()
+ {
+ var version = SemVersion.Parse("1");
+
+ Assert.Equal(1, version.Major);
+ Assert.Equal(0, version.Minor);
+ Assert.Equal(0, version.Patch);
+ Assert.Equal("", version.Prerelease);
+ Assert.Equal("", version.Build);
+ }
+
+ [Fact]
+ public void ParseTest3()
+ {
+ var version = SemVersion.Parse("1.2.45-alpha-beta+nightly.23.43-bla");
+
+ Assert.Equal(1, version.Major);
+ Assert.Equal(2, version.Minor);
+ Assert.Equal(45, version.Patch);
+ Assert.Equal("alpha-beta", version.Prerelease);
+ Assert.Equal("nightly.23.43-bla", version.Build);
+ }
+
+ [Fact]
+ public void ParseTest4()
+ {
+ var version = SemVersion.Parse("2.0.0+nightly.23.43-bla");
+
+ Assert.Equal(2, version.Major);
+ Assert.Equal(0, version.Minor);
+ Assert.Equal(0, version.Patch);
+ Assert.Equal("", version.Prerelease);
+ Assert.Equal("nightly.23.43-bla", version.Build);
+ }
+
+ [Fact]
+ public void ParseTest5()
+ {
+ var version = SemVersion.Parse("2.0+nightly.23.43-bla");
+
+ Assert.Equal(2, version.Major);
+ Assert.Equal(0, version.Minor);
+ Assert.Equal(0, version.Patch);
+ Assert.Equal("", version.Prerelease);
+ Assert.Equal("nightly.23.43-bla", version.Build);
+ }
+
+ [Fact]
+ public void ParseTest6()
+ {
+ var version = SemVersion.Parse("2.1-alpha");
+
+ Assert.Equal(2, version.Major);
+ Assert.Equal(1, version.Minor);
+ Assert.Equal(0, version.Patch);
+ Assert.Equal("alpha", version.Prerelease);
+ Assert.Equal("", version.Build);
+ }
+
+ [Fact]
+ public void ParseTest7()
+ {
+ Assert.Throws(() => SemVersion.Parse("ui-2.1-alpha"));
+ }
+
+ [Fact]
+ public void ParseTestStrict1()
+ {
+ var version = SemVersion.Parse("1.3.4", true);
+
+ Assert.Equal(1, version.Major);
+ Assert.Equal(3, version.Minor);
+ Assert.Equal(4, version.Patch);
+ Assert.Equal("", version.Prerelease);
+ Assert.Equal("", version.Build);
+ }
+
+ [Fact]
+ public void ParseTestStrict2()
+ {
+ Assert.Throws(() => SemVersion.Parse("1", true));
+ }
+
+ [Fact]
+ public void ParseTestStrict3()
+ {
+ Assert.Throws(() => SemVersion.Parse("1.3", true));
+ }
+
+ [Fact]
+ public void ParseTestStrict4()
+ {
+ Assert.Throws(() => SemVersion.Parse("1.3-alpha", true));
+ }
+
+ [Fact]
+ public void TryParseTest1()
+ {
+ SemVersion v;
+ Assert.True(SemVersion.TryParse("1.2.45-alpha-beta+nightly.23.43-bla", out v));
+ }
+
+ [Fact]
+ public void TryParseTest2()
+ {
+ SemVersion v;
+ Assert.False(SemVersion.TryParse("ui-2.1-alpha", out v));
+ }
+
+ [Fact]
+ public void TryParseTest3()
+ {
+ SemVersion v;
+ Assert.False(SemVersion.TryParse("", out v));
+ }
+
+ [Fact]
+ public void TryParseTest4()
+ {
+ SemVersion v;
+ Assert.False(SemVersion.TryParse(null, out v));
+ }
+
+ [Fact]
+ public void TryParseTest5()
+ {
+ SemVersion v;
+ Assert.True(SemVersion.TryParse("1.2", out v, false));
+ }
+
+ [Fact]
+ public void TryParseTest6()
+ {
+ SemVersion v;
+ Assert.False(SemVersion.TryParse("1.2", out v, true));
+ }
+
+ [Fact]
+ public void ToStringTest()
+ {
+ var version = new SemVersion(1, 2, 0, "beta", "dev-mha.120");
+
+ Assert.Equal("1.2.0-beta+dev-mha.120", version.ToString());
+ }
+
+ [Fact]
+ public void EqualTest1()
+ {
+ var v1 = new SemVersion(1, 2, build: "nightly");
+ var v2 = new SemVersion(1, 2, build: "nightly");
+
+ var r = v1.Equals(v2);
+ Assert.True(r);
+ }
+
+ [Fact]
+ public void EqualTest2()
+ {
+ var v1 = new SemVersion(1, 2, prerelease: "alpha", build: "dev");
+ var v2 = new SemVersion(1, 2, prerelease: "alpha", build: "dev");
+
+ var r = v1.Equals(v2);
+ Assert.True(r);
+ }
+
+ [Fact]
+ public void EqualTest3()
+ {
+ var v1 = SemVersion.Parse("1.2-nightly+dev");
+ var v2 = SemVersion.Parse("1.2.0-nightly");
+
+ var r = v1.Equals(v2);
+ Assert.False(r);
+ }
+
+ [Fact]
+ public void EqualTest4()
+ {
+ var v1 = SemVersion.Parse("1.2-nightly");
+ var v2 = SemVersion.Parse("1.2.0-nightly2");
+
+ var r = v1.Equals(v2);
+ Assert.False(r);
+ }
+
+ [Fact]
+ public void EqualTest5()
+ {
+ var v1 = SemVersion.Parse("1.2.1");
+ var v2 = SemVersion.Parse("1.2.0");
+
+ var r = v1.Equals(v2);
+ Assert.False(r);
+ }
+
+ [Fact]
+ public void EqualTest6()
+ {
+ var v1 = SemVersion.Parse("1.4.0");
+ var v2 = SemVersion.Parse("1.2.0");
+
+ var r = v1.Equals(v2);
+ Assert.False(r);
+ }
+
+ [Fact]
+ public void EqualByReferenceTest()
+ {
+ var v1 = SemVersion.Parse("1.2-nightly");
+
+ var r = v1.Equals(v1);
+ Assert.True(r);
+ }
+
+ [Fact]
+ public void CompareTest1()
+ {
+ var v1 = SemVersion.Parse("1.0.0");
+ var v2 = SemVersion.Parse("2.0.0");
+
+ var r = v1.CompareTo(v2);
+ Assert.Equal(-1, r);
+ }
+
+ [Fact]
+ public void CompareTest2()
+ {
+ var v1 = SemVersion.Parse("1.0.0-beta+dev.123");
+ var v2 = SemVersion.Parse("1-beta+dev.123");
+
+ var r = v1.CompareTo(v2);
+ Assert.Equal(0, r);
+ }
+
+ [Fact]
+ public void CompareTest3()
+ {
+ var v1 = SemVersion.Parse("1.0.0-alpha+dev.123");
+ var v2 = SemVersion.Parse("1-beta+dev.123");
+
+ var r = v1.CompareTo(v2);
+ Assert.Equal(-1, r);
+ }
+
+ [Fact]
+ public void CompareTest4()
+ {
+ var v1 = SemVersion.Parse("1.0.0-alpha");
+ var v2 = SemVersion.Parse("1.0.0");
+
+ var r = v1.CompareTo(v2);
+ Assert.Equal(-1, r);
+ }
+
+ [Fact]
+ public void CompareTest5()
+ {
+ var v1 = SemVersion.Parse("1.0.0");
+ var v2 = SemVersion.Parse("1.0.0-alpha");
+
+ var r = v1.CompareTo(v2);
+ Assert.Equal(1, r);
+ }
+
+ [Fact]
+ public void CompareTest6()
+ {
+ var v1 = SemVersion.Parse("1.0.0");
+ var v2 = SemVersion.Parse("1.0.1-alpha");
+
+ var r = v1.CompareTo(v2);
+ Assert.Equal(-1, r);
+ }
+
+ [Fact]
+ public void CompareTest7()
+ {
+ var v1 = SemVersion.Parse("0.0.1");
+ var v2 = SemVersion.Parse("0.0.1+build.12");
+
+ var r = v1.CompareTo(v2);
+ Assert.Equal(-1, r);
+ }
+
+ [Fact]
+ public void CompareTest8()
+ {
+ var v1 = SemVersion.Parse("0.0.1+build.13");
+ var v2 = SemVersion.Parse("0.0.1+build.12.2");
+
+ var r = v1.CompareTo(v2);
+ Assert.Equal(1, r);
+ }
+
+ [Fact]
+ public void CompareTest9()
+ {
+ var v1 = SemVersion.Parse("0.0.1-13");
+ var v2 = SemVersion.Parse("0.0.1-b");
+
+ var r = v1.CompareTo(v2);
+ Assert.Equal(-1, r);
+ }
+
+ [Fact]
+ public void CompareTest10()
+ {
+ var v1 = SemVersion.Parse("0.0.1+uiui");
+ var v2 = SemVersion.Parse("0.0.1+12");
+
+ var r = v1.CompareTo(v2);
+ Assert.Equal(1, r);
+ }
+
+ [Fact]
+ public void CompareTest11()
+ {
+ var v1 = SemVersion.Parse("0.0.1+bu");
+ var v2 = SemVersion.Parse("0.0.1");
+
+ var r = v1.CompareTo(v2);
+ Assert.Equal(1, r);
+ }
+
+ [Fact]
+ public void CompareTest12()
+ {
+ var v1 = SemVersion.Parse("0.1.1+bu");
+ var v2 = SemVersion.Parse("0.2.1");
+
+ var r = v1.CompareTo(v2);
+ Assert.Equal(-1, r);
+ }
+
+ [Fact]
+ public void CompareTest13()
+ {
+ var v1 = SemVersion.Parse("0.1.1-gamma.12.87");
+ var v2 = SemVersion.Parse("0.1.1-gamma.12.88");
+
+ var r = v1.CompareTo(v2);
+ Assert.Equal(-1, r);
+ }
+
+ [Fact]
+ public void CompareTest14()
+ {
+ var v1 = SemVersion.Parse("0.1.1-gamma.12.87");
+ var v2 = SemVersion.Parse("0.1.1-gamma.12.87.1");
+
+ var r = v1.CompareTo(v2);
+ Assert.Equal(-1, r);
+ }
+
+ [Fact]
+ public void CompareTest15()
+ {
+ var v1 = SemVersion.Parse("0.1.1-gamma.12.87.99");
+ var v2 = SemVersion.Parse("0.1.1-gamma.12.87.X");
+
+ var r = v1.CompareTo(v2);
+ Assert.Equal(-1, r);
+ }
+
+ [Fact]
+ public void CompareTest16()
+ {
+ var v1 = SemVersion.Parse("0.1.1-gamma.12.87");
+ var v2 = SemVersion.Parse("0.1.1-gamma.12.87.X");
+
+ var r = v1.CompareTo(v2);
+ Assert.Equal(-1, r);
+ }
+
+ [Fact]
+ public void CompareNullTest()
+ {
+ var v1 = SemVersion.Parse("0.0.1+bu");
+ var r = v1.CompareTo(null);
+ Assert.Equal(1, r);
+ }
+
+ [Fact]
+ public void TestHashCode()
+ {
+ var v1 = SemVersion.Parse("1.0.0-1+b");
+ var v2 = SemVersion.Parse("1.0.0-1+c");
+
+ var h1 = v1.GetHashCode();
+ var h2 = v2.GetHashCode();
+
+ Assert.NotEqual(h1, h2);
+ }
+
+ [Fact]
+ public void TestStringConversion()
+ {
+ SemVersion v = "1.0.0";
+ Assert.Equal(1, v.Major);
+ }
+
+ [Fact]
+ public void TestUntypedCompareTo()
+ {
+ var v1 = new SemVersion(1);
+ var c = v1.CompareTo((object)v1);
+
+ Assert.Equal(0, c);
+ }
+
+ [Fact]
+ public void StaticEqualsTest1()
+ {
+ var v1 = new SemVersion(1, 2, 3);
+ var v2 = new SemVersion(1, 2, 3);
+
+ var r = SemVersion.Equals(v1, v2);
+ Assert.True(r);
+ }
+
+ [Fact]
+ public void StaticEqualsTest2()
+ {
+ var r = SemVersion.Equals(null, null);
+ Assert.True(r);
+ }
+
+ [Fact]
+ public void StaticEqualsTest3()
+ {
+ var v1 = new SemVersion(1);
+
+ var r = SemVersion.Equals(v1, null);
+ Assert.False(r);
+ }
+
+ [Fact]
+ public void StaticCompareTest1()
+ {
+ var v1 = new SemVersion(1);
+ var v2 = new SemVersion(2);
+
+ var r = SemVersion.Compare(v1, v2);
+ Assert.Equal(-1, r);
+ }
+
+ [Fact]
+ public void StaticCompareTest2()
+ {
+ var v1 = new SemVersion(1);
+
+ var r = SemVersion.Compare(v1, null);
+ Assert.Equal(1, r);
+ }
+
+ [Fact]
+ public void StaticCompareTest3()
+ {
+ var v1 = new SemVersion(1);
+
+ var r = SemVersion.Compare(null, v1);
+ Assert.Equal(-1, r);
+ }
+
+ [Fact]
+ public void StaticCompareTest4()
+ {
+ var r = SemVersion.Compare(null, null);
+ Assert.Equal(0, r);
+ }
+
+ [Fact]
+ public void EqualsOperatorTest()
+ {
+ var v1 = new SemVersion(1);
+ var v2 = new SemVersion(1);
+
+ var r = v1 == v2;
+ Assert.True(r);
+ }
+
+ [Fact]
+ public void UnequalOperatorTest()
+ {
+ var v1 = new SemVersion(1);
+ var v2 = new SemVersion(2);
+
+ var r = v1 != v2;
+ Assert.True(r);
+ }
+
+ [Fact]
+ public void GreaterOperatorTest()
+ {
+ var v1 = new SemVersion(1);
+ var v2 = new SemVersion(2);
+
+ var r = v2 > v1;
+ Assert.True(r);
+ }
+
+ [Fact]
+ public void GreaterOperatorTest2()
+ {
+ var v1 = new SemVersion(1, 0, 0, "alpha");
+ var v2 = new SemVersion(1, 0, 0, "rc");
+
+ var r = v2 > v1;
+ Assert.True(r);
+ }
+
+ [Fact]
+ public void GreaterOperatorTest3()
+ {
+ var v1 = new SemVersion(1, 0, 0, "-ci.1");
+ var v2 = new SemVersion(1, 0, 0, "alpha");
+
+ var r = v2 > v1;
+ Assert.True(r);
+ }
+
+ [Fact]
+ public void GreaterOrEqualOperatorTest1()
+ {
+ var v1 = new SemVersion(1);
+ var v2 = new SemVersion(1);
+
+ var r = v1 >= v2;
+ Assert.True(r);
+ }
+
+ [Fact]
+ public void GreaterOrEqualOperatorTest2()
+ {
+ var v1 = new SemVersion(2);
+ var v2 = new SemVersion(1);
+
+ var r = v1 >= v2;
+ Assert.True(r);
+ }
+
+ [Fact]
+ public void LessOperatorTest()
+ {
+ var v1 = new SemVersion(1);
+ var v2 = new SemVersion(2);
+
+ var r = v1 < v2;
+ Assert.True(r);
+ }
+
+ [Fact]
+ public void LessOperatorTest2()
+ {
+ var v1 = new SemVersion(1, 0, 0, "alpha");
+ var v2 = new SemVersion(1, 0, 0, "rc");
+
+ var r = v1 < v2;
+ Assert.True(r);
+ }
+
+ [Fact]
+ public void LessOperatorTest3()
+ {
+ var v1 = new SemVersion(1, 0, 0, "-ci.1");
+ var v2 = new SemVersion(1, 0, 0, "alpha");
+
+ var r = v1 < v2;
+ Assert.True(r);
+ }
+
+ [Fact]
+ public void LessOrEqualOperatorTest1()
+ {
+ var v1 = new SemVersion(1);
+ var v2 = new SemVersion(1);
+
+ var r = v1 <= v2;
+ Assert.True(r);
+ }
+
+ [Fact]
+ public void LessOrEqualOperatorTest2()
+ {
+ var v1 = new SemVersion(1);
+ var v2 = new SemVersion(2);
+
+ var r = v1 <= v2;
+ Assert.True(r);
+ }
+
+ [Fact]
+ public void TestChangeMajor()
+ {
+ var v1 = new SemVersion(1, 2, 3, "alpha", "dev");
+ var v2 = v1.Change(major: 5);
+
+ Assert.Equal(5, v2.Major);
+ Assert.Equal(2, v2.Minor);
+ Assert.Equal(3, v2.Patch);
+ Assert.Equal("alpha", v2.Prerelease);
+ Assert.Equal("dev", v2.Build);
+ }
+
+ [Fact]
+ public void TestChangeMinor()
+ {
+ var v1 = new SemVersion(1, 2, 3, "alpha", "dev");
+ var v2 = v1.Change(minor: 5);
+
+ Assert.Equal(1, v2.Major);
+ Assert.Equal(5, v2.Minor);
+ Assert.Equal(3, v2.Patch);
+ Assert.Equal("alpha", v2.Prerelease);
+ Assert.Equal("dev", v2.Build);
+ }
+
+ [Fact]
+ public void TestChangePatch()
+ {
+ var v1 = new SemVersion(1, 2, 3, "alpha", "dev");
+ var v2 = v1.Change(patch: 5);
+
+ Assert.Equal(1, v2.Major);
+ Assert.Equal(2, v2.Minor);
+ Assert.Equal(5, v2.Patch);
+ Assert.Equal("alpha", v2.Prerelease);
+ Assert.Equal("dev", v2.Build);
+ }
+
+ [Fact]
+ public void TestChangePrerelease()
+ {
+ var v1 = new SemVersion(1, 2, 3, "alpha", "dev");
+ var v2 = v1.Change(prerelease: "beta");
+
+ Assert.Equal(1, v2.Major);
+ Assert.Equal(2, v2.Minor);
+ Assert.Equal(3, v2.Patch);
+ Assert.Equal("beta", v2.Prerelease);
+ Assert.Equal("dev", v2.Build);
+ }
+
+#if !NETSTANDARD
+ [Fact]
+ public void TestSerialization()
+ {
+ var semVer = new SemVersion(1, 2, 3, "alpha", "dev");
+ SemVersion semVerSerializedDeserialized;
+ using (var ms = new MemoryStream())
+ {
+ var bf = new BinaryFormatter();
+ bf.Serialize(ms, semVer);
+ ms.Position = 0;
+ semVerSerializedDeserialized = (SemVersion) bf.Deserialize(ms);
+ }
+ Assert.Equal(semVer, semVerSerializedDeserialized);
+ }
+#endif
+ }
+}
\ No newline at end of file
diff --git a/test/Semver.Test/Semver.Test.xproj b/test/Semver.Test/Semver.Test.xproj
new file mode 100644
index 0000000..469a42d
--- /dev/null
+++ b/test/Semver.Test/Semver.Test.xproj
@@ -0,0 +1,21 @@
+
+
+
+ 14.0
+ $(MSBuildExtensionsPath32)\Microsoft\VisualStudio\v$(VisualStudioVersion)
+
+
+
+ da03e4c4-cb6c-447b-b617-15b5689e9029
+ Semver.Test
+ .\obj
+ .\bin\
+
+
+ 2.0
+
+
+
+
+
+
\ No newline at end of file
diff --git a/test/Semver.Test/project.json b/test/Semver.Test/project.json
new file mode 100644
index 0000000..5ecec7c
--- /dev/null
+++ b/test/Semver.Test/project.json
@@ -0,0 +1,44 @@
+{
+ "testRunner": "xunit",
+ "buildOptions": {
+ "debugType": "portable",
+ "warningsAsErrors": true,
+ "copyToOutput": {
+ "include": [ "xunit.runner.json" ]
+ }
+ },
+ "dependencies": {
+ "dotnet-test-xunit": "2.2.0-preview2-build1029",
+ "Semver": {
+ "target": "project"
+ },
+ "xunit": "2.2.0-beta2-build3300",
+ "xunit.extensibility.core": "2.2.0-beta2-build3300",
+ "xunit.extensibility.execution": "2.2.0-beta2-build3300",
+ "xunit.runner.visualstudio": "2.2.0-beta2-build1149"
+ },
+ "frameworks": {
+ "netcoreapp1.0": {
+ "buildOptions": {
+ "define": [ "NETSTANDARD", "NETSTANDARD1_5" ]
+ },
+ "dependencies": {
+ "Microsoft.NETCore.App": {
+ "type": "platform",
+ "version": "1.0.0"
+ },
+ "System.Runtime": "4.1.0"
+ }
+ },
+ "NET46": {
+ "buildOptions": {
+ "define": [ "NET46" ]
+ },
+ "frameworkAssemblies": {
+ "System.Runtime": {
+ "type": "build"
+ }
+ }
+ }
+ }
+}
\ No newline at end of file
diff --git a/test/Semver.Test/xunit.runner.json b/test/Semver.Test/xunit.runner.json
new file mode 100644
index 0000000..1b40892
--- /dev/null
+++ b/test/Semver.Test/xunit.runner.json
@@ -0,0 +1,7 @@
+{
+ "diagnosticMessages": true,
+ "maxParallelThreads": 1,
+ "methodDisplay": "method",
+ "parallelizeAssembly": false,
+ "parallelizetestcollections": false
+}