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); }
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)); } } } }
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 }); }
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)); }
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()); }
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)); }
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"))); }
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); }
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 }); }
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)); }
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()); }
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()); } }
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); } }
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); } }
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); } }
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); } }
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); }
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/")); } }
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)); } } }
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")); } }
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); } }
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")); } } }
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); } } } }
public void Leaf_stringQuoteTests(string src, string value) { SigoAssert.Equal(Sigo.From(value), Sigo.Parse(src)); }
public void Leaf_boolTests(string src, bool value) { SigoAssert.Equal(Sigo.From(value), Sigo.Parse(src)); }
public void Leaf_numberTests(string src) { var num = double.Parse(src, CultureInfo.InvariantCulture); SigoAssert.Equal(Sigo.From(num), Sigo.Parse(src)); }
public ValueSchema(object value) { Value = Sigo.From(value); }
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")); }
public void AllowPathWithoutKeys_returnTheChild(string path) { var value = Sigo.From("child"); SigoAssert.Equal(value, Sigo.Create(3, path, value)); }
public void Return_the_child() { var sigo = Sigo.Create(0).Set1("k", Sigo.From("v")); SigoAssert.Equal("v", sigo.Get1("k").Data); }