Skip to content

Commit f90aae1

Browse files
committed
Enable nullable in tests
1 parent 18dc8c0 commit f90aae1

Some content is hidden

Large Commits have some content hidden by default. Use the searchbox below for content that may be hidden.

45 files changed

+152
-102
lines changed

ValveKeyValue/ValveKeyValue.Test/ApiSurfaceTestCase.cs

Lines changed: 3 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -75,7 +75,7 @@ static void GenerateTypeApiSurface(StringBuilder sb, Type type)
7575
var members = Enum.GetNames(type);
7676
foreach (var member in members)
7777
{
78-
var rawValue = type.GetField(member, BindingFlags.Public | BindingFlags.Static).GetValue(null);
78+
var rawValue = type.GetField(member, BindingFlags.Public | BindingFlags.Static)!.GetValue(null);
7979
var convertedValue = Convert.ChangeType(rawValue, Enum.GetUnderlyingType(type), CultureInfo.InvariantCulture);
8080

8181
sb.Append(" ");
@@ -172,7 +172,7 @@ static void GenerateTypeApiSurface(StringBuilder sb, Type type)
172172

173173
static bool IsHidingMember(MethodInfo method)
174174
{
175-
var baseType = method.DeclaringType.GetTypeInfo().BaseType;
175+
var baseType = method.DeclaringType!.GetTypeInfo().BaseType;
176176
if (baseType == null)
177177
{
178178
return false;
@@ -233,7 +233,7 @@ static string GetTypeAsString(Type type)
233233
{
234234
if (type.IsArray)
235235
{
236-
var elementType = type.GetElementType();
236+
var elementType = type.GetElementType()!;
237237
var elementTypeAsString = GetTypeAsString(elementType);
238238
return string.Format(CultureInfo.InvariantCulture, "{0}[]", elementTypeAsString);
239239
}

ValveKeyValue/ValveKeyValue.Test/Binary/BinaryObjectConsecutiveDeserializationTestCase.cs

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -47,13 +47,13 @@ public void SetUp()
4747
class FirstObject
4848
{
4949
[KVProperty("firstkey")]
50-
public string StringValue { get; set; }
50+
public required string StringValue { get; set; }
5151
}
5252

5353
class SecondObject
5454
{
5555
[KVProperty("secondkey")]
56-
public string StringValue { get; set; }
56+
public required string StringValue { get; set; }
5757
}
5858
}
5959
}

ValveKeyValue/ValveKeyValue.Test/Binary/BinaryObjectConsecutiveSerializationTestCase.cs

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -7,11 +7,11 @@ public void SerializesToBinaryStructure()
77
{
88
var firstObj = KVObject.ListCollection();
99
firstObj.Add("firstkey", "firstvalue");
10-
var first = new KVDocument(null, "FirstObject", firstObj);
10+
var first = new KVDocument(null!, "FirstObject", firstObj);
1111

1212
var secondObj = KVObject.ListCollection();
1313
secondObj.Add("secondkey", "secondvalue");
14-
var second = new KVDocument(null, "SecondObject", secondObj);
14+
var second = new KVDocument(null!, "SecondObject", secondObj);
1515

1616
var expectedData = new byte[]
1717
{

ValveKeyValue/ValveKeyValue.Test/Binary/BinaryObjectDeserializationTestCase.cs

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -81,10 +81,10 @@ public void SetUp()
8181
class TestObject
8282
{
8383
[KVProperty("key")]
84-
public string StringValue { get; set; }
84+
public required string StringValue { get; set; }
8585

8686
[KVProperty("key_utf8")]
87-
public string StringUtf8Value { get; set; }
87+
public required string StringUtf8Value { get; set; }
8888

8989
[KVProperty("int")]
9090
public int TheIntegerValue { get; set; }

ValveKeyValue/ValveKeyValue.Test/Binary/BinaryObjectSerializationTestCase.cs

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -13,7 +13,7 @@ public void SerializesToBinaryStructure()
1313
kvo.Add("ptr", new IntPtr(0x12345678));
1414
kvo.Add("lng", 0x8877665544332211u);
1515
kvo.Add("i64", 0x0102030405060708);
16-
var doc = new KVDocument(null, "TestObject", kvo);
16+
var doc = new KVDocument(null!, "TestObject", kvo);
1717

1818
var expectedData = new byte[]
1919
{
@@ -71,7 +71,7 @@ public void NewValueTypesAreWidenedInBinarySerialization()
7171
kvo.Add("f64", 3.14);
7272
kvo.Add("blob", KVObject.Blob([0xAB, 0xCD]));
7373
kvo.Add("null", KVObject.Null());
74-
var doc = new KVDocument(null, "Test", kvo);
74+
var doc = new KVDocument(null!, "Test", kvo);
7575

7676
using var ms = new MemoryStream();
7777
KVSerializer.Create(KVSerializationFormat.KeyValues1Binary).Serialize(ms, doc);

ValveKeyValue/ValveKeyValue.Test/Binary/StringTableFromScratchTestCase.cs

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -12,7 +12,7 @@ public void PopulatesStringTableDuringSerialization()
1212
var kv = KVObject.ListCollection();
1313
kv.Add("key", "value");
1414
kv.Add("child", child);
15-
var doc = new KVDocument(null, "root", kv);
15+
var doc = new KVDocument(null!, "root", kv);
1616

1717
var stringTable = new StringTable();
1818

ValveKeyValue/ValveKeyValue.Test/ConversionCoverageTestCase.cs

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -345,7 +345,7 @@ public void DictBackedCollectionSetNullStoresNullValue()
345345

346346
Assert.That(data.Count, Is.EqualTo(2));
347347

348-
data["key1"] = null;
348+
data["key1"] = null!;
349349

350350
Assert.That(data.Count, Is.EqualTo(2));
351351
Assert.That(data["key1"].IsNull, Is.True);

ValveKeyValue/ValveKeyValue.Test/EdgeCaseTestCase.cs

Lines changed: 7 additions & 7 deletions
Original file line numberDiff line numberDiff line change
@@ -86,7 +86,7 @@ public void IndexerSetNullStoresNullValue()
8686
obj.Add("a", "1");
8787
obj.Add("b", "2");
8888

89-
obj["a"] = null;
89+
obj["a"] = null!;
9090

9191
Assert.That(obj.Count, Is.EqualTo(2));
9292
Assert.That(obj["a"].IsNull, Is.True);
@@ -99,7 +99,7 @@ public void IndexerSetNullOnMissingKeyStoresNullValue()
9999
var obj = KVObject.ListCollection();
100100
obj.Add("a", "1");
101101

102-
obj["nonexistent"] = null;
102+
obj["nonexistent"] = null!;
103103

104104
Assert.That(obj.Count, Is.EqualTo(2));
105105
Assert.That((string)obj["a"], Is.EqualTo("1"));
@@ -429,7 +429,7 @@ public void TryGetValueReturnsTrueForExisting()
429429

430430
Assert.That(result, Is.True);
431431
Assert.That(child, Is.Not.Null);
432-
Assert.That((string)child, Is.EqualTo("value"));
432+
Assert.That((string)child!, Is.EqualTo("value"));
433433
}
434434

435435
[Test]
@@ -440,7 +440,7 @@ public void TryGetValueOnDictBackedCollection()
440440
var obj = KVSerializer.Create(KVSerializationFormat.KeyValues3Text).Deserialize(stream);
441441

442442
Assert.That(obj.TryGetValue("key1", out var found), Is.True);
443-
Assert.That((string)found, Is.EqualTo("value1"));
443+
Assert.That((string)found!, Is.EqualTo("value1"));
444444

445445
Assert.That(obj.TryGetValue("missing", out var notFound), Is.False);
446446
Assert.That(notFound, Is.Null);
@@ -700,7 +700,7 @@ public void IndexerSetNullOnMissingKeyInDictCollectionStoresNullValue()
700700
var obj = KVObject.Collection();
701701
obj.Add("a", 1);
702702

703-
obj["nonexistent"] = null;
703+
obj["nonexistent"] = null!;
704704

705705
Assert.That(obj.Count, Is.EqualTo(2));
706706
Assert.That((int)obj["a"], Is.EqualTo(1));
@@ -738,9 +738,9 @@ public void DictAndListCollectionsHaveConsistentBehavior()
738738
{
739739
// TryGetValue
740740
Assert.That(dict.TryGetValue("a", out var dictA), Is.True);
741-
Assert.That((int)dictA, Is.EqualTo(1));
741+
Assert.That((int)dictA!, Is.EqualTo(1));
742742
Assert.That(list.TryGetValue("a", out var listA), Is.True);
743-
Assert.That((int)listA, Is.EqualTo(1));
743+
Assert.That((int)listA!, Is.EqualTo(1));
744744
Assert.That(dict.TryGetValue("missing", out _), Is.False);
745745
Assert.That(list.TryGetValue("missing", out _), Is.False);
746746

ValveKeyValue/ValveKeyValue.Test/Helpers/KVSerializerExtensions.cs

Lines changed: 4 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -2,19 +2,19 @@ namespace ValveKeyValue.Test
22
{
33
static class KVSerializerExtensions
44
{
5-
public static KVDocument Deserialize(this KVSerializer serializer, byte[] data, KVSerializerOptions options = null)
5+
public static KVDocument Deserialize(this KVSerializer serializer, byte[] data, KVSerializerOptions? options = null)
66
{
77
using var ms = new MemoryStream(data);
88
return serializer.Deserialize(ms, options);
99
}
1010

11-
public static TObject Deserialize<TObject>(this KVSerializer serializer, byte[] data, KVSerializerOptions options = null)
11+
public static TObject Deserialize<TObject>(this KVSerializer serializer, byte[] data, KVSerializerOptions? options = null)
1212
{
1313
using var ms = new MemoryStream(data);
1414
return serializer.Deserialize<TObject>(ms, options);
1515
}
1616

17-
public static KVDocument Deserialize(this KVSerializer serializer, string text, KVSerializerOptions options = null)
17+
public static KVDocument Deserialize(this KVSerializer serializer, string text, KVSerializerOptions? options = null)
1818
{
1919
using var ms = new MemoryStream();
2020
using var writer = new StreamWriter(ms);
@@ -26,7 +26,7 @@ public static KVDocument Deserialize(this KVSerializer serializer, string text,
2626
return serializer.Deserialize(ms, options);
2727
}
2828

29-
public static TObject Deserialize<TObject>(this KVSerializer serializer, string text, KVSerializerOptions options = null)
29+
public static TObject Deserialize<TObject>(this KVSerializer serializer, string text, KVSerializerOptions? options = null)
3030
{
3131
using var ms = new MemoryStream();
3232
using var writer = new StreamWriter(ms);

ValveKeyValue/ValveKeyValue.Test/IKVTextReader.cs

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -2,8 +2,8 @@ namespace ValveKeyValue.Test
22
{
33
interface IKVTextReader
44
{
5-
KVObject Read(string resourceName, KVSerializerOptions options = null);
5+
KVObject Read(string resourceName, KVSerializerOptions? options = null);
66

7-
T Read<T>(string resourceName, KVSerializerOptions options = null);
7+
T Read<T>(string resourceName, KVSerializerOptions? options = null);
88
}
99
}

0 commit comments

Comments
 (0)