Skip to content

Commit

Permalink
Add test cases for different types of roots
Browse files Browse the repository at this point in the history
  • Loading branch information
xPaw committed Jun 5, 2023
1 parent f859838 commit 239a2e6
Show file tree
Hide file tree
Showing 11 changed files with 197 additions and 0 deletions.
23 changes: 23 additions & 0 deletions ValveKeyValue/ValveKeyValue.Test/Test Data/TextKV3/root_array.kv3
Original file line number Diff line number Diff line change
@@ -0,0 +1,23 @@
<!-- kv3 encoding:text:version{e21c7f3c-8a33-41c5-9977-a76d3a32aa0d} format:generic:version{7412167c-06e9-4698-aff2-e63eb59037e7} -->
[
"a",
1,
true,
false,
null,
{
foo = "bar"
},
[
1, 3, 3, 7
],
#[
11 FF
],
resource:"hello.world",
"""
multiline
string
""",
-69.420
]
Original file line number Diff line number Diff line change
@@ -0,0 +1,5 @@
<!-- kv3 encoding:text:version{e21c7f3c-8a33-41c5-9977-a76d3a32aa0d} format:generic:version{7412167c-06e9-4698-aff2-e63eb59037e7} -->
#[
00 11 22 33 44 55 66 77 88 99
AA BB CC DD FF
]
Original file line number Diff line number Diff line change
@@ -0,0 +1,4 @@
<!-- kv3 encoding:text:version{e21c7f3c-8a33-41c5-9977-a76d3a32aa0d} format:generic:version{7412167c-06e9-4698-aff2-e63eb59037e7} -->
panorama:{
foo = resource:"bar"
}
Original file line number Diff line number Diff line change
@@ -0,0 +1,2 @@
<!-- kv3 encoding:text:version{e21c7f3c-8a33-41c5-9977-a76d3a32aa0d} format:generic:version{7412167c-06e9-4698-aff2-e63eb59037e7} -->
resource:"cool_resource.txt"
Original file line number Diff line number Diff line change
@@ -0,0 +1,2 @@
<!-- kv3 encoding:text:version{e21c7f3c-8a33-41c5-9977-a76d3a32aa0d} format:generic:version{7412167c-06e9-4698-aff2-e63eb59037e7} -->
-1337.401
Original file line number Diff line number Diff line change
@@ -0,0 +1,5 @@
<!-- kv3 encoding:text:version{e21c7f3c-8a33-41c5-9977-a76d3a32aa0d} format:generic:version{7412167c-06e9-4698-aff2-e63eb59037e7} -->
"""
First line of a multi-line string literal.
Second line of a multi-line string literal.
"""
Original file line number Diff line number Diff line change
@@ -0,0 +1,2 @@
<!-- kv3 encoding:text:version{e21c7f3c-8a33-41c5-9977-a76d3a32aa0d} format:generic:version{7412167c-06e9-4698-aff2-e63eb59037e7} -->
null
Original file line number Diff line number Diff line change
@@ -0,0 +1,2 @@
<!-- kv3 encoding:text:version{e21c7f3c-8a33-41c5-9977-a76d3a32aa0d} format:generic:version{7412167c-06e9-4698-aff2-e63eb59037e7} -->
1234567890
Original file line number Diff line number Diff line change
@@ -0,0 +1,2 @@
<!-- kv3 encoding:text:version{e21c7f3c-8a33-41c5-9977-a76d3a32aa0d} format:generic:version{7412167c-06e9-4698-aff2-e63eb59037e7} -->
-1234567890
Original file line number Diff line number Diff line change
@@ -0,0 +1,2 @@
<!-- kv3 encoding:text:version{e21c7f3c-8a33-41c5-9977-a76d3a32aa0d} format:generic:version{7412167c-06e9-4698-aff2-e63eb59037e7} -->
"cool 123 string"
148 changes: 148 additions & 0 deletions ValveKeyValue/ValveKeyValue.Test/TextKV3/RootTypesTestCase.cs
Original file line number Diff line number Diff line change
@@ -0,0 +1,148 @@
using NUnit.Framework;

namespace ValveKeyValue.Test.TextKV3
{
class RootTypesTestCase
{
[Test]
public void DeserializesRootNull()
{
using var stream = TestDataHelper.OpenResource("TextKV3.root_null.kv3");
var data = KVSerializer.Create(KVSerializationFormat.KeyValues3Text).Deserialize(stream);

Assert.Multiple(() =>
{
Assert.That(data.Name, Is.EqualTo("root"));
Assert.That(data.Value.ValueType, Is.EqualTo(KVValueType.Null));
Assert.That((string)data.Value, Is.EqualTo("")); // TODO: This should be a null value
});
}

[Test]
public void DeserializesRootString()
{
using var stream = TestDataHelper.OpenResource("TextKV3.root_string.kv3");
var data = KVSerializer.Create(KVSerializationFormat.KeyValues3Text).Deserialize(stream);

Assert.Multiple(() =>
{
Assert.That(data.Name, Is.EqualTo("root"));
Assert.That(data.Value.ValueType, Is.EqualTo(KVValueType.String));
Assert.That((string)data.Value, Is.EqualTo("cool 123 string"));
});
}

[Test]
public void DeserializesRootMultilineString()
{
using var stream = TestDataHelper.OpenResource("TextKV3.root_multiline.kv3");
var data = KVSerializer.Create(KVSerializationFormat.KeyValues3Text).Deserialize(stream);

Assert.Multiple(() =>
{
Assert.That(data.Name, Is.EqualTo("root"));
Assert.That((string)data.Value, Is.EqualTo("First line of a multi-line string literal.\nSecond line of a multi-line string literal."));
});
}

[Test]
public void DeserializesRootFlaggedString()
{
using var stream = TestDataHelper.OpenResource("TextKV3.root_flagged_string.kv3");
var data = KVSerializer.Create(KVSerializationFormat.KeyValues3Text).Deserialize(stream);

Assert.Multiple(() =>
{
Assert.That(data.Name, Is.EqualTo("root"));
Assert.That(data.Value.ValueType, Is.EqualTo(KVValueType.String));
Assert.That(data.Value.Flag, Is.EqualTo(KVFlag.Resource));
Assert.That((string)data.Value, Is.EqualTo("cool_resource.txt"));
});
}

[Test]
public void DeserializesRootFlaggedObject()
{
using var stream = TestDataHelper.OpenResource("TextKV3.root_flagged_object.kv3");
var data = KVSerializer.Create(KVSerializationFormat.KeyValues3Text).Deserialize(stream);

Assert.Multiple(() =>
{
Assert.That(data.Name, Is.EqualTo("root"));
Assert.That(data.Value.ValueType, Is.EqualTo(KVValueType.Collection));
Assert.That(data.Value.Flag, Is.EqualTo(KVFlag.Panorama));
Assert.That(data["foo"].Flag, Is.EqualTo(KVFlag.Resource));
Assert.That((string)data["foo"], Is.EqualTo("bar"));
});
}

[Test]
public void DeserializesRootBinaryBlob()
{
using var stream = TestDataHelper.OpenResource("TextKV3.root_binary_blob.kv3");
var data = KVSerializer.Create(KVSerializationFormat.KeyValues3Text).Deserialize(stream);

Assert.Multiple(() =>
{
Assert.That(data.Name, Is.EqualTo("root"));
Assert.That(data.Value.ValueType, Is.EqualTo(KVValueType.BinaryBlob));
Assert.That(((KVBinaryBlob)data.Value).Bytes, Is.EqualTo(new byte[]
{
0x00, 0x11, 0x22, 0x33, 0x44, 0x55, 0x66, 0x77,
0x88, 0x99, 0xAA, 0xBB, 0xCC, 0xDD, 0xFF
}));
});
}

[Test]
public void DeserializesRootNumber()
{
using var stream = TestDataHelper.OpenResource("TextKV3.root_number.kv3");
var data = KVSerializer.Create(KVSerializationFormat.KeyValues3Text).Deserialize(stream);

Assert.Multiple(() =>
{
Assert.That(data.Name, Is.EqualTo("root"));
Assert.That(data.Value.ValueType, Is.EqualTo(KVValueType.UInt64));
Assert.That((int)data.Value, Is.EqualTo(1234567890));
});
}

[Test]
public void DeserializesRootNumberNegative()
{
using var stream = TestDataHelper.OpenResource("TextKV3.root_number_negative.kv3");
var data = KVSerializer.Create(KVSerializationFormat.KeyValues3Text).Deserialize(stream);

Assert.Multiple(() =>
{
Assert.That(data.Name, Is.EqualTo("root"));
Assert.That(data.Value.ValueType, Is.EqualTo(KVValueType.Int64));
Assert.That((int)data.Value, Is.EqualTo(-1234567890));
});
}

[Test]
public void DeserializesRootFloat()
{
using var stream = TestDataHelper.OpenResource("TextKV3.root_float.kv3");
var data = KVSerializer.Create(KVSerializationFormat.KeyValues3Text).Deserialize(stream);

Assert.Multiple(() =>
{
Assert.That(data.Name, Is.EqualTo("root"));
Assert.That(data.Value.ValueType, Is.EqualTo(KVValueType.FloatingPoint));
Assert.That((float)data.Value, Is.EqualTo(-1337.401f));
});
}

[Test]
public void DeserializesRootArray()
{
using var stream = TestDataHelper.OpenResource("TextKV3.root_array.kv3");
var data = KVSerializer.Create(KVSerializationFormat.KeyValues3Text).Deserialize(stream);

Assert.That(data.Value.ValueType, Is.EqualTo(KVValueType.Array));
}
}
}

0 comments on commit 239a2e6

Please sign in to comment.