-
Notifications
You must be signed in to change notification settings - Fork 38
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
- Loading branch information
Showing
3 changed files
with
120 additions
and
0 deletions.
There are no files selected for viewing
41 changes: 41 additions & 0 deletions
41
ValveKeyValue/ValveKeyValue.Test/Test Data/TextKV3/array_from_kv1.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,41 @@ | ||
<!-- kv3 encoding:text:version{e21c7f3c-8a33-41c5-9977-a76d3a32aa0d} format:generic:version{7412167c-06e9-4698-aff2-e63eb59037e7} --> | ||
{ | ||
arrayValue = { | ||
0 = "a" | ||
1 = "b" | ||
} | ||
arrayOnSingleLine = { | ||
0 = 16.7551 | ||
1 = 20.3763 | ||
2 = 19.6448 | ||
} | ||
arrayNoSpace = { | ||
0 = 1.3763 | ||
1 = 19.6448 | ||
} | ||
arrayMixedTypes = { | ||
0 = "a" | ||
1 = "1" | ||
2 = "True" | ||
3 = "False" | ||
4 = "" | ||
5 = { | ||
foo = "bar" | ||
} | ||
6 = { | ||
0 = "1" | ||
1 = "3" | ||
2 = "3" | ||
3 = "7" | ||
} | ||
7 = "11 FF" | ||
8 = "hello.world" | ||
9 = """ | ||
multiline | ||
string | ||
""" | ||
10 = -69.42 | ||
} | ||
test = "success" | ||
test = "success" | ||
} |
20 changes: 20 additions & 0 deletions
20
ValveKeyValue/ValveKeyValue.Test/Test Data/TextKV3/flagged_value_from_kv1.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,20 @@ | ||
<!-- kv3 encoding:text:version{e21c7f3c-8a33-41c5-9977-a76d3a32aa0d} format:generic:version{7412167c-06e9-4698-aff2-e63eb59037e7} --> | ||
{ | ||
foo = "bar" | ||
bar = "foo" | ||
uppercase = "foo" | ||
flaggedNumber = "-1234" | ||
multipleFlags = "cool value" | ||
soundEvent = "event sound" | ||
noFlags = "5" | ||
flaggedObject = { | ||
1 = "test1" | ||
2 = "test2" | ||
3 = { | ||
0 = "test3" | ||
} | ||
4 = "test4" | ||
} | ||
test = "success" | ||
test = "success" | ||
} |
59 changes: 59 additions & 0 deletions
59
ValveKeyValue/ValveKeyValue.Test/TextKV3/Kv1ToKv3TestCase.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,59 @@ | ||
using System; | ||
using System.IO; | ||
using NUnit.Framework; | ||
|
||
namespace ValveKeyValue.Test.TextKV3 | ||
{ | ||
class Kv1ToKv3TestCase | ||
{ | ||
[Test] | ||
public void SerializesBasicObjects() | ||
{ | ||
using var stream = TestDataHelper.OpenResource("TextKV3.flagged_value_kv1.vdf"); | ||
var expected = TestDataHelper.ReadTextResource("TextKV3.flagged_value_from_kv1.kv3"); | ||
|
||
var kv1 = KVSerializer.Create(KVSerializationFormat.KeyValues1Text); | ||
var kv3 = KVSerializer.Create(KVSerializationFormat.KeyValues3Text); | ||
var data = kv1.Deserialize(stream); | ||
|
||
data.Add(new KVObject("test", "success")); | ||
|
||
string text; | ||
using (var ms = new MemoryStream()) | ||
{ | ||
kv3.Serialize(ms, data); | ||
|
||
ms.Seek(0, SeekOrigin.Begin); | ||
using var reader = new StreamReader(ms); | ||
text = reader.ReadToEnd(); | ||
} | ||
|
||
Assert.That(text, Is.EqualTo(expected)); | ||
} | ||
|
||
[Test] | ||
public void SerializesAndKeepsLinearObjects() // TODO: Perhaps in the future KV1 arrays can use the KVArray type so it can be emitted as an array | ||
{ | ||
using var stream = TestDataHelper.OpenResource("TextKV3.array_kv1.vdf"); | ||
var expected = TestDataHelper.ReadTextResource("TextKV3.array_from_kv1.kv3"); | ||
|
||
var kv1 = KVSerializer.Create(KVSerializationFormat.KeyValues1Text); | ||
var kv3 = KVSerializer.Create(KVSerializationFormat.KeyValues3Text); | ||
var data = kv1.Deserialize(stream); | ||
|
||
data.Add(new KVObject("test", "success")); | ||
|
||
string text; | ||
using (var ms = new MemoryStream()) | ||
{ | ||
kv3.Serialize(ms, data); | ||
|
||
ms.Seek(0, SeekOrigin.Begin); | ||
using var reader = new StreamReader(ms); | ||
text = reader.ReadToEnd(); | ||
} | ||
|
||
Assert.That(text, Is.EqualTo(expected)); | ||
} | ||
} | ||
} |