Skip to content

Commit 33b5bfb

Browse files
authored
Add Ulid.Empty field and corresponding tests (#8)
Introduce a static readonly field `Ulid.Empty` in the `Ulid` struct to represent an empty ULID value. This field serves as a default or placeholder. A new test method `EmptyUlid_ShouldBeDefault` is added to ensure `Ulid.Empty` behaves as expected, confirming it equals the default ULID and has a byte array of all zeros. Documentation comments are included to clarify the purpose of the `Ulid.Empty` field.
1 parent 2a934f0 commit 33b5bfb

File tree

3 files changed

+22
-0
lines changed

3 files changed

+22
-0
lines changed

README.md

Lines changed: 2 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -142,6 +142,8 @@ Gets the timestamp component of the ULID as a `DateTimeOffset`.
142142
Gets the time component of the ULID as a `ReadOnlySpan<byte>`.
143143
- `.Random`\
144144
Gets the random component of the ULID as a `ReadOnlySpan<byte>`.
145+
- `Ulid.Empty`\
146+
Represents an empty ULID, equivalent to `default(Ulid)` and `Ulid.New(new byte[16])`.
145147

146148
### Conversion Methods
147149

src/ByteAether.Ulid.Tests/Ulid.Tests.cs

Lines changed: 11 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -3,6 +3,17 @@
33
namespace ByteAether.Ulid.Tests;
44
public class UlidTests
55
{
6+
[Fact]
7+
public void EmptyUlid_ShouldBeDefault()
8+
{
9+
// Arrange
10+
var ulid = Ulid.Empty;
11+
12+
// Assert
13+
Assert.Equal(default, ulid);
14+
Assert.Equal(new byte[16], ulid.ToByteArray());
15+
}
16+
617
private static readonly byte[] _sampleUlidBytes =
718
[
819
// Timestamp (6 bytes)

src/ByteAether.Ulid/Ulid.cs

Lines changed: 9 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -26,6 +26,15 @@ public readonly partial struct Ulid
2626
private const byte _ulidSizeRandom = 10;
2727
private const byte _ulidSize = _ulidSizeTime + _ulidSizeRandom;
2828

29+
/// <summary>
30+
/// Represents an empty ULID value.
31+
/// </summary>
32+
/// <remarks>
33+
/// The <see cref="Empty"/> field is a ULID with all components set to zero.
34+
/// It can be used as a default or placeholder value.
35+
/// </remarks>
36+
public static readonly Ulid Empty = default;
37+
2938
[FieldOffset(00)] private readonly byte _t0;
3039
[FieldOffset(01)] private readonly byte _t1;
3140
[FieldOffset(02)] private readonly byte _t2;

0 commit comments

Comments
 (0)