mirror of
https://github.com/microsoft/PowerToys.git
synced 2026-04-05 02:36:19 +02:00
[PTRun][ValueGenerator]Add support for UUIDv7 (#35757)
* add Run support for UUIDv7 generation * simplify comments and maybe satisfy spell check * fix endianess * prefer stack allocation for temporary fixed-size buffer * perhaps the async test caused the pipeline to hang * switch to .NET 9 BCL implementation of UUIDv7 * add UUIDv7 to input query suggestions + update exception messages to include v7 * simplify Guid description switch + update devdocs
This commit is contained in:
@@ -3,8 +3,9 @@
|
||||
// See the LICENSE file in the project root for more information.
|
||||
|
||||
using System;
|
||||
using System.Buffers.Binary;
|
||||
using System.Linq;
|
||||
|
||||
using System.Threading;
|
||||
using Microsoft.VisualStudio.TestTools.UnitTesting;
|
||||
|
||||
namespace Community.PowerToys.Run.Plugin.ValueGenerator.UnitTests
|
||||
@@ -56,6 +57,39 @@ namespace Community.PowerToys.Run.Plugin.ValueGenerator.UnitTests
|
||||
Assert.AreEqual(0x5000, GetGUIDVersion(guid));
|
||||
}
|
||||
|
||||
[TestMethod]
|
||||
public void GUIDv7Generator()
|
||||
{
|
||||
var guidRequest = new GUID.GUIDRequest(7);
|
||||
guidRequest.Compute();
|
||||
var guid = guidRequest.Result;
|
||||
|
||||
Assert.IsNotNull(guid);
|
||||
Assert.AreEqual(0x7000, GetGUIDVersion(guid));
|
||||
}
|
||||
|
||||
[TestMethod]
|
||||
public void GUIDv7GeneratorTimeOrdered()
|
||||
{
|
||||
const int numberOfSamplesToCheck = 10;
|
||||
ulong previousTimestampWithTrailingRandomData = 0uL;
|
||||
for (int i = 0; i < numberOfSamplesToCheck; i++)
|
||||
{
|
||||
var guidRequest = new GUID.GUIDRequest(7);
|
||||
guidRequest.Compute();
|
||||
var guid = guidRequest.Result;
|
||||
|
||||
// can't hurt to assert invariants again
|
||||
Assert.IsNotNull(guid);
|
||||
Assert.AreEqual(0x7000, GetGUIDVersion(guid));
|
||||
ulong timestampWithTrailingRandomData = BinaryPrimitives.ReadUInt64BigEndian(guid.AsSpan());
|
||||
Assert.IsTrue(timestampWithTrailingRandomData > previousTimestampWithTrailingRandomData, "UUIDv7 wasn't time-ordered");
|
||||
|
||||
// ensure at least one millisecond passes for consistent time-ordering. we wait 10 ms just to be sure.
|
||||
Thread.Sleep(10);
|
||||
}
|
||||
}
|
||||
|
||||
[DataTestMethod]
|
||||
[DataRow(3, "ns:DNS", "abc", "5bd670ce-29c8-3369-a8a1-10ce44c7259e")]
|
||||
[DataRow(3, "ns:URL", "abc", "874a8cb4-4e91-3055-a476-3d3e2ffe375f")]
|
||||
|
||||
@@ -12,7 +12,7 @@ using Wox.Plugin;
|
||||
namespace Community.PowerToys.Run.Plugin.ValueGenerator.UnitTests
|
||||
{
|
||||
[TestClass]
|
||||
public class InputParserTests
|
||||
public partial class InputParserTests
|
||||
{
|
||||
[DataTestMethod]
|
||||
[DataRow("md5 abc", typeof(Hashing.HashRequest))]
|
||||
@@ -27,6 +27,8 @@ namespace Community.PowerToys.Run.Plugin.ValueGenerator.UnitTests
|
||||
[DataRow("uUiD5 ns:URL abc", typeof(GUID.GUIDRequest))]
|
||||
[DataRow("Guidvv ns:DNS abc", null)]
|
||||
[DataRow("guidv4", typeof(GUID.GUIDRequest))]
|
||||
[DataRow("guidv7", typeof(GUID.GUIDRequest))]
|
||||
[DataRow("GUIDv7", typeof(GUID.GUIDRequest))]
|
||||
[DataRow("base64 abc", typeof(Base64.Base64Request))]
|
||||
[DataRow("base99 abc", null)]
|
||||
[DataRow("base64s abc", null)]
|
||||
@@ -90,25 +92,22 @@ namespace Community.PowerToys.Run.Plugin.ValueGenerator.UnitTests
|
||||
|
||||
private static bool CommandIsKnown(string command)
|
||||
{
|
||||
string[] hashes = new string[] { "md5", "sha1", "sha256", "sha384", "sha512", "base64", "base64d" };
|
||||
string[] hashes = ["md5", "sha1", "sha256", "sha384", "sha512", "base64", "base64d"];
|
||||
if (hashes.Contains(command.ToLowerInvariant()))
|
||||
{
|
||||
return true;
|
||||
}
|
||||
|
||||
Regex regexGuiUUID = new Regex("^(guid|uuid)([1345]{0,1}|v[1345]{1})$", RegexOptions.IgnoreCase | RegexOptions.Compiled);
|
||||
if (regexGuiUUID.IsMatch(command))
|
||||
if (GetKnownUuidImplementations().IsMatch(command))
|
||||
{
|
||||
return true;
|
||||
}
|
||||
|
||||
string[] uriCommands = new string[] { "url", "urld", "esc:hex", "uesc:hex", "esc:data", "uesc:data" };
|
||||
if (uriCommands.Contains(command.ToLowerInvariant()))
|
||||
{
|
||||
return true;
|
||||
}
|
||||
|
||||
return false;
|
||||
string[] uriCommands = ["url", "urld", "esc:hex", "uesc:hex", "esc:data", "uesc:data"];
|
||||
return uriCommands.Contains(command.ToLowerInvariant());
|
||||
}
|
||||
|
||||
[GeneratedRegex("^(guid|uuid)([13457]{0,1}|v[13457]{1})$", RegexOptions.IgnoreCase | RegexOptions.Compiled, "en-US")]
|
||||
private static partial Regex GetKnownUuidImplementations();
|
||||
}
|
||||
}
|
||||
|
||||
Reference in New Issue
Block a user