-
Notifications
You must be signed in to change notification settings - Fork 37
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
Add test cases for different types of roots
- Loading branch information
Showing
11 changed files
with
197 additions
and
0 deletions.
There are no files selected for viewing
23 changes: 23 additions & 0 deletions
23
ValveKeyValue/ValveKeyValue.Test/Test Data/TextKV3/root_array.kv3
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
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 | ||
] |
5 changes: 5 additions & 0 deletions
5
ValveKeyValue/ValveKeyValue.Test/Test Data/TextKV3/root_binary_blob.kv3
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
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 | ||
] |
4 changes: 4 additions & 0 deletions
4
ValveKeyValue/ValveKeyValue.Test/Test Data/TextKV3/root_flagged_object.kv3
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
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" | ||
} |
2 changes: 2 additions & 0 deletions
2
ValveKeyValue/ValveKeyValue.Test/Test Data/TextKV3/root_flagged_string.kv3
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
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" |
2 changes: 2 additions & 0 deletions
2
ValveKeyValue/ValveKeyValue.Test/Test Data/TextKV3/root_float.kv3
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
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 |
5 changes: 5 additions & 0 deletions
5
ValveKeyValue/ValveKeyValue.Test/Test Data/TextKV3/root_multiline.kv3
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
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. | ||
""" |
2 changes: 2 additions & 0 deletions
2
ValveKeyValue/ValveKeyValue.Test/Test Data/TextKV3/root_null.kv3
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
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 |
2 changes: 2 additions & 0 deletions
2
ValveKeyValue/ValveKeyValue.Test/Test Data/TextKV3/root_number.kv3
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
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 |
2 changes: 2 additions & 0 deletions
2
ValveKeyValue/ValveKeyValue.Test/Test Data/TextKV3/root_number_negative.kv3
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
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 |
2 changes: 2 additions & 0 deletions
2
ValveKeyValue/ValveKeyValue.Test/Test Data/TextKV3/root_string.kv3
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
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
148
ValveKeyValue/ValveKeyValue.Test/TextKV3/RootTypesTestCase.cs
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
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)); | ||
} | ||
} | ||
} |