Exemple #1
0
        public static ISigo Create(int lmr, params object[] pvs)
        {
            var i   = 0;
            var ret = Sigo.Create(lmr);

            while (i < pvs.Length)
            {
                var path  = Paths.ToPath(pvs[i++]);
                var value = Sigo.From(pvs[i++]);
                if (path == null)
                {
                    return(value);
                }

                if (path is string key)
                {
                    if (key == "")
                    {
                        return(value);
                    }

                    ret = ret.Set1(key, value);
                }
                else if (path is string[] keys)
                {
                    ret = ret.SetN(keys, value, 0);
                }
            }

            return(ret);
        }
Exemple #2
0
        public void If_sigosAreEqual_then_hashsAreEqual()
        {
            var sigos = new List <ISigo> {
                Sigo.From("a"),
                Sigo.From("a"),
                Sigo.From("b"),
                Sigo.Create(0),
                Sigo.Create(3),
                Sigo.Create(1, "x", "1", "y", "2").Freeze(),
                Sigo.Create(1, "y", "2", "x", "1"),
                Sigo.Create(1, "y", "2", "x", "2"),
                Sigo.Create(1, "diff", "2", "x", "1")
            };

            foreach (var a in sigos)
            {
                foreach (var b in sigos)
                {
                    if (a.Equals(b))
                    {
                        // THIS IS A MUST
                        SigoAssert.Equal(Hash(a), Hash(b));
                    }
                    else
                    {
                        // THIS IS A SHOULD
                        SigoAssert.NotEqual(Hash(a), Hash(b));
                    }
                }
            }
        }
Exemple #3
0
        public void ShouldEqual()
        {
            var a1 = Sigo.From(1);
            var a2 = Sigo.From(1);

            SigoAssert.Equal(a1, a2);
            SigoAssert.Equal(new[] { a1, a2 }, new[] { a2, a1 });
        }
Exemple #4
0
        public void Trees_only_compare_using_referenceEquals()
        {
            var tree1 = Sigo.Create(3).Set1("k", Sigo.From("v"));
            var tree2 = Sigo.Create(3).Set1("k", Sigo.From("v"));

            SigoAssert.True(Sigo.Same(tree1, tree1));

            SigoAssert.False(Sigo.Same(tree1, tree2));
        }
Exemple #5
0
        public void Frozen_return_self()
        {
            var leaf = Sigo.From("leaf");
            var e3   = Sigo.Create(3);
            var tree = Sigo.Create(3, "k", "v").Freeze();

            SigoAssert.Same(leaf, leaf.Clone());
            SigoAssert.Same(e3, e3.Clone());
            SigoAssert.Same(tree, tree.Clone());
        }
Exemple #6
0
        public void Leafs_compare_data_using_equals()
        {
            var v1 = Sigo.From("v");
            var v2 = Sigo.From("v");
            var x1 = Sigo.From("x");

            SigoAssert.True(Sigo.Same(v1, v1));
            SigoAssert.True(Sigo.Same(v1, v2));

            SigoAssert.False(Sigo.Same(v1, x1));
        }
Exemple #7
0
        public void Donot_createNewObject_ifNothingChange()
        {
            var v = Sigo.From("v");
            var s = e3.Set1("k", v).Freeze();

            SigoAssert.Same(s, s.Set1("k", v));
            SigoAssert.Same(s, s.Set1("k1", e3));
            SigoAssert.Same(s, s.Set1("k1", e7));

            // using Sigo.Same(), insteadOf referenceEquals
            SigoAssert.Same(s, s.Set1("k", Sigo.From("v")));
        }
Exemple #8
0
        public void See_createTests()
        {
            var user = Sigo.Create(1);

            user = user.Set("name/first", Sigo.From("Phat"));
            user = user.Set("name/last", Sigo.From("Dam"));
            user = user.Set("male", Sigo.From(true));

            SigoAssert.Equal("Phat", user.Get1("name").Get1("first").Data);
            SigoAssert.Equal("Dam", user.Get1("name").Get1("last").Data);
            SigoAssert.Equal(true, user.Get1("male").Data);
        }
Exemple #9
0
        public void ShouldNotEqual()
        {
            var a = Sigo.From(1);
            var b = Sigo.From(2);

            SigoAssert.NotEqual(a, b);

            SigoAssert.NotEqual(new[] { a }, new[] { b });
            SigoAssert.NotEqual(new[] { a }, new[] { b });

            SigoAssert.NotEqual(new[] { b, a }, new[] { b });
            SigoAssert.NotEqual(new[] { a }, new[] { a, b });
        }
Exemple #10
0
        public void Statements()
        {
            var src = "number=1|2; string='aa'|'bb'; 'ok'; number|string";

            var expected = new[] {
                Sigo.From(1),
                Sigo.From(2),
                Sigo.From("aa"),
                Sigo.From("bb")
            };

            SigoAssert.Equal(expected, Gen(src));
        }
Exemple #11
0
        public void NonEmptyTree_areNotFrozen_after_creating_or_changing()
        {
            // non empty tree are not frozen after creating
            SigoAssert.False(tree.IsFrozen());

            // not frozen after changing
            tree = tree.Freeze().Set1("v", Sigo.From("v+"));
            SigoAssert.False(tree.IsFrozen());

            // leafs and elements are frozen always frozen
            SigoAssert.True(leaf.IsFrozen());
            SigoAssert.True(e3.IsFrozen());
        }
Exemple #12
0
        public void Overrided_getHashCode()
        {
            var list = new List <ISigo> {
                Sigo.From("a"),
                Sigo.Create(7),
                Sigo.Create(3, "k", "a")
            };

            foreach (var a in list)
            {
                SigoAssert.Equal(Sigo.GetHashCode(a), a.GetHashCode());
            }
        }
Exemple #13
0
        public void Return_the_input_if_input_is_sigo()
        {
            var inputs = new object[] {
                Sigo.From("abc"),
                Sigo.Create(3),
                Sigo.Create(3).Set1("k", Sigo.From("v"))
            };

            foreach (var o in inputs)
            {
                var sigo = Sigo.From(o);

                SigoAssert.Same(o, sigo);
            }
        }
Exemple #14
0
        public void Numbers_are_convert_to_double()
        {
            var inputs = new object[] {
                (int)1,
                (long)1,
                (float)1,
                (double)1
            };

            foreach (var number in inputs)
            {
                var sigo = Sigo.From(number);

                SigoAssert.Equal(Convert.ToDouble(number), sigo.Data);
            }
        }
Exemple #15
0
        public void Return_leaf_if_input_is_scalar()
        {
            var inputs = new object[] {
                true, false,
                123.0,
                "",
                "abc"
            };

            foreach (var scalar in inputs)
            {
                var sigo = Sigo.From(scalar);

                SigoAssert.True(sigo.IsLeaf());
                SigoAssert.Equal(scalar, sigo.Data);
            }
        }
Exemple #16
0
        public void Convert_to_tree_if_input_is_enumerable()
        {
            var inputs = new object[] {
                new[] { "a", "b" },
                new List <string> {
                    "a", "b"
                }
            };

            foreach (var o in inputs)
            {
                var sigo = Sigo.From(o);

                SigoAssert.True(sigo.IsTree());
                SigoAssert.Equal("a", sigo.Get1("0").Data);
                SigoAssert.Equal("b", sigo.Get1("1").Data);
            }
        }
Exemple #17
0
        public GetTests()
        {
            V  = Sigo.From("V");
            A  = Sigo.Create(0).Set1("x", Sigo.From(1)).Set1("y", Sigo.From(2));
            B  = Sigo.Create(0).Set1("x", Sigo.From(3)).Set1("y", Sigo.From(4));
            AB = Sigo.Create(3, "A", A, "B", B);

            E = new ISigo[8];
            for (var i = 0; i < 8; i++)
            {
                E[i] = Sigo.Create(i);
            }

            All = new List <ISigo> {
                A, B, AB, V
            };
            All.AddRange(E);
        }
Exemple #18
0
        public void Throws_if_null_empty_or_has_slash()
        {
            // TODO this behaviour take some cpu cost. Add UnsafeGet1()?
            var sigos = new List <ISigo> {
                Sigo.From("v"),
                Sigo.Create(0),
                Sigo.Create(1),
                Sigo.Create(0).Set1("k", Sigo.From("v")),
                Sigo.Create(1).Set1("k", Sigo.From("v"))
            };

            foreach (var sigo in sigos)
            {
                SigoAssert.ThrowsAny <Exception>(() => sigo.Get1(null));
                SigoAssert.ThrowsAny <Exception>(() => sigo.Get1(""));
                SigoAssert.ThrowsAny <Exception>(() => sigo.Get1("/"));
                SigoAssert.ThrowsAny <Exception>(() => sigo.Get1("x/"));
            }
        }
Exemple #19
0
        public void Overrided_equal_object()
        {
            var list = new List <ISigo> {
                Sigo.From("a"),
                Sigo.From("a"),
                Sigo.From("b"),
                Sigo.Create(3, "k", "a"),
                Sigo.Create(3, "k", "a"),
                Sigo.Create(3, "k", "b")
            };

            foreach (var a in list)
            {
                foreach (var b in list)
                {
                    SigoAssert.Equal(Sigo.Equals(a, b), a.Equals((object)b));
                }
            }
        }
Exemple #20
0
        public void Return_treeWith1Child()
        {
            var values = new List <ISigo> {
                Sigo.From("v"),
                Sigo.Create(0),
                Sigo.Create(1),
                Sigo.Create(2),
                Sigo.Create(3, "k", Sigo.Create(0)),
                Sigo.Create(4),
                Sigo.Create(5),
                Sigo.Create(6),
                Sigo.Create(7, "k", "v")
            };

            foreach (var v in values)
            {
                var ret = s.Set1("k", v);
                SigoAssert.Same(v, ret.Get1("k"));
            }
        }
Exemple #21
0
        public void Convert_to_tree_if_input_is_dictionary()
        {
            var inputs = new object[] {
                new Hashtable()
                {
                    { "k", "v" }
                },
                new Dictionary <string, object>()
                {
                    { "k", "v" }
                }
            };

            foreach (var o in inputs)
            {
                var sigo = Sigo.From(o);

                SigoAssert.True(sigo.IsTree());
                SigoAssert.Equal("v", sigo.Get1("k").Data);
            }
        }
Exemple #22
0
        public void Return_default()
        {
            var sigos = new List <ISigo> {
                Sigo.From("v"),
                Sigo.Create(0),
                Sigo.Create(1),
                Sigo.Create(0).Set1("k", Sigo.From("v")),
                Sigo.Create(1).Set1("k", Sigo.From("v"))
            };

            foreach (var sigo in sigos)
            {
                if ((sigo.Flags & Bits.R) == Bits.R)
                {
                    SigoAssert.Equal(Sigo.Create(3), sigo.Get1("nonExists"));
                }
                else
                {
                    SigoAssert.Equal(Sigo.Create(0), sigo.Get1("nonExists"));
                }
            }
        }
Exemple #23
0
        public void Compare_aListOf_differenceValues()
        {
            var diffs = new List <ISigo> {
                Sigo.From(true),
                Sigo.From(false),
                Sigo.From(1),
                Sigo.From(2),
                Sigo.From("a"),
                Sigo.From("b")
            };

            for (var i = 0; i < 8; i++)
            {
                diffs.Add(Sigo.Create(i));
            }

            diffs.Add(Sigo.Create(0, "x", 1));
            diffs.Add(Sigo.Create(0, "x", 2));
            diffs.Add(Sigo.Create(0, "y", 1));
            diffs.Add(Sigo.Create(0, "y", 2));

            diffs.Add(Sigo.Create(3, "x", 1));
            diffs.Add(Sigo.Create(3, "x", 2));
            diffs.Add(Sigo.Create(3, "y", 1));
            diffs.Add(Sigo.Create(3, "y", 2));

            foreach (var a in diffs)
            {
                foreach (var b in diffs)
                {
                    if (!a.Same(b))
                    {
                        SigoAssert.NotEqual(a, b);
                    }
                }
            }
        }
Exemple #24
0
 public void Leaf_stringQuoteTests(string src, string value)
 {
     SigoAssert.Equal(Sigo.From(value), Sigo.Parse(src));
 }
Exemple #25
0
 public void Leaf_boolTests(string src, bool value)
 {
     SigoAssert.Equal(Sigo.From(value), Sigo.Parse(src));
 }
Exemple #26
0
        public void Leaf_numberTests(string src)
        {
            var num = double.Parse(src, CultureInfo.InvariantCulture);

            SigoAssert.Equal(Sigo.From(num), Sigo.Parse(src));
        }
Exemple #27
0
 public ValueSchema(object value)
 {
     Value = Sigo.From(value);
 }
Exemple #28
0
 public void Leafs_compare_theirData()
 {
     SigoAssert.Equal(Sigo.From(10000), Sigo.From(10000));
     SigoAssert.Equal(Sigo.From(true), Sigo.From(true));
     SigoAssert.Equal(Sigo.From("abc"), Sigo.From("abc"));
 }
Exemple #29
0
        public void AllowPathWithoutKeys_returnTheChild(string path)
        {
            var value = Sigo.From("child");

            SigoAssert.Equal(value, Sigo.Create(3, path, value));
        }
Exemple #30
0
        public void Return_the_child()
        {
            var sigo = Sigo.Create(0).Set1("k", Sigo.From("v"));

            SigoAssert.Equal("v", sigo.Get1("k").Data);
        }