Exemplo n.º 1
0
        public static ISigo SetN(ISigo sigo, IReadOnlyList <string> keys, ISigo value, int start)
        {
            switch (keys.Count - start)
            {
            case 0: return(value);

            case 1: return(sigo.Set1(keys[start], value));

            default: {
                var key = keys[start];
                return(sigo.Set1(key, SetN(sigo.Get1(key), keys, value, start + 1)));
            }
            }
        }
Exemplo n.º 2
0
        public static ISigo Solid(int lm1, ISigo b)
        {
            // {3} * {0, x:{3}}
            ISigo ret = null;

            // new if b not frozen or miss some lm1
            if (16 + lm1 != ((16 + lm1) & b.Flags))
            {
                ret = Sigo.Create(7 & (lm1 | b.Flags));
            }

            foreach (var e in b)
            {
                var k  = e.Key;
                var bk = e.Value;
                var rk = Solid(3, bk);
                if (ret != null)
                {
                    ret = ret.Set1(k, rk);
                }
                else
                {
                    if (ReferenceEquals(rk, bk))
                    {
                        continue;
                    }

                    ret = Sigo.Create(7 & (lm1 | b.Flags));
                    foreach (var t in b)
                    {
                        if (t.Key != k)
                        {
                            ret = ret.Set1(t.Key, t.Value);
                        }
                        else
                        {
                            ret = ret.Set1(k, rk);
                            break;
                        }
                    }
                }
            }

            return(ret ?? b);
        }
Exemplo n.º 3
0
        public void ChangeFlagsOnly()
        {
            var s0 = e0.Set1("k", e3).Freeze();

            // change parent proton by adding a child with L effect
            var s1 = s0.Set1("k2", e4).Freeze();

            SigoAssert.Equal(e3, s1.Get1("k"));
            SigoAssert.Equal(Bits.LM, s1.Flags & Bits.LMR);
        }
Exemplo n.º 4
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")));
        }
Exemplo n.º 5
0
        public static ISigo Set(ISigo sigo, string path, ISigo value)
        {
            if (string.IsNullOrEmpty(path))
            {
                return(value);
            }

            if (!Paths.ShouldSplit(path))
            {
                return(sigo.Set1(path, value));
            }

            var keys = Paths.Split(path);

            return(SetN(sigo, keys, value, 0));
        }
Exemplo n.º 6
0
 public void Return_self()
 {
     SigoAssert.Same(s, s.Set1("k", Sigo.Create(3)));
 }