示例#1
0
        public void SectionMerge_6()
        {
            var conf1 = "r{ a{} c{}}".AsLaconicConfig(handling: ConvertErrorHandling.Throw);
              var conf2 = "r{ b{ z = 134 } c{name='id1' y=456} c{name='id2' z=789 } c{ gg=123}}".AsLaconicConfig(handling: ConvertErrorHandling.Throw);

              var rules = new NodeOverrideRules{ AppendSectionsWithoutMatchAttr = true };
              conf1.OverrideBy(conf2, rules);

              Assert.AreEqual(6, conf1.ChildCount); //<-- 6 because names are different, but 6th gets added due to rules
              Assert.IsTrue( conf1.Navigate("/a").Exists);
              Assert.IsTrue( conf1.Navigate("/b").Exists);
              Assert.IsTrue( conf1.Navigate("/c").Exists);
              Assert.IsTrue( conf1.Navigate("/c[name=id1]").Exists);
              Assert.IsTrue( conf1.Navigate("/c[name=id2]").Exists);
              Assert.IsTrue( conf1.Navigate("/c[gg=123]").Exists);
              Assert.IsTrue( conf1.Navigate("/b/$z").Exists);
              Assert.AreEqual( 134,  conf1.Navigate("/b/$z").ValueAsInt());

              Assert.IsTrue( conf1.Navigate("/c[gg=123]/$gg").Exists);
              Assert.IsTrue( conf1.Navigate("/c[name=id1]/$y").Exists);
              Assert.IsTrue( conf1.Navigate("/c[name=id2]/$z").Exists);

              Assert.AreEqual( 123,  conf1.Navigate("/c[gg=123]/$gg").ValueAsInt());
              Assert.AreEqual( 456,  conf1.Navigate("/c[name=id1]/$y").ValueAsInt());
              Assert.AreEqual( 789,  conf1.Navigate("/c[name=id2]/$z").ValueAsInt());
        }
示例#2
0
 /// <summary>
 /// Creates new configuration from ordered merge result of two other nodes - base and override which can be from different configurations
 /// </summary>
 /// <param name="baseNode">A base node that data is defaulted from</param>
 /// <param name="overrideNode">A node that contains overrides/additions of/to data from base node</param>
 /// <param name="rules">Rules to use or default rules will be used in null is passed</param>
 public void CreateFromMerge(ConfigSectionNode baseNode, ConfigSectionNode overrideNode, NodeOverrideRules rules = null)
 {
     m_Root = new ConfigSectionNode(this, null, baseNode);
     m_Root.OverrideBy(overrideNode, rules);
 }
示例#3
0
        public void SectionMerge_3()
        {
            var conf1 = "r{ a{} c{}}".AsLaconicConfig(handling: ConvertErrorHandling.Throw);
              var conf2 = "r{ b{ z = 134 } c{ y=456} c{z=789 }}".AsLaconicConfig(handling: ConvertErrorHandling.Throw);

              var rules = new NodeOverrideRules{ AppendSectionsWithoutMatchAttr = true };
              conf1.OverrideBy(conf2, rules);

              Assert.AreEqual(5, conf1.ChildCount);//<---- 5 because all "C" get appended
              Assert.IsTrue( conf1.Navigate("/a").Exists);
              Assert.IsTrue( conf1.Navigate("/b").Exists);
              Assert.IsTrue( conf1.Navigate("/c").Exists);
              Assert.IsTrue( conf1.Navigate("/b/$z").Exists);
              Assert.AreEqual( 134,  conf1.Navigate("/b/$z").ValueAsInt());

              Assert.IsTrue( conf1.Navigate("/c[y=456]").Exists);
              Assert.IsTrue( conf1.Navigate("/c[z=789]").Exists);

              Assert.AreEqual( 456,  conf1.Navigate("/c[y=456]/$y").ValueAsInt());
              Assert.AreEqual( 789,  conf1.Navigate("/c[z=789]/$z").ValueAsInt());
        }