Skip to content

Commit

Permalink
Fix ignore logic for nullable bool (#445)
Browse files Browse the repository at this point in the history
  • Loading branch information
SimonCropp authored Dec 5, 2021
1 parent 43fbf0a commit b6ecbd7
Show file tree
Hide file tree
Showing 13 changed files with 187 additions and 87 deletions.
4 changes: 2 additions & 2 deletions docs/named-tuples.md
Original file line number Diff line number Diff line change
Expand Up @@ -21,7 +21,7 @@ static (bool Member1, string Member2, string Member3) MethodWithNamedTuple()
return (true, "A", "B");
}
```
<sup><a href='/src/Verify.Tests/Serialization/SerializationTests.cs#L999-L1006' title='Snippet source file'>snippet source</a> | <a href='#snippet-methodwithnamedtuple' title='Start of snippet'>anchor</a></sup>
<sup><a href='/src/Verify.Tests/Serialization/SerializationTests.cs#L1067-L1074' title='Snippet source file'>snippet source</a> | <a href='#snippet-methodwithnamedtuple' title='Start of snippet'>anchor</a></sup>
<!-- endSnippet -->

Can be verified:
Expand All @@ -31,7 +31,7 @@ Can be verified:
```cs
await Verifier.VerifyTuple(() => MethodWithNamedTuple());
```
<sup><a href='/src/Verify.Tests/Serialization/SerializationTests.cs#L992-L996' title='Snippet source file'>snippet source</a> | <a href='#snippet-verifytuple' title='Start of snippet'>anchor</a></sup>
<sup><a href='/src/Verify.Tests/Serialization/SerializationTests.cs#L1060-L1064' title='Snippet source file'>snippet source</a> | <a href='#snippet-verifytuple' title='Start of snippet'>anchor</a></sup>
<!-- endSnippet -->

Resulting in:
Expand Down
10 changes: 5 additions & 5 deletions docs/scrubbers.md
Original file line number Diff line number Diff line change
Expand Up @@ -56,7 +56,7 @@ For example remove lines containing `text`:
```cs
verifySettings.ScrubLines(line => line.Contains("text"));
```
<sup><a href='/src/Verify.Tests/Serialization/SerializationTests.cs#L870-L874' title='Snippet source file'>snippet source</a> | <a href='#snippet-scrublines' title='Start of snippet'>anchor</a></sup>
<sup><a href='/src/Verify.Tests/Serialization/SerializationTests.cs#L938-L942' title='Snippet source file'>snippet source</a> | <a href='#snippet-scrublines' title='Start of snippet'>anchor</a></sup>
<!-- endSnippet -->


Expand All @@ -71,7 +71,7 @@ For example remove lines containing `text1` or `text2`
```cs
verifySettings.ScrubLinesContaining("text1", "text2");
```
<sup><a href='/src/Verify.Tests/Serialization/SerializationTests.cs#L876-L880' title='Snippet source file'>snippet source</a> | <a href='#snippet-scrublinescontaining' title='Start of snippet'>anchor</a></sup>
<sup><a href='/src/Verify.Tests/Serialization/SerializationTests.cs#L944-L948' title='Snippet source file'>snippet source</a> | <a href='#snippet-scrublinescontaining' title='Start of snippet'>anchor</a></sup>
<!-- endSnippet -->

Case insensitive by default (StringComparison.OrdinalIgnoreCase).
Expand All @@ -83,7 +83,7 @@ Case insensitive by default (StringComparison.OrdinalIgnoreCase).
```cs
verifySettings.ScrubLinesContaining(StringComparison.Ordinal, "text1", "text2");
```
<sup><a href='/src/Verify.Tests/Serialization/SerializationTests.cs#L882-L886' title='Snippet source file'>snippet source</a> | <a href='#snippet-scrublinescontainingordinal' title='Start of snippet'>anchor</a></sup>
<sup><a href='/src/Verify.Tests/Serialization/SerializationTests.cs#L950-L954' title='Snippet source file'>snippet source</a> | <a href='#snippet-scrublinescontainingordinal' title='Start of snippet'>anchor</a></sup>
<!-- endSnippet -->


Expand All @@ -98,7 +98,7 @@ For example converts lines to upper case:
```cs
verifySettings.ScrubLinesWithReplace(line => line.ToUpper());
```
<sup><a href='/src/Verify.Tests/Serialization/SerializationTests.cs#L888-L892' title='Snippet source file'>snippet source</a> | <a href='#snippet-scrublineswithreplace' title='Start of snippet'>anchor</a></sup>
<sup><a href='/src/Verify.Tests/Serialization/SerializationTests.cs#L956-L960' title='Snippet source file'>snippet source</a> | <a href='#snippet-scrublineswithreplace' title='Start of snippet'>anchor</a></sup>
<!-- endSnippet -->


Expand All @@ -111,7 +111,7 @@ Replaces `Environment.MachineName` with `TheMachineName`.
```cs
verifySettings.ScrubMachineName();
```
<sup><a href='/src/Verify.Tests/Serialization/SerializationTests.cs#L894-L898' title='Snippet source file'>snippet source</a> | <a href='#snippet-scrubmachinename' title='Start of snippet'>anchor</a></sup>
<sup><a href='/src/Verify.Tests/Serialization/SerializationTests.cs#L962-L966' title='Snippet source file'>snippet source</a> | <a href='#snippet-scrubmachinename' title='Start of snippet'>anchor</a></sup>
<!-- endSnippet -->


Expand Down
70 changes: 35 additions & 35 deletions docs/serializer-settings.md

Large diffs are not rendered by default.

2 changes: 1 addition & 1 deletion readme.md
Original file line number Diff line number Diff line change
Expand Up @@ -335,7 +335,7 @@ public Task VerifyJsonJToken()
return Verifier.VerifyJson(target);
}
```
<sup><a href='/src/Verify.Tests/Serialization/SerializationTests.cs#L1751-L1776' title='Snippet source file'>snippet source</a> | <a href='#snippet-verifyjson' title='Start of snippet'>anchor</a></sup>
<sup><a href='/src/Verify.Tests/Serialization/SerializationTests.cs#L1819-L1844' title='Snippet source file'>snippet source</a> | <a href='#snippet-verifyjson' title='Start of snippet'>anchor</a></sup>
<!-- endSnippet -->

Results in:
Expand Down
2 changes: 1 addition & 1 deletion src/Directory.Build.props
Original file line number Diff line number Diff line change
Expand Up @@ -2,7 +2,7 @@
<Project>
<PropertyGroup>
<NoWarn>CS1591;CS0649;xUnit1026;xUnit1013;msb3277;CS0436</NoWarn>
<Version>14.7.0</Version>
<Version>14.7.1</Version>
<ImplicitUsings>enable</ImplicitUsings>
<LangVersion>10</LangVersion>
<AssemblyVersion>1.0.0</AssemblyVersion>
Expand Down
Original file line number Diff line number Diff line change
@@ -0,0 +1 @@
{}
Original file line number Diff line number Diff line change
@@ -0,0 +1,4 @@
{
BoolMember: false,
NullableBoolMember: false
}
Original file line number Diff line number Diff line change
@@ -0,0 +1 @@
{}
Original file line number Diff line number Diff line change
@@ -0,0 +1,3 @@
{
BoolMember: false
}
Original file line number Diff line number Diff line change
@@ -0,0 +1,4 @@
{
BoolMember: true,
NullableBoolMember: true
}
Original file line number Diff line number Diff line change
@@ -0,0 +1,4 @@
{
BoolMember: true,
NullableBoolMember: true
}
128 changes: 98 additions & 30 deletions src/Verify.Tests/Serialization/SerializationTests.cs
Original file line number Diff line number Diff line change
Expand Up @@ -49,8 +49,8 @@ public Task SortedDictionaryInt()
{
var dictionary = new SortedDictionary<int, string>(new DescendingComparer<int>())
{
{1, "1234"},
{2, "5678"}
{ 1, "1234" },
{ 2, "5678" }
};

return Verifier.Verify(dictionary);
Expand All @@ -61,8 +61,8 @@ public Task SymbolOrdering1()
{
var target = new Dictionary<string, int>
{
{"#", 1},
{"@", 2},
{ "#", 1 },
{ "@", 2 },
};

return Verifier.Verify(target);
Expand All @@ -73,8 +73,8 @@ public Task SymbolOrdering2()
{
var target = new Dictionary<string, int>
{
{"@", 2},
{"#", 1},
{ "@", 2 },
{ "#", 1 },
};

return Verifier.Verify(target);
Expand Down Expand Up @@ -107,9 +107,9 @@ public Task SortedDictionaryOrder()
{
var dictionary = new SortedDictionary<string, string>(new DescendingComparer<string>())
{
{"Entry_1", "1234"},
{"ignored", "1234"},
{"Entry_2", "5678"}
{ "Entry_1", "1234" },
{ "ignored", "1234" },
{ "Entry_2", "5678" }
};

return Verifier.Verify(dictionary)
Expand Down Expand Up @@ -172,7 +172,7 @@ public Task DictionaryOrderString()
{
var dictionary = new Dictionary<string, string>
{
{"ignored", "1234"}
{ "ignored", "1234" }
};

if (DateTime.UtcNow.Ticks % 2 == 0)
Expand Down Expand Up @@ -310,12 +310,13 @@ public Task NumericIdScrubbingDisabledGlobal()
Id = 5,
OtherId = 5,
YetAnotherId = 4,
PossibleNullId = (int?) 5,
ActualNullId = (int?) null
PossibleNullId = (int?)5,
ActualNullId = (int?)null
});
}

#endregion

#region DisableNumericId

[Fact]
Expand Down Expand Up @@ -345,8 +346,8 @@ public Task NumericIdScrubbing()
Id = 5,
OtherId = 5,
YetAnotherId = 4,
PossibleNullId = (int?) 5,
ActualNullId = (int?) null
PossibleNullId = (int?)5,
ActualNullId = (int?)null
};

return Verifier.Verify(target);
Expand Down Expand Up @@ -446,14 +447,14 @@ public Task NameValueCollection()
return Verifier.Verify(
new
{
item1 = new NameValueCollection {{null, null}},
item2 = new NameValueCollection {{"key", null}},
item3 = new NameValueCollection {{null, "value"}},
item4 = new NameValueCollection {{"key", "value"}},
item5 = new NameValueCollection {{"key", "value1"}, {"key", "value2"}},
item6 = new NameValueCollection {{"key", null}, {"key", "value2"}},
item7 = new NameValueCollection {{"key", "value1"}, {"key", null}},
item8 = new NameValueCollection {{"key1", "value1"}, {"key2", "value2"}},
item1 = new NameValueCollection { { null, null } },
item2 = new NameValueCollection { { "key", null } },
item3 = new NameValueCollection { { null, "value" } },
item4 = new NameValueCollection { { "key", "value" } },
item5 = new NameValueCollection { { "key", "value1" }, { "key", "value2" } },
item6 = new NameValueCollection { { "key", null }, { "key", "value2" } },
item7 = new NameValueCollection { { "key", "value1" }, { "key", null } },
item8 = new NameValueCollection { { "key1", "value1" }, { "key2", "value2" } },
});
}

Expand Down Expand Up @@ -483,7 +484,7 @@ public Task ByteArray()
return Verifier.Verify(
new
{
bytes = new byte[] {1}
bytes = new byte[] { 1 }
});
}

Expand All @@ -497,7 +498,7 @@ public Task ExampleNonDefaults()
GivenNames = "John",
FamilyName = "Smith",
Spouse = "Jill",
Children = new() {"Sam", "Mary"},
Children = new() { "Sam", "Mary" },
Address = new()
{
Street = "1 Puddle Lane",
Expand All @@ -517,6 +518,73 @@ public Task ExampleNonDefaults()
return Verifier.Verify(person, settings);
}

[Fact]
public Task Bools_True_DontIgnoreFalse()
{
var target = new BoolModel
{
BoolMember = true,
NullableBoolMember = true
};
return Verifier.Verify(target)
.ModifySerialization(x => x.DontIgnoreFalse());
}

[Fact]
public Task Bools_Null_DontIgnoreFalse()
{
var target = new BoolModel();
return Verifier.Verify(target)
.ModifySerialization(x => x.DontIgnoreFalse());
}

[Fact]
public Task Bools_False_DontIgnoreFalse()
{
var target = new BoolModel
{
BoolMember = false,
NullableBoolMember = false
};
return Verifier.Verify(target)
.ModifySerialization(x => x.DontIgnoreFalse());
}

[Fact]
public Task Bools_True()
{
var target = new BoolModel
{
BoolMember = true,
NullableBoolMember = true
};
return Verifier.Verify(target);
}

[Fact]
public Task Bools_Null()
{
var target = new BoolModel();
return Verifier.Verify(target);
}

[Fact]
public Task Bools_False()
{
var target = new BoolModel
{
BoolMember = false,
NullableBoolMember = false
};
return Verifier.Verify(target);
}

public class BoolModel
{
public bool BoolMember;
public bool? NullableBoolMember;
}

[Fact]
public Task TypeNameHandlingAll()
{
Expand All @@ -527,7 +595,7 @@ public Task TypeNameHandlingAll()
GivenNames = "John",
FamilyName = "Smith",
Spouse = "Jill",
Children = new() {"Sam", "Mary"},
Children = new() { "Sam", "Mary" },
Address = new()
{
Street = "1 Puddle Lane",
Expand Down Expand Up @@ -848,7 +916,7 @@ void DontScrubDateTimesGlobal()
#endregion
}

void DontIgnoreFalse()
void DontIgnoreFalseGlobal()
{
#region DontIgnoreFalse

Expand All @@ -860,7 +928,7 @@ void DontIgnoreFalse()
[Fact]
public Task NewLineNotEscapedInProperty()
{
return Verifier.Verify(new {Property = "a\r\nb\\nc"});
return Verifier.Verify(new { Property = "a\r\nb\\nc" });
}

void List()
Expand Down Expand Up @@ -938,7 +1006,7 @@ public Task ScrubCodeBaseLocation()
{
var codeBaseLocation = CodeBaseLocation.CurrentDirectory!.TrimEnd('/', '\\');
var altCodeBaseLocation = codeBaseLocation.Replace(Path.DirectorySeparatorChar, Path.AltDirectorySeparatorChar);
return Verifier.Verify(new {codeBaseLocation, altCodeBaseLocation});
return Verifier.Verify(new { codeBaseLocation, altCodeBaseLocation });
}
#endif

Expand All @@ -947,7 +1015,7 @@ public Task ScrubBaseDirectory()
{
var baseDirectory = AppDomain.CurrentDomain.BaseDirectory!.TrimEnd('/', '\\');
var altBaseDirectory = baseDirectory.Replace(Path.DirectorySeparatorChar, Path.AltDirectorySeparatorChar);
return Verifier.Verify(new {baseDirectory, altBaseDirectory});
return Verifier.Verify(new { baseDirectory, altBaseDirectory });
}

class TypeTarget
Expand All @@ -973,7 +1041,7 @@ public async Task ShouldUseShortTypeName()
{
#region type

var foo = new {x = 1};
var foo = new { x = 1 };
var target = new TypeTarget
{
Type = GetType(),
Expand Down
Loading

0 comments on commit b6ecbd7

Please sign in to comment.