Skip to content
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
4 changes: 2 additions & 2 deletions src/CalendarVersioning/CalendarVersion.cs
Original file line number Diff line number Diff line change
Expand Up @@ -57,7 +57,7 @@

if (format == null)
{
var parts = input.Split('.', 5);

Check failure on line 60 in src/CalendarVersioning/CalendarVersion.cs

View workflow job for this annotation

GitHub Actions / build-and-test

A local or parameter named 'parts' cannot be declared in this scope because that name is used in an enclosing local scope to define a local or parameter

Check failure on line 60 in src/CalendarVersioning/CalendarVersion.cs

View workflow job for this annotation

GitHub Actions / build-and-test

A local or parameter named 'parts' cannot be declared in this scope because that name is used in an enclosing local scope to define a local or parameter

Check failure on line 60 in src/CalendarVersioning/CalendarVersion.cs

View workflow job for this annotation

GitHub Actions / build-and-test

A local or parameter named 'parts' cannot be declared in this scope because that name is used in an enclosing local scope to define a local or parameter

Check failure on line 60 in src/CalendarVersioning/CalendarVersion.cs

View workflow job for this annotation

GitHub Actions / build-and-test

A local or parameter named 'parts' cannot be declared in this scope because that name is used in an enclosing local scope to define a local or parameter

// Default parsing: YYYY.MM[.DD[.Minor]]
if (parts.Length is < 2 or > 4)
Expand All @@ -81,7 +81,7 @@
for (int i = 0; i < tokens.Length; i++)
{
var token = tokens[i];
var value = int.Parse(parts[i]);
var value = int.Parse(formatParts[i]);

Check failure on line 84 in src/CalendarVersioning/CalendarVersion.cs

View workflow job for this annotation

GitHub Actions / build-and-test

The name 'formatParts' does not exist in the current context

Check failure on line 84 in src/CalendarVersioning/CalendarVersion.cs

View workflow job for this annotation

GitHub Actions / build-and-test

The name 'formatParts' does not exist in the current context

Check failure on line 84 in src/CalendarVersioning/CalendarVersion.cs

View workflow job for this annotation

GitHub Actions / build-and-test

The name 'formatParts' does not exist in the current context

Check failure on line 84 in src/CalendarVersioning/CalendarVersion.cs

View workflow job for this annotation

GitHub Actions / build-and-test

The name 'formatParts' does not exist in the current context

switch (token)
{
Expand All @@ -90,7 +90,7 @@
break;
case "YY":
if (value is < 0 or > 99)
throw new FormatException($"Invalid YY value '{parts[i]}' in version string '{input}'");
throw new FormatException($"Invalid YY value '{formatParts[i]}' in version string '{input}'");

Check failure on line 93 in src/CalendarVersioning/CalendarVersion.cs

View workflow job for this annotation

GitHub Actions / build-and-test

The name 'formatParts' does not exist in the current context

Check failure on line 93 in src/CalendarVersioning/CalendarVersion.cs

View workflow job for this annotation

GitHub Actions / build-and-test

The name 'formatParts' does not exist in the current context

Check failure on line 93 in src/CalendarVersioning/CalendarVersion.cs

View workflow job for this annotation

GitHub Actions / build-and-test

The name 'formatParts' does not exist in the current context

Check failure on line 93 in src/CalendarVersioning/CalendarVersion.cs

View workflow job for this annotation

GitHub Actions / build-and-test

The name 'formatParts' does not exist in the current context
year = 2000 + value;
break;
case "MM":
Expand Down
Original file line number Diff line number Diff line change
@@ -0,0 +1,62 @@
using System;
using Xunit;
using CalendarVersioning;

namespace CalendarVersioning.Tests.UnitTests
{
public class CalendarVersionFormatTests
{
[Fact]
public void Constructor_WithPattern_SetsPatternProperty()
{
// Arrange
var pattern = "YYYY.MM.DD";

// Act
var format = new CalendarVersionFormat(pattern);

// Assert
Assert.Equal(pattern, format.Pattern);
}

[Theory]
[InlineData("YYYY.MM", 2025, 4, null, null, "2025.04")]
[InlineData("YY.MM.DD", 2025, 4, 29, null, "25.04.29")]
[InlineData("YYYY.MM.DD.Minor", 2025, 4, 29, 1, "2025.04.29.1")]
[InlineData("YYYY-MM-DD", 2025, 4, 29, null, "2025-04-29")]
public void Format_WithValidPatterns_ReturnsExpectedStrings(string pattern, int year, int month, int? day, int? minor, string expected)
{
// Arrange
var format = new CalendarVersionFormat(pattern);
var version = new CalendarVersion(year, month, day, minor, format);

// Act
var result = format.Format(version);

// Assert
Assert.Equal(expected, result);
}

[Fact]
public void Format_MissingDay_ThrowsInvalidOperationException()
{
// Arrange
var format = new CalendarVersionFormat("YYYY.MM.DD");
var version = new CalendarVersion(2025, 4, day: null, minor: null, format: format);

// Act & Assert
Assert.Throws<InvalidOperationException>(() => format.Format(version));
}

[Fact]
public void Format_MissingMinor_ThrowsInvalidOperationException()
{
// Arrange
var format = new CalendarVersionFormat("YYYY.MM.Minor");
var version = new CalendarVersion(2025, 4, day: 29, minor: null, format: format);

// Act & Assert
Assert.Throws<InvalidOperationException>(() => format.Format(version));
}
}
}
Loading