private static string PerformNewLineTest(string value, bool hasEscapeSequences)
        {
            KvObject convertedKv;
            var      kv      = new KvObject("newLineTestCase", value);
            var      options = new KvSerializerOptions {
                HasEscapeSequences = hasEscapeSequences
            };

            string text;

            using (var ms = new MemoryStream())
            {
                var serializer = KvSerializer.Create(KvSerializationFormat.KeyValues1Text);

                serializer.Serialize(ms, kv, options);

                ms.Seek(0, SeekOrigin.Begin);

                text = Encoding.ASCII.GetString(ms.ToArray(), 0, (int)ms.Length);

                convertedKv = serializer.Deserialize(ms, options);
            }

            Assert.That((string)convertedKv.Value, Is.EqualTo(value));

            return(text);
        }
        public void SetUp()
        {
            var data = new byte[]
            {
                0x00, // object: TestObject
                0x54, 0x65, 0x73, 0x74, 0x4F, 0x62, 0x6A, 0x65, 0x63, 0x74, 0x00,
                0x01, // string: key = value
                0x6B, 0x65, 0x79, 0x00,
                0x76, 0x61, 0x6C, 0x75, 0x65, 0x00,
                0x02,     // int32: int = 0x01020304
                0x69, 0x6E, 0x74, 0x00,
                0x04, 0x03, 0x02, 0x01,
                0x03,     // float32: flt = 1234.5678f
                0x66, 0x6C, 0x74, 0x00,
                0x2B, 0x52, 0x9A, 0x44,
                0x04,     // color: col = 0x10203040
                0x63, 0x6F, 0x6C, 0x00,
                0x40, 0x30, 0x20, 0x10,
                0x06,     // pointer: ptr = 0x11223344
                0x70, 0x74, 0x72, 0x00,
                0x44, 0x33, 0x22, 0x11,
                0x07,     // uint64: long = 0x1122334455667788
                0x6C, 0x6E, 0x67, 0x00,
                0x88, 0x77, 0x66, 0x55, 0x44, 0x33, 0x22, 0x11,
                0x0A,     // int64, i64 = 0x0102030405070809
                0x69, 0x36, 0x34, 0x00,
                0x08, 0x07, 0x06, 0x05, 0x04, 0x03, 0x02, 0x01,
                0x08, // end object
                0x08, // end document
            };

            _obj = KvSerializer.Create(KvSerializationFormat.KeyValues1Binary).Deserialize(data);
        }
Esempio n. 3
0
        public object ConvertingObjectWithChildren(Type type)
        {
            var kv = new KvObject(
                "aaa",
                new[] { new KvObject("bbb", "ccc") });

            return(Convert.ChangeType(kv.Value, type));
        }
Esempio n. 4
0
        public void SetUp()
        {
            var options = new KvSerializerOptions {
                FileLoader = new StubIncludedFileLoader()
            };

            using (var stream = TestDataHelper.OpenResource("Text.kv_with_include.vdf"))
                _data = KvSerializer.Create(KvSerializationFormat.KeyValues1Text).Deserialize(stream, options);
        }
        public void SetUp()
        {
            var options = new KvSerializerOptions {
                HasEscapeSequences = true
            };

            using (var stream = TestDataHelper.OpenResource("Text.escaped_backslash.vdf"))
                _data = KvSerializer.Create(KvSerializationFormat.KeyValues1Text).Deserialize(stream, options);
        }
Esempio n. 6
0
        public void ConvertingObjectWithChildrenIsNotSupported(Type type)
        {
            var kv = new KvObject(
                "aaa",
                new[] { new KvObject("bbb", "ccc") });

            Assert.That(
                () => Convert.ChangeType(kv.Value, type),
                Throws.Exception.TypeOf <NotSupportedException>());
        }
Esempio n. 7
0
 public void SetUp()
 {
     _data = new KvObject(
         "test data",
         new[]
     {
         new KvObject("foo", "bar"),
         new KvObject("bar", "baz"),
         new KvObject("baz", "-"),
     });
 }
        public void SerializesToBinaryStructure()
        {
            var kvo = new KvObject("TestObject", new[]
            {
                new KvObject("key", "value"),
                new KvObject("key_utf8", "邪恶的战"),
                new KvObject("int", 0x10203040),
                new KvObject("flt", 1234.5678f),
                new KvObject("ptr", new IntPtr(0x12345678)),
                new KvObject("lng", 0x8877665544332211u),
                new KvObject("i64", 0x0102030405060708)
            });

            var expectedData = new byte[]
            {
                0x00, // object: TestObject
                0x54, 0x65, 0x73, 0x74, 0x4F, 0x62, 0x6A, 0x65, 0x63, 0x74, 0x00,
                0x01, // string: key = value
                0x6B, 0x65, 0x79, 0x00,
                0x76, 0x61, 0x6C, 0x75, 0x65, 0x00,
                0x01,     // string_utf8: key_utf8 = 邪恶的战
                0x6B, 0x65, 0x79, 0x5F, 0x75, 0x74, 0x66, 0x38, 0x00,
                0xE9, 0x82, 0xAA, 0xE6, 0x81, 0xB6, 0xE7, 0x9A, 0x84, 0xE6, 0x88, 0x98, 0x00,
                0x02,     // int32: int = 0x10203040
                0x69, 0x6E, 0x74, 0x00,
                0x40, 0x30, 0x20, 0x10,
                0x03,     // float32: flt = 1234.5678f
                0x66, 0x6C, 0x74, 0x00,
                0x2B, 0x52, 0x9A, 0x44,
                0x04,     // pointer: ptr = 0x12345678
                0x70, 0x74, 0x72, 0x00,
                0x78, 0x56, 0x34, 0x12,
                0x07,     // uint64: lng = 0x8877665544332211
                0x6C, 0x6E, 0x67, 0x00,
                0x11, 0x22, 0x33, 0x44, 0x55, 0x66, 0x77, 0x88,
                0x0A,     // int64, i64 = 0x0102030405070809
                0x69, 0x36, 0x34, 0x00,
                0x08, 0x07, 0x06, 0x05, 0x04, 0x03, 0x02, 0x01,
                0x08, // end object
                0x08, // end document
            };

            using (var ms = new MemoryStream())
            {
                KvSerializer.Create(KvSerializationFormat.KeyValues1Binary).Serialize(ms, kvo);

                Assert.That(ms.ToArray(), Is.EqualTo(expectedData));
            }
        }
Esempio n. 9
0
 private static void Merge(KvObject from, KvObject into)
 {
     foreach (var child in from)
     {
         var matchingChild = into.Children.FirstOrDefault(c => c.Name == child.Name);
         if (matchingChild == null && into.Value.ValueType == KvValueType.Collection)
         {
             into.Add(child);
         }
         else
         {
             Merge(child, matchingChild);
         }
     }
 }
Esempio n. 10
0
        public void CreatesTextDocument()
        {
            var kv = new KvObject(
                "test data",
                new[]
            {
                new KvObject(
                    "0",
                    new[]
                {
                    new KvObject("description", "Dota 2 is a complex game where you get sworn at\nin Russian all the time."),
                    new KvObject("developer", "Valve Software"),
                    new KvObject("name", "Dota 2")
                }),
                new KvObject(
                    "1",
                    new[]
                {
                    new KvObject("description", "Known as \"America's #1 war-themed hat simulator\", this game lets you wear stupid items while killing people."),
                    new KvObject("developer", "Valve Software"),
                    new KvObject("name", "Team Fortress 2")
                })
            });

            string text;

            using (var ms = new MemoryStream())
            {
                KvSerializer.Create(KvSerializationFormat.KeyValues1Text).Serialize(ms, kv);

                ms.Seek(0, SeekOrigin.Begin);
                using (var reader = new StreamReader(ms))
                    text = reader.ReadToEnd();
            }

            var expected = TestDataHelper.ReadTextResource("Text.serialization_expected.vdf");

            Assert.That(text, Is.EqualTo(expected));
        }
Esempio n. 11
0
        public void SerializesToBinaryStructure()
        {
            var first = new KvObject("FirstObject", new[]
            {
                new KvObject("firstkey", "firstvalue")
            });

            var second = new KvObject("SecondObject", new[]
            {
                new KvObject("secondkey", "secondvalue")
            });

            var expectedData = new byte[]
            {
                0x00, // object: FirstObject
                0x46, 0x69, 0x72, 0x73, 0x74, 0x4f, 0x62, 0x6a, 0x65, 0x63, 0x74, 0x00,
                0x01, // string: firstkey = firstvalue
                0x66, 0x69, 0x72, 0x73, 0x74, 0x6b, 0x65, 0x79, 0x00,
                0x66, 0x69, 0x72, 0x73, 0x74, 0x76, 0x61, 0x6c, 0x75, 0x65, 0x00,
                0x08, // end object
                0x08, // end document

                0x00, // object: SecondObject
                0x53, 0x65, 0x63, 0x6f, 0x6e, 0x64, 0x4f, 0x62, 0x6a, 0x65, 0x63, 0x74, 0x00,
                0x01, // string: secondkey = secondvalue
                0x73, 0x65, 0x63, 0x6f, 0x6e, 0x64, 0x6b, 0x65, 0x79, 0x00,
                0x73, 0x65, 0x63, 0x6f, 0x6e, 0x64, 0x76, 0x61, 0x6c, 0x75, 0x65, 0x00,
                0x08, // end object
                0x08, // end document
            };

            using (var stream = new MemoryStream())
            {
                KvSerializer.Create(KvSerializationFormat.KeyValues1Binary).Serialize(stream, first);
                KvSerializer.Create(KvSerializationFormat.KeyValues1Binary).Serialize(stream, second);
                Assert.That(stream.ToArray(), Is.EqualTo(expectedData));
            }
        }
Esempio n. 12
0
        public void Int16Failure(string value)
        {
            var kv = new KvObject("aaa", value);

            Assert.That(() => (short)kv.Value, Throws.Exception.TypeOf <FormatException>().Or.TypeOf <OverflowException>());
        }
Esempio n. 13
0
 public void SetUp()
 {
     _data = new KvObject("foo", "bar");
 }
 public void SetUp()
 {
     using (var stream = TestDataHelper.OpenResource("Text.unquoted_document.vdf"))
         _data = KvSerializer.Create(KvSerializationFormat.KeyValues1Text).Deserialize(stream);
 }
Esempio n. 15
0
 public void Visit(KvObject @object)
 {
     VisitObject(@object.Name, @object.Value);
 }
Esempio n. 16
0
        public void BooleanSuccess(string value, bool expected)
        {
            var kv = new KvObject("aaa", value);

            Assert.That((bool)kv.Value, Is.EqualTo(expected));
        }
Esempio n. 17
0
        public void UInt64Success(string value, ulong expected)
        {
            var kv = new KvObject("aaa", value);

            Assert.That((ulong)kv.Value, Is.EqualTo(expected));
        }
 public void SetUp()
 {
     using (var stream = TestDataHelper.OpenResource("Text.escaped_quotation_marks.vdf"))
         _data = KvSerializer.Create(KvSerializationFormat.KeyValues1Text).Deserialize(stream);
 }
Esempio n. 19
0
        public void ByteSuccess(string value, byte expected)
        {
            var kv = new KvObject("aaa", value);

            Assert.That((byte)kv.Value, Is.EqualTo(expected));
        }
Esempio n. 20
0
        public void CharSuccess(string value)
        {
            var kv = new KvObject("aaa", value);

            Assert.That((char)kv.Value, Is.EqualTo(value[0]));
        }
Esempio n. 21
0
        public void CharFailure(string value)
        {
            var kv = new KvObject("aaa", value);

            Assert.That(() => (char)kv.Value, Throws.Exception.TypeOf <FormatException>());
        }
 public void SetUp()
 {
     using (var stream = TestDataHelper.OpenResource("Text.escaped_backslash_not_special.vdf"))
         _data = KvSerializer.Create(KvSerializationFormat.KeyValues1Text).Deserialize(stream);
 }
Esempio n. 23
0
        public void Int16Success(string value, short expected)
        {
            var kv = new KvObject("aaa", value);

            Assert.That((short)kv.Value, Is.EqualTo(expected));
        }
Esempio n. 24
0
 public void AddItem(KvObject item) => CurrentObject.Items.Add(item);
Esempio n. 25
0
 public void SetUp()
 {
     _data = new TReader().Read("Text.legacydepotdata_subset.vdf");
 }