mirror of
https://github.com/AssetRipper/AssetRipper.Primitives.git
synced 2026-11-13 04:26:30 -10:00
Compare commits
| Author | SHA1 | Date | |
|---|---|---|---|
|
|
4bcc823371 | ||
|
|
7630da6da0 | ||
|
|
e5802e39ee | ||
|
|
c663c68124 | ||
|
|
fa2458cfae | ||
|
|
ee923d8e9b | ||
|
|
8b23a0c671 | ||
|
|
f56feaf217 |
No files matched your search
@@ -9,14 +9,14 @@
|
||||
</PropertyGroup>
|
||||
|
||||
<ItemGroup>
|
||||
<PackageReference Include="Microsoft.NET.Test.Sdk" Version="17.8.0" />
|
||||
<PackageReference Include="Microsoft.NET.Test.Sdk" Version="17.9.0" />
|
||||
<PackageReference Include="NUnit" Version="3.14.0" />
|
||||
<PackageReference Include="NUnit3TestAdapter" Version="4.5.0" />
|
||||
<PackageReference Include="NUnit.Analyzers" Version="3.10.0">
|
||||
<PackageReference Include="NUnit.Analyzers" Version="4.1.0">
|
||||
<PrivateAssets>all</PrivateAssets>
|
||||
<IncludeAssets>runtime; build; native; contentfiles; analyzers; buildtransitive</IncludeAssets>
|
||||
</PackageReference>
|
||||
<PackageReference Include="coverlet.collector" Version="6.0.0" />
|
||||
<PackageReference Include="coverlet.collector" Version="6.0.2" />
|
||||
</ItemGroup>
|
||||
|
||||
<ItemGroup>
|
||||
|
||||
@@ -72,20 +72,4 @@ public class ComparisonTests
|
||||
Assert.That(new UnityVersion(2019, 1, 0, UnityVersionType.Final, 1).LessThanOrEquals(2019, 1, 0));
|
||||
});
|
||||
}
|
||||
|
||||
[TestCase(2017)]
|
||||
[TestCase(2018)]
|
||||
[TestCase(2019)]
|
||||
[TestCase(2020)]
|
||||
[TestCase(2021)]
|
||||
[TestCase(2022)]
|
||||
[TestCase(2023)]
|
||||
public void YearVersioningIsBetweenFiveAndSix(int year)
|
||||
{
|
||||
Assert.Multiple(() =>
|
||||
{
|
||||
Assert.That(new UnityVersion((ushort)year).GreaterThan(5));
|
||||
Assert.That(new UnityVersion((ushort)year).LessThan(6));
|
||||
});
|
||||
}
|
||||
}
|
||||
@@ -9,8 +9,13 @@ public class ParsingTests
|
||||
[TestCase("4.2.2f1\n1", 4, 2, 2, UnityVersionType.Final, 1, "\n1", "Custom Unity 4 Version")]
|
||||
[TestCase("2343.4.5f7", 2343, 4, 5, UnityVersionType.Final, 7, null, "Fictitious Future Version")]
|
||||
[TestCase("2019.2.2f1c2\n2", 2019, 2, 2, UnityVersionType.China, 2, "\n2", "Fake Custom Chinese Version")]
|
||||
[TestCase("2019", 2019, 0, 0, UnityVersionType.Final, 1, null, "Major Only")]
|
||||
[TestCase("2019.4", 2019, 4, 0, UnityVersionType.Final, 1, null, "Major Minor Only")]
|
||||
[TestCase("2019.4.3", 2019, 4, 3, UnityVersionType.Final, 1, null, "Major Minor Build Only")]
|
||||
[TestCase("0", 0, 0, 0, UnityVersionType.Alpha, 0, null, "Zero, Major Only")]
|
||||
[TestCase("0.0", 0, 0, 0, UnityVersionType.Alpha, 0, null, "Zero, Major Minor Only")]
|
||||
[TestCase("0.0.0", 0, 0, 0, UnityVersionType.Alpha, 0, null, "Zero, Major Minor Build Only")]
|
||||
[TestCase("0.0.0b2", 0, 0, 0, UnityVersionType.Beta, 2, null, "Zero, Full")]
|
||||
[TestCase("2019.2.2f1-letters", 2019, 2, 2, UnityVersionType.Final, 1, "-letters", "Issue #40 - Appended Custom Characters")]
|
||||
public void UnityVersionParsesCorrectly(string versionString, int major, int minor, int build, UnityVersionType type, int typeNumber, string? customEngine, string name)
|
||||
{
|
||||
@@ -20,7 +25,7 @@ public class ParsingTests
|
||||
{
|
||||
Assert.That(parsedCustomEngine, Is.EqualTo(customEngine), $"The custom engine boolean is incorrect for '{name}'");
|
||||
Assert.That(parsedVersion, Is.EqualTo(expected), $"The parsed version is incorrect for '{name}'");
|
||||
if (customEngine is not null || typeNumber is not 1)
|
||||
if (customEngine is not null || typeNumber is not 0 and not 1)
|
||||
{
|
||||
Assert.That(parsedVersion.ToString(UnityVersionFormatFlags.Default, parsedCustomEngine ?? ""), Is.EqualTo(versionString));
|
||||
}
|
||||
|
||||
@@ -6,7 +6,7 @@
|
||||
<Nullable>enable</Nullable>
|
||||
<Authors>ds5678</Authors>
|
||||
<Company>AssetRipper</Company>
|
||||
<Version>2.1.1</Version>
|
||||
<Version>3.1.0</Version>
|
||||
<AssemblyVersion>$(Version)</AssemblyVersion>
|
||||
<PackageId>AssetRipper.Primitives</PackageId>
|
||||
<PackageTags>C# assetripper unity unity3d</PackageTags>
|
||||
|
||||
@@ -27,47 +27,7 @@ public readonly partial struct UnityVersion : IEquatable<UnityVersion>, ICompara
|
||||
/// </returns>
|
||||
public int CompareTo(UnityVersion other)
|
||||
{
|
||||
//Unity 6 is sequentially equivalent to Unity 2024 because
|
||||
//they switched to back to the old versioning scheme.
|
||||
const ushort FirstNewVersion = 6;
|
||||
|
||||
if (this == other)
|
||||
{
|
||||
return 0;
|
||||
}
|
||||
|
||||
if (UsesYearNumbering(this))
|
||||
{
|
||||
if (UsesYearNumbering(other))
|
||||
{
|
||||
return CompareByData(this, other);
|
||||
}
|
||||
else
|
||||
{
|
||||
return other.Major < FirstNewVersion ? 1 : -1;
|
||||
}
|
||||
}
|
||||
else
|
||||
{
|
||||
if (UsesYearNumbering(other))
|
||||
{
|
||||
return Major < FirstNewVersion ? -1 : 1;
|
||||
}
|
||||
else
|
||||
{
|
||||
return CompareByData(this, other);
|
||||
}
|
||||
}
|
||||
|
||||
static int CompareByData(UnityVersion x, UnityVersion y)
|
||||
{
|
||||
return x.m_data < y.m_data ? -1 : 1;
|
||||
}
|
||||
|
||||
static bool UsesYearNumbering(UnityVersion version)
|
||||
{
|
||||
return version.Major is >= 2017 and <= 2023;
|
||||
}
|
||||
return m_data.CompareTo(other.m_data);
|
||||
}
|
||||
|
||||
/// <summary>
|
||||
@@ -90,6 +50,6 @@ public readonly partial struct UnityVersion : IEquatable<UnityVersion>, ICompara
|
||||
/// <inheritdoc/>
|
||||
public override int GetHashCode()
|
||||
{
|
||||
return unchecked(827 + 911 * m_data.GetHashCode());
|
||||
return m_data.GetHashCode();
|
||||
}
|
||||
}
|
||||
@@ -32,7 +32,7 @@ public readonly partial struct UnityVersion
|
||||
/// <returns></returns>
|
||||
public static bool operator >(UnityVersion left, UnityVersion right)
|
||||
{
|
||||
return left.CompareTo(right) > 0;
|
||||
return left.m_data > right.m_data;
|
||||
}
|
||||
|
||||
/// <summary>
|
||||
@@ -43,7 +43,7 @@ public readonly partial struct UnityVersion
|
||||
/// <returns></returns>
|
||||
public static bool operator >=(UnityVersion left, UnityVersion right)
|
||||
{
|
||||
return left.CompareTo(right) >= 0;
|
||||
return left.m_data >= right.m_data;
|
||||
}
|
||||
|
||||
/// <summary>
|
||||
@@ -54,7 +54,7 @@ public readonly partial struct UnityVersion
|
||||
/// <returns></returns>
|
||||
public static bool operator <(UnityVersion left, UnityVersion right)
|
||||
{
|
||||
return left.CompareTo(right) < 0;
|
||||
return left.m_data < right.m_data;
|
||||
}
|
||||
|
||||
/// <summary>
|
||||
@@ -65,6 +65,6 @@ public readonly partial struct UnityVersion
|
||||
/// <returns></returns>
|
||||
public static bool operator <=(UnityVersion left, UnityVersion right)
|
||||
{
|
||||
return left.CompareTo(right) <= 0;
|
||||
return left.m_data <= right.m_data;
|
||||
}
|
||||
}
|
||||
@@ -5,6 +5,7 @@ namespace AssetRipper.Primitives;
|
||||
|
||||
public readonly partial struct UnityVersion
|
||||
{
|
||||
private static readonly Regex majorRegex = new Regex(@"^([0-9]+)$", RegexOptions.Compiled);
|
||||
private static readonly Regex majorMinorRegex = new Regex(@"^([0-9]+)\.([0-9]+)$", RegexOptions.Compiled);
|
||||
private static readonly Regex majorMinorBuildRegex = new Regex(@"^([0-9]+)\.([0-9]+)\.([0-9]+)$", RegexOptions.Compiled);
|
||||
private static readonly Regex normalRegex = new Regex(@"^([0-9]+)\.([0-9]+)\.([0-9]+)\.?([abcfpx])([0-9]+)((?:.|[\r\n])+)?$", RegexOptions.Compiled);
|
||||
@@ -125,7 +126,9 @@ public readonly partial struct UnityVersion
|
||||
int minor = int.Parse(match.Groups[2].Value);
|
||||
int build = int.Parse(match.Groups[3].Value);
|
||||
customEngine = null;
|
||||
version = new UnityVersion((ushort)major, (ushort)minor, (ushort)build, UnityVersionType.Final, 1);
|
||||
version = major is not 0 || minor is not 0 || build is not 0
|
||||
? new UnityVersion((ushort)major, (ushort)minor, (ushort)build, UnityVersionType.Final, 1)
|
||||
: default;
|
||||
return true;
|
||||
}
|
||||
else if (majorMinorRegex.TryMatch(s, out match))
|
||||
@@ -133,7 +136,18 @@ public readonly partial struct UnityVersion
|
||||
int major = int.Parse(match.Groups[1].Value);
|
||||
int minor = int.Parse(match.Groups[2].Value);
|
||||
customEngine = null;
|
||||
version = new UnityVersion((ushort)major, (ushort)minor, 0, UnityVersionType.Final, 1);
|
||||
version = major is not 0 || minor is not 0
|
||||
? new UnityVersion((ushort)major, (ushort)minor, 0, UnityVersionType.Final, 1)
|
||||
: default;
|
||||
return true;
|
||||
}
|
||||
else if (majorRegex.TryMatch(s, out match))
|
||||
{
|
||||
int major = int.Parse(match.Groups[1].Value);
|
||||
customEngine = null;
|
||||
version = major is not 0
|
||||
? new UnityVersion((ushort)major, 0, 0, UnityVersionType.Final, 1)
|
||||
: default;
|
||||
return true;
|
||||
}
|
||||
else
|
||||
|
||||
Reference in new issue
Block a user