Skip to content

Commit

Permalink
Support optional PreRelease
Browse files Browse the repository at this point in the history
  • Loading branch information
emlautarom1 committed Oct 31, 2024
1 parent 9bb9486 commit 728446c
Show file tree
Hide file tree
Showing 2 changed files with 17 additions and 2 deletions.
Original file line number Diff line number Diff line change
Expand Up @@ -129,6 +129,21 @@ public void OptimismProtocolVersion_Throws_Unknown_Version(byte version)
read.Should().Throw<OptimismProtocolVersion.ParseException>();
}


private static IEnumerable<(string, OptimismProtocolVersion.V0)> V0FromStringCases()
{
yield return ("3.1.0", new(new byte[8], 3, 1, 0, 0));
yield return ("1.1.1", new(new byte[8], 1, 1, 1, 0));
yield return ("1.1.1.16", new(new byte[8], 1, 1, 1, 16));
yield return ("1.26.0.4", new(new byte[8], 1, 26, 0, 4));
}
[TestCaseSource(nameof(V0FromStringCases))]
public void OptimismProtocolVersionV0_FromStringVersion((string Version, OptimismProtocolVersion.V0 Expected) testCase)
{
var actual = new OptimismProtocolVersion.V0(testCase.Version);
actual.Should().Be(testCase.Expected);
}

[Test]
public void OptimismProtocolVersionV0_FromProductInfoVersion()
{
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -71,13 +71,13 @@ public V0(ReadOnlySpan<byte> build, string version)
if (build.Length != 8) throw new ArgumentException($"Expected build identifier to be 8 bytes long, got {build.Length}", nameof(build));

var parts = version.Split('.').Select(uint.Parse).ToList();
if (parts.Count != 4) throw new ArgumentException($"Invalid version format '{version}'", nameof(version));
if (parts.Count is < 3 or > 4) throw new ArgumentException($"Invalid version format '{version}'", nameof(version));

Build = build.ToArray();
Major = parts[0];
Minor = parts[1];
Patch = parts[2];
PreRelease = parts[3];
PreRelease = parts.Count == 4 ? parts[3] : 0;
}

public V0(string version) : this(new byte[8], version) { }
Expand Down

0 comments on commit 728446c

Please sign in to comment.