Skip to content

Commit c6664f2

Browse files
committed
✅ refactor test lambdas to discard unused parameters and simplify logic
1 parent fc95268 commit c6664f2

File tree

5 files changed

+40
-30
lines changed

5 files changed

+40
-30
lines changed

QsNet.Tests/DecodeOptionsTests.cs

Lines changed: 7 additions & 7 deletions
Original file line numberDiff line numberDiff line change
@@ -152,7 +152,7 @@ public void DecoderWithKind_IsUsed_For_Key_And_Value()
152152
var calls = new List<(string? s, DecodeKind kind)>();
153153
var options = new DecodeOptions
154154
{
155-
DecoderWithKind = (s, enc, kind) =>
155+
DecoderWithKind = (s, _, kind) =>
156156
{
157157
calls.Add((s, kind));
158158
return s;
@@ -174,7 +174,7 @@ public void DecoderWithKind_NullReturn_IsHonored_NoFallback()
174174
{
175175
var options = new DecodeOptions
176176
{
177-
DecoderWithKind = (s, enc, kind) => null
177+
DecoderWithKind = (_, _, _) => null
178178
};
179179

180180
options.DecodeValue("foo", Encoding.UTF8).Should().BeNull();
@@ -186,7 +186,7 @@ public void LegacyDecoder_IsUsed_When_NoKindAwareDecoder_IsProvided()
186186
{
187187
var options = new DecodeOptions
188188
{
189-
Decoder = (s, enc) => s is null ? null : s.ToUpperInvariant()
189+
Decoder = (s, _) => s?.ToUpperInvariant()
190190
};
191191

192192
options.DecodeValue("abc", Encoding.UTF8).Should().Be("ABC");
@@ -199,8 +199,8 @@ public void CopyWith_PreservesAndOverrides_Decoders()
199199
{
200200
var original = new DecodeOptions
201201
{
202-
Decoder = (s, enc) => s == null ? null : $"L:{s}",
203-
DecoderWithKind = (s, enc, k) => s == null ? null : $"K:{k}:{s}"
202+
Decoder = (s, _) => s == null ? null : $"L:{s}",
203+
DecoderWithKind = (s, _, k) => s == null ? null : $"K:{k}:{s}"
204204
};
205205

206206
// Copy without overrides preserves both decoders
@@ -209,11 +209,11 @@ public void CopyWith_PreservesAndOverrides_Decoders()
209209
copy.DecodeKey("k", Encoding.UTF8).Should().Be("K:Key:k");
210210

211211
// Override only the legacy decoder; kind-aware remains
212-
var copy2 = original.CopyWith(decoder: (s, enc) => s == null ? null : $"L2:{s}");
212+
var copy2 = original.CopyWith(decoder: (s, _) => s == null ? null : $"L2:{s}");
213213
copy2.DecodeValue("v", Encoding.UTF8).Should().Be("K:Value:v"); // still kind-aware takes precedence
214214

215215
// Override kind-aware decoder
216-
var copy3 = original.CopyWith(decoderWithKind: (s, enc, k) => s == null ? null : $"K2:{k}:{s}");
216+
var copy3 = original.CopyWith(decoderWithKind: (s, _, k) => s == null ? null : $"K2:{k}:{s}");
217217
copy3.DecodeValue("v", Encoding.UTF8).Should().Be("K2:Value:v");
218218
copy3.DecodeKey("k", Encoding.UTF8).Should().Be("K2:Key:k");
219219
}

QsNet.Tests/DecodeTests.cs

Lines changed: 19 additions & 10 deletions
Original file line numberDiff line numberDiff line change
@@ -1678,23 +1678,32 @@ public void Decode_ParsesValuesWithCommaAsListDivider()
16781678
[Fact]
16791679
public void Decode_UseNumberDecoderParsesStringThatHasOneNumberWithCommaOptionEnabled()
16801680
{
1681-
object? NumberDecoder(string? str, Encoding? charset)
1682-
{
1683-
if (int.TryParse(str, out var number))
1684-
return number;
1685-
return Utils.Decode(str, charset);
1686-
}
1687-
16881681
var options = new DecodeOptions { Comma = true, Decoder = NumberDecoder };
16891682

1690-
// For now, testing with default decoder
16911683
Qs.Decode("foo=1", new DecodeOptions { Comma = true })
16921684
.Should()
16931685
.BeEquivalentTo(new Dictionary<string, object?> { ["foo"] = "1" });
16941686

16951687
Qs.Decode("foo=0", new DecodeOptions { Comma = true })
16961688
.Should()
16971689
.BeEquivalentTo(new Dictionary<string, object?> { ["foo"] = "0" });
1690+
1691+
Qs.Decode("foo=1", options)
1692+
.Should()
1693+
.BeEquivalentTo(new Dictionary<string, object?> { ["foo"] = 1 });
1694+
1695+
Qs.Decode("foo=0", options)
1696+
.Should()
1697+
.BeEquivalentTo(new Dictionary<string, object?> { ["foo"] = 0 });
1698+
1699+
return;
1700+
1701+
object? NumberDecoder(string? str, Encoding? charset)
1702+
{
1703+
if (int.TryParse(str, out var number))
1704+
return number;
1705+
return Utils.Decode(str, charset);
1706+
}
16981707
}
16991708

17001709
[Fact]
@@ -1984,7 +1993,7 @@ public void Decode_CanParseWithCustomEncoding()
19841993

19851994
string? CustomDecoder(string? str, Encoding? charset)
19861995
{
1987-
return str?.Replace("%8c%a7", "県")?.Replace("%91%e5%8d%e3%95%7b", "大阪府");
1996+
return str?.Replace("%8c%a7", "県").Replace("%91%e5%8d%e3%95%7b", "大阪府");
19881997
}
19891998

19901999
var options = new DecodeOptions { Decoder = CustomDecoder };
@@ -4519,7 +4528,7 @@ public void DecoderWithKind_ReceivesKey_ForTopLevelAndBracketedKeys()
45194528
var calls = new List<(string? s, DecodeKind kind)>();
45204529
var opt = new DecodeOptions
45214530
{
4522-
DecoderWithKind = (s, enc, kind) =>
4531+
DecoderWithKind = (s, _, kind) =>
45234532
{
45244533
calls.Add((s, kind));
45254534
return s;

QsNet.Tests/EncodeTests.cs

Lines changed: 7 additions & 8 deletions
Original file line numberDiff line numberDiff line change
@@ -110,16 +110,16 @@ public void Encode_AccessPropertyOfNonMapNonIterableObject()
110110
new EncodeOptions
111111
{
112112
Encode = false,
113-
Filter = new FunctionFilter((prefix, map) =>
113+
Filter = new FunctionFilter((_, map) =>
114114
{
115115
// This should trigger the code path that accesses properties of non-Map, non-Iterable objects
116116
var result = new Dictionary<string, object?>();
117-
if (map is IDictionary<string, object?> dict)
118-
foreach (var (key, value) in dict)
119-
if (value is CustomObject customValue)
120-
result[key] = customValue["prop"];
121-
else
122-
result[key] = value;
117+
if (map is not IDictionary<string, object?> dict) return result;
118+
foreach (var (key, value) in dict)
119+
if (value is CustomObject customValue)
120+
result[key] = customValue["prop"];
121+
else
122+
result[key] = value;
123123

124124
return result;
125125
}
@@ -2979,7 +2979,6 @@ public void Encode_EncodesSpatieMap()
29792979
[MemberData(nameof(GetEmptyTestCases))]
29802980
public void Encode_MapWithEmptyStringKey(Dictionary<string, object?> testCase)
29812981
{
2982-
var input = (string)testCase["input"]!;
29832982
var withEmptyKeys = (Dictionary<string, object?>)testCase["withEmptyKeys"]!;
29842983
var stringifyOutput = (Dictionary<string, object?>)testCase["stringifyOutput"]!;
29852984

QsNet.Tests/Fixtures/DummyEnum.cs

Lines changed: 2 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -2,7 +2,9 @@ namespace QsNet.Tests.Fixtures;
22

33
internal enum DummyEnum
44
{
5+
// ReSharper disable InconsistentNaming
56
LOREM,
67
IPSUM,
78
DOLOR
9+
// ReSharper restore InconsistentNaming
810
}

QsNet.Tests/UtilsTests.cs

Lines changed: 5 additions & 5 deletions
Original file line numberDiff line numberDiff line change
@@ -1551,19 +1551,19 @@ public void ToStringKeyDeepNonRecursive_Converts_Nested_Lists_And_Dicts()
15511551
var outTopList = result["x"] as List<object?>;
15521552
outTopList.Should().NotBeNull();
15531553

1554-
var outDict1 = outTopList![0] as Dictionary<string, object?>;
1554+
var outDict1 = outTopList[0] as Dictionary<string, object?>;
15551555
outDict1.Should().NotBeNull();
1556-
outDict1!["a"].Should().Be(1);
1556+
outDict1["a"].Should().Be(1);
15571557

15581558
var outInnerList = outTopList[1] as List<object?>;
15591559
outInnerList.Should().NotBeNull();
15601560

1561-
var outDict2 = outInnerList![0] as Dictionary<string, object?>;
1561+
var outDict2 = outInnerList[0] as Dictionary<string, object?>;
15621562
var outDict3 = outInnerList[1] as Dictionary<string, object?>;
15631563
outDict2.Should().NotBeNull();
15641564
outDict3.Should().NotBeNull();
1565-
outDict2!["b"].Should().Be(2);
1566-
outDict3!["c"].Should().Be(3);
1565+
outDict2["b"].Should().Be(2);
1566+
outDict3["c"].Should().Be(3);
15671567

15681568
outTopList[2].Should().Be(4);
15691569
}

0 commit comments

Comments
 (0)