Skip to content

Commit

Permalink
Update OsBrandStringHelper
Browse files Browse the repository at this point in the history
  • Loading branch information
AndreyAkinshin committed Aug 4, 2021
1 parent 4bd433d commit 8cb701c
Show file tree
Hide file tree
Showing 2 changed files with 10 additions and 4 deletions.
13 changes: 9 additions & 4 deletions src/BenchmarkDotNet/Environments/OsBrandStringHelper.cs
Expand Up @@ -98,7 +98,8 @@ public class OsBrandStringHelper
{ "10.0.18363", "10 19H2 [1909, November 2019 Update]" },
{ "10.0.19041", "10 20H1 [2004, May 2020 Update]" },
{ "10.0.19042", "10 20H2 [20H2, October 2020 Update]" },
{ "10.0.19043", "10 21H1 [21H1, May 2021 Update]" }
{ "10.0.19043", "10 21H1 [21H1, May 2021 Update]" },
{ "10.0.19044", "10 21H2 [21H2]" }
};

private class Windows10Version
Expand All @@ -122,13 +123,15 @@ private Windows10Version(string version, [NotNull] string codeName, [NotNull] st
private string ToFullVersion([CanBeNull] int? ubr = null)
=> ubr == null ? $"10.0.{BuildNumber}" : $"10.0.{BuildNumber}.{ubr}";

private static string Collapse(params string[] values) => string.Join("/", values.Where(v => !string.IsNullOrEmpty(v)));

// The line with OsBrandString is one of the longest lines in the summary.
// When people past in on GitHub, it can be a reason of an ugly horizontal scrollbar.
// To avoid this, we are trying to minimize this line and use the minimum possible number of characters.
public string ToPrettifiedString([CanBeNull] int? ubr)
=> Version == ShortifiedCodeName
? $"{ToFullVersion(ubr)} ({Version}/{ShortifiedMarketingName})"
: $"{ToFullVersion(ubr)} ({Version}/{ShortifiedMarketingName}/{ShortifiedCodeName})";
? $"{ToFullVersion(ubr)} ({Collapse(Version, ShortifiedMarketingName)})"
: $"{ToFullVersion(ubr)} ({Collapse(Version, ShortifiedMarketingName, ShortifiedCodeName)})";

// See https://en.wikipedia.org/wiki/Windows_10_version_history
private static readonly List<Windows10Version> WellKnownVersions = new List<Windows10Version>
Expand All @@ -145,6 +148,7 @@ public string ToPrettifiedString([CanBeNull] int? ubr)
new Windows10Version("2004", "20H1", "May 2020 Update", 19041),
new Windows10Version("20H2", "20H2", "October 2020 Update", 19042),
new Windows10Version("21H1", "21H1", "May 2021 Update", 19043),
new Windows10Version("21H2", "21H2", "", 19044), // The markingName is not announced yet
};

[CanBeNull]
Expand Down Expand Up @@ -209,7 +213,8 @@ private MacOSXVersion(int darwinVersion, [NotNull] string codeName)
new MacOSXVersion(17, "High Sierra"),
new MacOSXVersion(18, "Mojave"),
new MacOSXVersion(19, "Catalina"),
new MacOSXVersion(20, "Big Sur")
new MacOSXVersion(20, "Big Sur"),
new MacOSXVersion(21, "Monterey")
};

[CanBeNull]
Expand Down
Expand Up @@ -44,6 +44,7 @@ public void WindowsIsPrettified(string originalVersion, string prettifiedName)
[InlineData("10.0.19041", 1, "Windows 10.0.19041.1 (2004/May2020Update/20H1)")]
[InlineData("10.0.19042", 746, "Windows 10.0.19042.746 (20H2/October2020Update)")]
[InlineData("10.0.19043", 964, "Windows 10.0.19043.964 (21H1/May2021Update)")]
[InlineData("10.0.19044", 1147, "Windows 10.0.19044.1147 (21H2)")]
public void WindowsWithUbrIsPrettified(string originalVersion, int ubr, string prettifiedName)
=> Check(OsBrandStringHelper.Prettify("Windows", originalVersion, ubr), prettifiedName);

Expand Down

0 comments on commit 8cb701c

Please sign in to comment.