Skip to content

Commit 16ff852

Browse files
9swampyarturcic
authored andcommitted
Align tests with moved InputSanitizer.cs and StringFormatWithExtension.cs
1 parent dfd7ec0 commit 16ff852

File tree

10 files changed

+10
-32
lines changed

10 files changed

+10
-32
lines changed

src/GitVersion.Core.Tests/Extensions/StringFormatWithExtensionTests.cs

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -1,5 +1,5 @@
11
using GitVersion.Core.Tests.Helpers;
2-
using GitVersion.Helpers;
2+
using GitVersion.Formatting;
33

44
namespace GitVersion.Core.Tests;
55

src/GitVersion.Core.Tests/Helpers/EdgeCaseTests.cs renamed to src/GitVersion.Core.Tests/Formatting/EdgeCaseTests.cs

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -1,5 +1,5 @@
11
using GitVersion.Core.Tests.Extensions;
2-
using GitVersion.Helpers;
2+
using GitVersion.Formatting;
33

44
namespace GitVersion.Tests.Helpers;
55

src/GitVersion.Core.Tests/Helpers/InputSanitizerTests.cs renamed to src/GitVersion.Core.Tests/Formatting/InputSanitizerTests.cs

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -1,5 +1,5 @@
11
using GitVersion.Core.Tests.Extensions;
2-
using GitVersion.Helpers;
2+
using GitVersion.Formatting;
33

44
namespace GitVersion.Tests.Helpers;
55

src/GitVersion.Core.Tests/Helpers/SanitizeEnvVarNameTests.cs renamed to src/GitVersion.Core.Tests/Formatting/SanitizeEnvVarNameTests.cs

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -1,5 +1,5 @@
11
using GitVersion.Core.Tests.Extensions;
2-
using GitVersion.Helpers;
2+
using GitVersion.Formatting;
33

44
namespace GitVersion.Tests.Helpers;
55

src/GitVersion.Core.Tests/Helpers/SanitizeMemberNameTests.cs renamed to src/GitVersion.Core.Tests/Formatting/SanitizeMemberNameTests.cs

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -1,5 +1,5 @@
11
using GitVersion.Core.Tests.Extensions;
2-
using GitVersion.Helpers;
2+
using GitVersion.Formatting;
33

44
namespace GitVersion.Tests.Helpers;
55

src/GitVersion.Core/Helpers/IInputSanitizer.cs renamed to src/GitVersion.Core/Formatting/IInputSanitizer.cs

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -1,4 +1,4 @@
1-
namespace GitVersion.Helpers
1+
namespace GitVersion.Formatting
22
{
33
internal interface IInputSanitizer
44
{

src/GitVersion.Core/Helpers/InputSanitizer.cs renamed to src/GitVersion.Core/Formatting/InputSanitizer.cs

Lines changed: 1 addition & 19 deletions
Original file line numberDiff line numberDiff line change
@@ -1,65 +1,47 @@
11
using GitVersion.Core;
22

3-
namespace GitVersion.Helpers;
3+
namespace GitVersion.Formatting;
44

55
internal class InputSanitizer : IInputSanitizer
66
{
77
public string SanitizeFormat(string format)
88
{
99
if (string.IsNullOrWhiteSpace(format))
10-
{
1110
throw new FormatException("Format string cannot be empty.");
12-
}
1311

1412
if (format.Length > 50)
15-
{
1613
throw new FormatException($"Format string too long: '{format[..20]}...'");
17-
}
1814

1915
if (format.Any(c => char.IsControl(c) && c != '\t'))
20-
{
2116
throw new FormatException("Format string contains invalid control characters");
22-
}
2317

2418
return format;
2519
}
2620

2721
public string SanitizeEnvVarName(string name)
2822
{
2923
if (string.IsNullOrWhiteSpace(name))
30-
{
3124
throw new ArgumentException("Environment variable name cannot be null or empty.");
32-
}
3325

3426
if (name.Length > 200)
35-
{
3627
throw new ArgumentException($"Environment variable name too long: '{name[..20]}...'");
37-
}
3828

3929
if (!RegexPatterns.Cache.GetOrAdd(RegexPatterns.Common.SanitizeEnvVarNameRegexPattern).IsMatch(name))
40-
{
4130
throw new ArgumentException($"Environment variable name contains disallowed characters: '{name}'");
42-
}
4331

4432
return name;
4533
}
4634

4735
public string SanitizeMemberName(string memberName)
4836
{
4937
if (string.IsNullOrWhiteSpace(memberName))
50-
{
5138
throw new ArgumentException("Member name cannot be empty.");
52-
}
5339

5440
if (memberName.Length > 100)
55-
{
5641
throw new ArgumentException($"Member name too long: '{memberName[..20]}...'");
57-
}
5842

5943
if (!RegexPatterns.Cache.GetOrAdd(RegexPatterns.Common.SanitizeMemberNameRegexPattern).IsMatch(memberName))
60-
{
6144
throw new ArgumentException($"Member name contains disallowed characters: '{memberName}'");
62-
}
6345

6446
return memberName;
6547
}

src/GitVersion.Core/Helpers/StringFormatWith.cs renamed to src/GitVersion.Core/Formatting/StringFormatWithExtension.cs

Lines changed: 1 addition & 6 deletions
Original file line numberDiff line numberDiff line change
@@ -1,8 +1,7 @@
11
using System.Text.RegularExpressions;
22
using GitVersion.Core;
3-
using GitVersion.Formatting;
43

5-
namespace GitVersion.Helpers;
4+
namespace GitVersion.Formatting;
65

76
internal static class StringFormatWithExtension
87
{
@@ -59,9 +58,7 @@ private static string EvaluateMatch<T>(Match match, T source, IEnvironment envir
5958
var fallback = match.Groups["fallback"].Success ? match.Groups["fallback"].Value : null;
6059

6160
if (match.Groups["envvar"].Success)
62-
{
6361
return EvaluateEnvVar(match.Groups["envvar"].Value, fallback, environment);
64-
}
6562

6663
if (match.Groups["member"].Success)
6764
{
@@ -88,9 +85,7 @@ private static string EvaluateMember<T>(T source, string member, string? format,
8885
var value = getter(source);
8986

9087
if (value is null)
91-
{
9288
return fallback ?? string.Empty;
93-
}
9489

9590
if (format is not null && ValueFormatter.Default.TryFormat(
9691
value,

src/GitVersion.Core/VersionCalculation/VariableProvider.cs

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -1,7 +1,7 @@
11
using GitVersion.Configuration;
22
using GitVersion.Core;
33
using GitVersion.Extensions;
4-
using GitVersion.Helpers;
4+
using GitVersion.Formatting;
55
using GitVersion.OutputVariables;
66

77
namespace GitVersion.VersionCalculation;

src/GitVersion.Output/OutputGenerator/OutputGenerator.cs

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -1,6 +1,7 @@
11
using System.IO.Abstractions;
22
using GitVersion.Agents;
33
using GitVersion.Extensions;
4+
using GitVersion.Formatting;
45
using GitVersion.Helpers;
56
using GitVersion.Logging;
67
using GitVersion.OutputVariables;

0 commit comments

Comments
 (0)