Skip to content

Commit

Permalink
Route parameters though named items (#1392)
Browse files Browse the repository at this point in the history
* route parameters through counter

* .
  • Loading branch information
SimonCropp authored Jan 25, 2025
1 parent 7e237e8 commit 0a91574
Show file tree
Hide file tree
Showing 11 changed files with 224 additions and 55 deletions.
2 changes: 1 addition & 1 deletion docs/combinations.md
Original file line number Diff line number Diff line change
Expand Up @@ -210,7 +210,7 @@ public class CombinationResultsConverter :
for (var keyIndex = 0; keyIndex < keysLength; keyIndex++)
{
var key = item.Keys[keyIndex];
var name = VerifierSettings.GetNameForParameter(key, pathFriendly: false);
var name = VerifierSettings.GetNameForParameter(key, writer.Counter, pathFriendly: false);
keyValues[itemIndex, keyIndex] = name;
var currentKeyLength = maxKeyLengths[keyIndex];
if (name.Length > currentKeyLength)
Expand Down
18 changes: 9 additions & 9 deletions docs/naming.md
Original file line number Diff line number Diff line change
Expand Up @@ -32,7 +32,7 @@ var settings = new VerifySettings();
settings.UseDirectory("CustomDirectory");
await Verify("valueUseDirectory", settings);
```
<sup><a href='/src/Verify.Tests/Naming/NamerTests.cs#L196-L202' title='Snippet source file'>snippet source</a> | <a href='#snippet-UseDirectory' title='Start of snippet'>anchor</a></sup>
<sup><a href='/src/Verify.Tests/Naming/NamerTests.cs#L199-L205' title='Snippet source file'>snippet source</a> | <a href='#snippet-UseDirectory' title='Start of snippet'>anchor</a></sup>
<!-- endSnippet -->


Expand All @@ -44,7 +44,7 @@ await Verify("valueUseDirectory", settings);
await Verify("valueUseDirectoryFluent")
.UseDirectory("CustomDirectory");
```
<sup><a href='/src/Verify.Tests/Naming/NamerTests.cs#L207-L210' title='Snippet source file'>snippet source</a> | <a href='#snippet-UseDirectoryFluent' title='Start of snippet'>anchor</a></sup>
<sup><a href='/src/Verify.Tests/Naming/NamerTests.cs#L211-L216' title='Snippet source file'>snippet source</a> | <a href='#snippet-UseDirectoryFluent' title='Start of snippet'>anchor</a></sup>
<!-- endSnippet -->

Will result in `CustomDirectory/TypeName.MethodName.verified.txt`.
Expand All @@ -64,7 +64,7 @@ var settings = new VerifySettings();
settings.UseTypeName("CustomTypeName");
await Verify("valueUseTypeName", settings);
```
<sup><a href='/src/Verify.Tests/Naming/NamerTests.cs#L290-L296' title='Snippet source file'>snippet source</a> | <a href='#snippet-UseTypeName' title='Start of snippet'>anchor</a></sup>
<sup><a href='/src/Verify.Tests/Naming/NamerTests.cs#L299-L305' title='Snippet source file'>snippet source</a> | <a href='#snippet-UseTypeName' title='Start of snippet'>anchor</a></sup>
<!-- endSnippet -->


Expand All @@ -76,7 +76,7 @@ await Verify("valueUseTypeName", settings);
await Verify("valueUseTypeNameFluent")
.UseTypeName("CustomTypeName");
```
<sup><a href='/src/Verify.Tests/Naming/NamerTests.cs#L301-L304' title='Snippet source file'>snippet source</a> | <a href='#snippet-UseTypeNameFluent' title='Start of snippet'>anchor</a></sup>
<sup><a href='/src/Verify.Tests/Naming/NamerTests.cs#L311-L316' title='Snippet source file'>snippet source</a> | <a href='#snippet-UseTypeNameFluent' title='Start of snippet'>anchor</a></sup>
<!-- endSnippet -->

Will result in `CustomTypeName.MethodName.verified.txt`.
Expand All @@ -93,7 +93,7 @@ var settings = new VerifySettings();
settings.UseMethodName("CustomMethodName");
await Verify("valueUseMethodName", settings);
```
<sup><a href='/src/Verify.Tests/Naming/NamerTests.cs#L309-L315' title='Snippet source file'>snippet source</a> | <a href='#snippet-UseMethodName' title='Start of snippet'>anchor</a></sup>
<sup><a href='/src/Verify.Tests/Naming/NamerTests.cs#L321-L327' title='Snippet source file'>snippet source</a> | <a href='#snippet-UseMethodName' title='Start of snippet'>anchor</a></sup>
<!-- endSnippet -->

Will result in `TestClass.CustomMethodName.verified.txt`.
Expand All @@ -107,7 +107,7 @@ Will result in `TestClass.CustomMethodName.verified.txt`.
await Verify("valueUseMethodNameFluent")
.UseMethodName("CustomMethodNameFluent");
```
<sup><a href='/src/Verify.Tests/Naming/NamerTests.cs#L320-L323' title='Snippet source file'>snippet source</a> | <a href='#snippet-UseMethodNameFluent' title='Start of snippet'>anchor</a></sup>
<sup><a href='/src/Verify.Tests/Naming/NamerTests.cs#L333-L338' title='Snippet source file'>snippet source</a> | <a href='#snippet-UseMethodNameFluent' title='Start of snippet'>anchor</a></sup>
<!-- endSnippet -->

Will result in `TestClass.CustomMethodNameFluent.verified.txt`.
Expand Down Expand Up @@ -160,7 +160,7 @@ Will result in `CustomFileName.verified.txt`.
await Verify("valueUseFileNameFluent")
.UseFileName("CustomFileNameFluent");
```
<sup><a href='/src/Verify.Tests/Naming/NamerTests.cs#L188-L191' title='Snippet source file'>snippet source</a> | <a href='#snippet-UseFileNameFluent' title='Start of snippet'>anchor</a></sup>
<sup><a href='/src/Verify.Tests/Naming/NamerTests.cs#L189-L194' title='Snippet source file'>snippet source</a> | <a href='#snippet-UseFileNameFluent' title='Start of snippet'>anchor</a></sup>
<!-- endSnippet -->

Will result in `UseFileNameFluent.verified.txt`.
Expand Down Expand Up @@ -660,7 +660,7 @@ To access the current Namer `Runtime` or `RuntimeAndVersion` strings use:
Debug.WriteLine(Namer.Runtime);
Debug.WriteLine(Namer.RuntimeAndVersion);
```
<sup><a href='/src/Verify.Tests/Naming/NamerTests.cs#L329-L334' title='Snippet source file'>snippet source</a> | <a href='#snippet-AccessNamerRuntimeAndVersion' title='Start of snippet'>anchor</a></sup>
<sup><a href='/src/Verify.Tests/Naming/NamerTests.cs#L344-L349' title='Snippet source file'>snippet source</a> | <a href='#snippet-AccessNamerRuntimeAndVersion' title='Start of snippet'>anchor</a></sup>
<!-- endSnippet -->


Expand Down Expand Up @@ -834,7 +834,7 @@ var settings = new VerifySettings();
settings.UseUniqueDirectory();
await Verify("TheValue", settings);
```
<sup><a href='/src/Verify.Tests/Naming/NamerTests.cs#L216-L222' title='Snippet source file'>snippet source</a> | <a href='#snippet-UseUniqueDirectory' title='Start of snippet'>anchor</a></sup>
<sup><a href='/src/Verify.Tests/Naming/NamerTests.cs#L222-L228' title='Snippet source file'>snippet source</a> | <a href='#snippet-UseUniqueDirectory' title='Start of snippet'>anchor</a></sup>
<!-- endSnippet -->


Expand Down
101 changes: 77 additions & 24 deletions src/Verify.Tests/Naming/NameForParameterTests.cs
Original file line number Diff line number Diff line change
Expand Up @@ -2,62 +2,83 @@
{
[Fact]
public Task Null() =>
Verify(VerifierSettings.GetNameForParameter(null));
Verify(VerifierSettings.GetNameForParameter(null, counter: Counter()));

[Fact]
public Task StringEmpty() =>
Verify(VerifierSettings.GetNameForParameter(""));
Verify(VerifierSettings.GetNameForParameter("", counter: Counter()));

[Fact]
public Task StringInvalidPathChar() =>
Verify(VerifierSettings.GetNameForParameter("a/a"));
Verify(VerifierSettings.GetNameForParameter("a/a", counter: Counter()));

[Fact]
public Task Int() =>
Verify(VerifierSettings.GetNameForParameter(10));
Verify(VerifierSettings.GetNameForParameter(10, counter: Counter()));

#if NET6_0_OR_GREATER
[Fact]
public Task Half() =>
Verify(VerifierSettings.GetNameForParameter((Half) 10));
Verify(
VerifierSettings.GetNameForParameter(
(Half) 10,
counter: Counter()));
#endif

#if NET6_0_OR_GREATER
[Fact]
public Task Date() =>
Verify(VerifierSettings.GetNameForParameter(new Date(2000, 10, 1)));
Verify(
VerifierSettings.GetNameForParameter(
new Date(2000, 10, 1),
counter: Counter()));

[Fact]
public Task Time() =>
Verify(VerifierSettings.GetNameForParameter(new Date(2000, 10, 1)));
Verify(
VerifierSettings.GetNameForParameter(
new Date(2000, 10, 1),
counter: Counter()));
#endif

[Fact]
public Task DateTimeLocal()
{
var date = new DateTime(2000, 10, 1, 0, 0, 0, DateTimeKind.Local);
return Verify(VerifierSettings.GetNameForParameter(date));
return Verify(
VerifierSettings.GetNameForParameter(
date,
counter: Counter()));
}

[Fact]
public Task DateTimeUnspecified()
{
var date = new DateTime(2000, 10, 1, 0, 0, 0);
return Verify(VerifierSettings.GetNameForParameter(date));
return Verify(
VerifierSettings.GetNameForParameter(
date,
counter: Counter()));
}

[Fact]
public Task DateTimeUtc()
{
var date = new DateTime(2000, 10, 1, 0, 0, 0, DateTimeKind.Utc);
return Verify(VerifierSettings.GetNameForParameter(date));
return Verify(
VerifierSettings.GetNameForParameter(
date,
counter: Counter()));
}

[Fact]
public Task DateTimeOffsetUtc()
{
var date = new DateTimeOffset(2000, 10, 1, 0, 0, 0, TimeSpan.Zero);
return Verify(VerifierSettings.GetNameForParameter(date));
return Verify(
VerifierSettings.GetNameForParameter(
date,
counter: Counter()));
}

[Fact]
Expand All @@ -66,16 +87,19 @@ public Task List() =>
new List<string>
{
"value"
}));
},
counter: Counter()));

[Fact]
public Task ListMultiple() =>
Verify(VerifierSettings.GetNameForParameter(
Verify(
VerifierSettings.GetNameForParameter(
new List<string>
{
"value1",
"value2"
}));
},
counter: Counter()));

[Fact]
public Task Nested() =>
Expand All @@ -93,11 +117,15 @@ public Task Nested() =>
}
},
"value4"
}));
},
counter: Counter()));

[Fact]
public Task EmptyList() =>
Verify(VerifierSettings.GetNameForParameter(new List<string>()));
Verify(
VerifierSettings.GetNameForParameter(
new List<string>(),
counter: Counter()));

[Fact]
public Task Dictionary() =>
Expand All @@ -107,7 +135,8 @@ public Task Dictionary() =>
{
"value", 10
}
}));
},
counter: Counter()));

[Fact]
public Task DictionaryMultiple() =>
Expand All @@ -120,23 +149,43 @@ public Task DictionaryMultiple() =>
{
"value2", 11
}
}));
},
counter: Counter()));

[Fact]
public Task EmptyDictionary() =>
Verify(VerifierSettings.GetNameForParameter(new Dictionary<string, int>()));
Verify(
VerifierSettings.GetNameForParameter(
new Dictionary<string, int>(),
counter: Counter()));

[Fact]
public Task EnumerableStaticEmpty() =>
Verify(VerifierSettings.GetNameForParameter(Enumerable.Empty<string>()));
Verify(
VerifierSettings.GetNameForParameter(
Enumerable.Empty<string>(),
counter: Counter()));

[Fact]
public Task Array() =>
Verify(VerifierSettings.GetNameForParameter(
Verify(
VerifierSettings.GetNameForParameter(
new[]
{
"value"
}));
},
counter: Counter()));

private static Counter Counter() =>
new(
true,
#if NET6_0_OR_GREATER
[],
[],
#endif
[],
[],
[]);

[Fact]
public Task ArrayMultiple() =>
Expand All @@ -145,9 +194,13 @@ public Task ArrayMultiple() =>
{
"value1",
"value2"
}));
},
counter: Counter()));

[Fact]
public Task ArrayEmpty() =>
Verify(VerifierSettings.GetNameForParameter(System.Array.Empty<string>()));
Verify(
VerifierSettings.GetNameForParameter(
System.Array.Empty<string>(),
counter: Counter()));
}
Original file line number Diff line number Diff line change
@@ -0,0 +1 @@
Content
Original file line number Diff line number Diff line change
@@ -0,0 +1 @@
Content
Loading

0 comments on commit 0a91574

Please sign in to comment.