Skip to content

Commit

Permalink
Add kv1 -> kv3 test
Browse files Browse the repository at this point in the history
  • Loading branch information
xPaw committed Apr 8, 2023
1 parent df64a9f commit 07371cd
Show file tree
Hide file tree
Showing 3 changed files with 120 additions and 0 deletions.
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"
}
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 ValveKeyValue/ValveKeyValue.Test/TextKV3/Kv1ToKv3TestCase.cs
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));
}
}
}

0 comments on commit 07371cd

Please sign in to comment.