Beispiel #1
0
        public void Null()
        {
            var buffer = JsonToFlexBufferConverter.Convert("null");
            var flx    = FlxValue.FromBytes(buffer);

            Assert.AreEqual(true, flx.IsNull);
        }
        public void MultipleLineWithSpecialSeparatorAndDoubleQuotesEscapingLineBreak()
        {
            var bytes = CsvToFlexBufferConverter.Convert(
                @"A;B;C
1;2;3
""ds
kfsdh"";sdfsdf;sdfsf
", ';');
            var flx  = FlxValue.FromBytes(bytes);
            var json = flx.ToJson;

            Assert.AreEqual(flx.AsVector.Length, 3);
            Assert.AreEqual(flx[0].AsVector.Length, 3);
            Assert.AreEqual(flx[0][0].AsString, "A");
            Assert.AreEqual(flx[0][1].AsString, "B");
            Assert.AreEqual(flx[0][2].AsString, "C");

            Assert.AreEqual(flx[1][0].AsString, "1");
            Assert.AreEqual(flx[1][1].AsString, "2");
            Assert.AreEqual(flx[1][2].AsString, "3");

            Assert.AreEqual(flx[2][0].AsString, "ds\nkfsdh");
            Assert.AreEqual(flx[2][1].AsString, "sdfsdf");
            Assert.AreEqual(flx[2][2].AsString, "sdfsf");
        }
Beispiel #3
0
        public void SmallIntVectorAndNestedVector()
        {
            var bytes = FlexBufferBuilder.Vector(v1 =>
            {
                v1.Add(1);
                v1.Add(2);
                v1.Add(3);
                v1.Add(4);
                v1.Add(5);
                v1.Vector(v2 => {
                    v2.Add("hello");
                    v2.Add("world");
                });
            });

            var flx = FlxValue.FromBytes(bytes);

            Assert.AreEqual(6, flx.AsVector.Length);
            Assert.AreEqual(1, flx[0].AsLong);
            Assert.AreEqual(2, flx[1].AsLong);
            Assert.AreEqual(3, flx[2].AsLong);
            Assert.AreEqual(4, flx[3].AsLong);
            Assert.AreEqual(5, flx[4].AsLong);
            Assert.AreEqual(2, flx[5].AsVector.Length);
            Assert.AreEqual("hello", flx[5][0].AsString);
            Assert.AreEqual("world", flx[5][1].AsString);
        }
Beispiel #4
0
        public void TestOffsetAndLengthAreOfTypeULong()
        {
            var json = @"{""channels_in"":64,""dilation_height_factor"":1,""dilation_width_factor"":1,""fused_activation_function"":1,""pad_values"":1,""padding"":0,""stride_height"":1,""stride_width"":1}";
            var flx  = FlxValue.FromBytes(new byte[] { 99, 104, 97, 110, 110, 101, 108, 115, 95, 105, 110, 0, 100, 105, 108, 97, 116, 105, 111, 110, 95, 104, 101, 105, 103, 104, 116, 95, 102, 97, 99, 116, 111, 114, 0, 100, 105, 108, 97, 116, 105, 111, 110, 95, 119, 105, 100, 116, 104, 95, 102, 97, 99, 116, 111, 114, 0, 102, 117, 115, 101, 100, 95, 97, 99, 116, 105, 118, 97, 116, 105, 111, 110, 95, 102, 117, 110, 99, 116, 105, 111, 110, 0, 112, 97, 100, 95, 118, 97, 108, 117, 101, 115, 0, 112, 97, 100, 100, 105, 110, 103, 0, 115, 116, 114, 105, 100, 101, 95, 104, 101, 105, 103, 104, 116, 0, 115, 116, 114, 105, 100, 101, 95, 119, 105, 100, 116, 104, 0, 8, 130, 119, 97, 76, 51, 41, 34, 21, 8, 1, 8, 64, 1, 1, 1, 1, 0, 1, 1, 4, 4, 4, 4, 4, 4, 4, 4, 16, 36, 1 });

            Assert.AreEqual(json, flx.ToJson);
        }
Beispiel #5
0
        public void EmptyVector()
        {
            var buffer = JsonToFlexBufferConverter.Convert("[]");
            var flx    = FlxValue.FromBytes(buffer);

            Assert.AreEqual(0, flx.AsVector.Length);
        }
Beispiel #6
0
        private void CheckBool(bool value)
        {
            var bytes = FlexBuffer.SingleValue(value);
            var flx   = FlxValue.FromBytes(bytes);

            Assert.AreEqual(value, flx.AsBool);
        }
        public void LongStringArray()
        {
            var s1 = new StringBuilder();

            for (int i = 0; i < 260; i++)
            {
                s1.Append("a");
            }
            var s2 = new StringBuilder();

            for (int i = 0; i < 260000; i++)
            {
                s2.Append("b");
            }

            var list = new List <string>(2)
            {
                s1.ToString(), s2.ToString()
            };

            var bytes = FlexBuffer.From(list);

            var flx = FlxValue.FromBytes(bytes);

            Assert.AreEqual(2, flx.AsVector.Length);
            Assert.AreEqual(s1.ToString(), flx[0].AsString);
            Assert.AreEqual(s2.ToString(), flx[1].AsString);
        }
Beispiel #8
0
        private void CheckString(string value)
        {
            var bytes = FlexBuffer.SingleValue(value);
            var flx   = FlxValue.FromBytes(bytes);

            Assert.AreEqual(value, flx.AsString);
        }
Beispiel #9
0
        public void Int()
        {
            var buffer = JsonToFlexBufferConverter.Convert("3456");
            var flx    = FlxValue.FromBytes(buffer);

            Assert.AreEqual(3456, flx.AsLong);
        }
Beispiel #10
0
        private void CheckULongAsBool(ulong value)
        {
            var bytes = FlexBuffer.SingleValue(value);
            var flx   = FlxValue.FromBytes(bytes);

            Assert.AreEqual(value != 0, flx.AsBool);
        }
Beispiel #11
0
        public void TestPrettyJsonMap()
        {
            var dict = new Dictionary <string, object>()
            {
                { "a", 1 },
                { "b", 2 },
                { "c", 3 },
                { "d", new [] { 1, 2, 3 } }
            };

            var expected = @"{
  ""a"" : 1,
  ""b"" : 2,
  ""c"" : 3,
  ""d"" : [
    1,
    2,
    3
  ]
}".Replace("\r", "");
            var bytes    = FlexBuffer.From(dict);
            var flx      = FlxValue.FromBytes(bytes);

            Assert.AreEqual(expected, flx.ToPrettyJson());
        }
Beispiel #12
0
        private void CheckDouble(double value)
        {
            var bytes = FlexBuffer.SingleValue(value);
            var flx   = FlxValue.FromBytes(bytes);

            Assert.AreEqual(value, flx.AsDouble);
        }
Beispiel #13
0
        public void ComplexMap()
        {
            var value = new Dictionary <string, dynamic>()
            {
                { "age", 35 },
                { "flags", new[] { true, false, true, true } },
                { "weight", 72.5 },
                { "name", "Maxim" },
                { "address", new Dictionary <string, dynamic>()
                  {
                      { "city", "Bla" },
                      { "zip", "12345" },
                      { "countryCode", "XX" },
                  } },
            };
            var bytes = FlexBuffer.From(value);
            var flx   = FlxValue.FromBytes(bytes);

            Assert.AreEqual(value.Count, flx.AsMap.Length);

            Assert.AreEqual(35, flx["age"].AsLong);
            Assert.AreEqual(72.5, flx["weight"].AsDouble);
            Assert.AreEqual("Maxim", flx["name"].AsString);

            Assert.AreEqual(4, flx["flags"].AsVector.Length);
            Assert.AreEqual(true, flx["flags"][0].AsBool);
            Assert.AreEqual(false, flx["flags"][1].AsBool);
            Assert.AreEqual(true, flx["flags"][2].AsBool);
            Assert.AreEqual(true, flx["flags"][3].AsBool);

            Assert.AreEqual(3, flx["address"].AsMap.Length);
            Assert.AreEqual("Bla", flx["address"]["city"].AsString);
            Assert.AreEqual("12345", flx["address"]["zip"].AsString);
            Assert.AreEqual("XX", flx["address"]["countryCode"].AsString);
        }
Beispiel #14
0
        public void NegativeFloat()
        {
            var buffer = JsonToFlexBufferConverter.Convert("-34.56");
            var flx    = FlxValue.FromBytes(buffer);

            Assert.AreEqual(-34.56, flx.AsDouble);
        }
Beispiel #15
0
        public void VectorOfMaps()
        {
            const string json  = @"
[
    {""name"": ""Max"", ""age"": 38},
    {""name"": ""Maxim"", ""age"": 35},
    {""age"": 18, ""name"": ""Alex""}
]
";
            var          bytes = JsonToFlexBufferConverter.Convert(json);
            var          flx   = FlxValue.FromBytes(bytes);

            Assert.AreEqual(3, flx.AsVector.Length);

            Assert.AreEqual(2, flx[0].AsMap.Length);
            Assert.AreEqual("Max", flx[0]["name"].AsString);
            Assert.AreEqual(38, flx[0]["age"].AsLong);

            Assert.AreEqual(2, flx[1].AsMap.Length);
            Assert.AreEqual("Maxim", flx[1]["name"].AsString);
            Assert.AreEqual(35, flx[1]["age"].AsLong);

            Assert.AreEqual(2, flx[2].AsMap.Length);
            Assert.AreEqual("Alex", flx[2]["name"].AsString);
            Assert.AreEqual(18, flx[2]["age"].AsLong);
        }
Beispiel #16
0
        public void EmptyMap()
        {
            var buffer = JsonToFlexBufferConverter.Convert("{}");
            var flx    = FlxValue.FromBytes(buffer);

            Assert.AreEqual(0, flx.AsMap.Length);
        }
Beispiel #17
0
        public void Null()
        {
            var bytes = FlexBuffer.Null();
            var flx   = FlxValue.FromBytes(bytes);

            Assert.AreEqual(true, flx.IsNull);
        }
Beispiel #18
0
 public FlxValueTreeViewItem(FlxValue value, int depth = 0, FlxValueTreeViewItem parent = null, string key = "", FlxQuery query = null)
 {
     FlxValue = value;
     _depth   = depth;
     _parent  = parent;
     _key     = key;
     _query   = query;
 }
Beispiel #19
0
        public void Blob()
        {
            var value = new byte[] { 1, 2, 3, 4 };
            var bytes = FlexBuffer.SingleValue(value);
            var flx   = FlxValue.FromBytes(bytes);

            Assert.AreEqual(value, flx.AsBlob);
        }
Beispiel #20
0
        public void OneKeyMap()
        {
            var buffer = JsonToFlexBufferConverter.Convert("{\"\":1}");
            var flx    = FlxValue.FromBytes(buffer);

            Assert.AreEqual(1, flx.AsMap.Length);
            Assert.AreEqual(1, flx[""].AsLong);
        }
Beispiel #21
0
        public void BlobToJson()
        {
            var value = new byte[] { 1, 2, 3, 4 };
            var bytes = FlexBuffer.SingleValue(value);
            var flx   = FlxValue.FromBytes(bytes);

            Assert.AreEqual("\"AQIDBA==\"", flx.ToJson);
            Assert.AreEqual(value, Convert.FromBase64String("AQIDBA=="));
        }
Beispiel #22
0
        public void TwoKeysMap()
        {
            var buffer = JsonToFlexBufferConverter.Convert("{\"a\":1, \"b\":2}");
            var flx    = FlxValue.FromBytes(buffer);

            Assert.AreEqual(2, flx.AsMap.Length);
            Assert.AreEqual(1, flx["a"].AsLong);
            Assert.AreEqual(2, flx["b"].AsLong);
        }
        public void SingleTagWithAttributes()
        {
            var bytes = XmlToFlexBufferConverter.Convert("<tag1 a=\"123\" b=\"321\"/>");

            var flx = FlxValue.FromBytes(bytes);

            Assert.AreEqual(3, flx.AsMap.Length);
            Assert.AreEqual("tag1", flx["tagName"].AsString);
            Assert.AreEqual("123", flx["a"].AsString);
            Assert.AreEqual("321", flx["b"].AsString);
        }
        public void SimpleCSV()
        {
            var bytes = CsvToFlexBufferConverter.Convert("A,B,C");
            var flx   = FlxValue.FromBytes(bytes);

            Assert.AreEqual(flx.AsVector.Length, 1);
            Assert.AreEqual(flx[0].AsVector.Length, 3);
            Assert.AreEqual(flx[0][0].AsString, "A");
            Assert.AreEqual(flx[0][1].AsString, "B");
            Assert.AreEqual(flx[0][2].AsString, "C");
        }
Beispiel #25
0
        public void IntArray()
        {
            var value = new[] { 1, 2, 3, -1 };
            var bytes = FlexBuffer.From(value);
            var flx   = FlxValue.FromBytes(bytes);

            Assert.AreEqual(value.Length, flx.AsVector.Length);
            for (var i = 0; i < value.Length; i++)
            {
                Assert.AreEqual(value[i], flx[i].AsLong, $"Not equal at index {i}");
            }
        }
        public void ComplexXml()
        {
            var xml   = @"<?xml version=""1.0""?>
<!-- This is a sample XML document -->
<!DOCTYPE Items [<!ENTITY number ""123"">]>
<Items>
<Item>Test with an entity: &number;</Item>
<Item>Test with a child element <more/> stuff</Item>
<Item>Test with a CDATA section <![CDATA[<456>]]> def</Item>
<Item>Test with a char entity: &#65;</Item>
<!-- Fourteen chars in this element.-->
<Item>1234567890ABCD</Item>
</Items>
";
            var bytes = XmlToFlexBufferConverter.Convert(xml);

            var flx = FlxValue.FromBytes(bytes);

            Assert.AreEqual(2, flx.AsMap.Length);
            Assert.AreEqual("Items", flx["tagName"].AsString);
            Assert.AreEqual(5, flx["children"].AsVector.Length);

            Assert.AreEqual(2, flx["children"][0].AsMap.Length);
            Assert.AreEqual("Item", flx["children"][0]["tagName"].AsString);
            Assert.AreEqual(2, flx["children"][0]["children"].AsVector.Length);
            Assert.AreEqual("Test with an entity: ", flx["children"][0]["children"][0].AsString);
            Assert.AreEqual(2, flx["children"][0]["children"][1].AsMap.Length);
            Assert.AreEqual("number", flx["children"][0]["children"][1]["tagName"].AsString);
            Assert.AreEqual(1, flx["children"][0]["children"][1]["children"].AsVector.Length);
            Assert.AreEqual("123", flx["children"][0]["children"][1]["children"][0].AsString);

            Assert.AreEqual("Item", flx["children"][1]["tagName"].AsString);
            Assert.AreEqual(3, flx["children"][1]["children"].AsVector.Length);
            Assert.AreEqual("Test with a child element ", flx["children"][1]["children"][0].AsString);
            Assert.AreEqual(1, flx["children"][1]["children"][1].AsMap.Length);
            Assert.AreEqual("more", flx["children"][1]["children"][1]["tagName"].AsString);
            Assert.AreEqual(" stuff", flx["children"][1]["children"][2].AsString);

            Assert.AreEqual("Item", flx["children"][2]["tagName"].AsString);
            Assert.AreEqual(3, flx["children"][2]["children"].AsVector.Length);
            Assert.AreEqual("Test with a CDATA section ", flx["children"][2]["children"][0].AsString);
            Assert.AreEqual("<456>", flx["children"][2]["children"][1].AsString);
            Assert.AreEqual(" def", flx["children"][2]["children"][2].AsString);

            Assert.AreEqual("Item", flx["children"][3]["tagName"].AsString);
            Assert.AreEqual(1, flx["children"][3]["children"].AsVector.Length);
            Assert.AreEqual("Test with a char entity: A", flx["children"][3]["children"][0].AsString);

            Assert.AreEqual("Item", flx["children"][4]["tagName"].AsString);
            Assert.AreEqual(1, flx["children"][4]["children"].AsVector.Length);
            Assert.AreEqual("1234567890ABCD", flx["children"][4]["children"][0].AsString);
        }
Beispiel #27
0
        public void BoolArray()
        {
            var value = new[] { true, false, true, true };
            var bytes = FlexBuffer.From(value);
            var flx   = FlxValue.FromBytes(bytes);

            Assert.AreEqual(value.Length, flx.AsVector.Length);
            for (var i = 0; i < value.Length; i++)
            {
                var v = flx[i].AsBool;
                Assert.AreEqual(value[i], v, $"Not equal at index {i}");
            }
        }
Beispiel #28
0
        public void StringArray()
        {
            var value = new[] { "Max", "Maxim", "Alex", "Hi 😂🤣😍🤪" };
            var bytes = FlexBuffer.From(value);
            var flx   = FlxValue.FromBytes(bytes);

            Assert.AreEqual(value.Length, flx.AsVector.Length);
            for (var i = 0; i < value.Length; i++)
            {
                var v = flx[i].AsString;
                Assert.AreEqual(value[i], v, $"Not equal at index {i}");
            }
        }
Beispiel #29
0
        public void MixedVector()
        {
            var buffer = JsonToFlexBufferConverter.Convert("[null, true, false, \"hello 🙀\", -34, 6.1]");
            var flx    = FlxValue.FromBytes(buffer);

            Assert.AreEqual(6, flx.AsVector.Length);
            Assert.AreEqual(true, flx[0].IsNull);
            Assert.AreEqual(true, flx[1].AsBool);
            Assert.AreEqual(false, flx[2].AsBool);
            Assert.AreEqual("hello 🙀", flx[3].AsString);
            Assert.AreEqual(-34, flx[4].AsLong);
            Assert.AreEqual(6.1, flx[5].AsDouble);
        }
Beispiel #30
0
        public void IterateOverVector()
        {
            var ints  = new[] { 1, 2, 3 };
            var bytes = FlexBuffer.From(ints);
            var flx   = FlxValue.FromBytes(bytes);
            var i     = 0;

            foreach (var value in flx.AsVector)
            {
                Assert.AreEqual(ints[i], value.AsLong);
                i++;
            }
            Assert.AreEqual(3, i);
        }