public void AssertAreEqual(YamlNode expected, YamlNode result)
 {
     Assert.AreEqual(expected.GetType(), result.GetType());
     Assert.AreEqual(expected.Tag, result.Tag,
         "Tag was different between expected ({0}) and result ({1}).", expected, result);
     if ( expected is YamlScalar ) {
         var expectedScalar = (YamlScalar)expected;
         var resultScalar = (YamlScalar)result;
         Assert.AreEqual(expectedScalar.Value, resultScalar.Value);
     }
     if ( expected is YamlSequence ) {
         var expectedSequence = (YamlSequence)expected;
         var resultSequence = (YamlSequence)result;
         Assert.AreEqual(expectedSequence.Count, resultSequence.Count);
         for ( int i = 0; i < expectedSequence.Count; i++ )
             AssertAreEqual(expectedSequence[i], resultSequence[i]);
     }
     if ( expected is YamlMapping ) {
         var expectedMapping = (YamlMapping)expected;
         var resultMapping = (YamlMapping)result;
         Assert.AreEqual(expectedMapping.Count, resultMapping.Count);
         foreach ( var entry in expectedMapping ) {
             Assert.IsTrue(resultMapping.ContainsKey(entry.Key),
                 "Mapping node {0} does not contain a key {1}.",
                     resultMapping, entry.Key);
             AssertAreEqual(entry.Value, resultMapping[entry.Key]);
         }
     }
 }
 public void Add(string anchor_name, YamlNode node)
 {
     if ( Items.ContainsKey(anchor_name) ) {
         // override an existing anchor
         ItemsToRewind.Push(new RewindInfo(anchor_name, this[anchor_name]));
         Items[anchor_name] = node;
     } else {
         ItemsToRewind.Push(new RewindInfo(anchor_name, null));
         Items.Add(anchor_name, node);
     }
 }
Example #3
0
 /// <summary>
 /// Returns true if <paramref name="b"/> is of same type as the <see cref="YamlNode"/> and
 /// its Tag is same as the node. It returns true for <paramref name="skip"/> if they
 /// both already appeared in the node trees and were compared.
 /// </summary>
 /// <param name="b">Node to be compared.</param>
 /// <param name="repository">Node repository holds the nodes that already appeared and 
 /// the corresponding node in the other node tree.</param>
 /// <param name="skip">true if they already appeared in the node tree and were compared.</param>
 /// <returns>true if they are equal to each other.</returns>
 internal bool EqualsSub(YamlNode b, ObjectRepository repository, out bool skip)
 {
     YamlNode a = this;
     bool identity;
     if ( repository.AlreadyAppeared(a, b, out identity) ) {
         skip = true;
         return identity;
     }
     skip = false;
     if ( a.GetType() != b.GetType() || a.Tag != b.Tag )
         return false;
     return true;
 }
Example #4
0
 /// <summary>
 /// Returns true if <paramref name="b"/> is of same type as the <see cref="YamlNode"/> and
 /// its content is also logically same.
 /// </summary>
 /// <param name="b">Node to be compared.</param>
 /// <param name="repository">Node repository holds the nodes that already appeared and 
 /// the corresponding node in the other node tree.</param>
 /// <returns>true if they are equal to each other.</returns>
 internal abstract bool Equals(YamlNode b, ObjectRepository repository);
Example #5
0
 public bool AlreadyAppeared(YamlNode a, YamlNode b, out bool identity)
 {
     int ai, bi;
     bool ar = nodes_a.TryGetValue(a, out ai);
     bool br = nodes_b.TryGetValue(b, out bi);
     if ( ar && br && ai == bi ) {
         identity = true;
         return true;
     }
     if ( ar ^ br ) {
         identity = false;
         return true;
     }
     nodes_a.Add(a, nodes_a.Count);
     nodes_b.Add(b, nodes_b.Count);
     stack_a.Push(a);
     stack_b.Push(b);
     if ( a == b ) {
         identity = true;
         return true;
     }
     identity = false;
     return false;
 }
 public RewindInfo(string anchor_name, YamlNode old_value)
 {
     this.anchor_name = anchor_name;
     this.old_value = old_value;
 }
Example #7
0
 /// <summary>
 /// Returns true if <paramref name="b"/> is of same type as the <see cref="YamlNode"/> and
 /// its content is also logically same.
 /// </summary>
 /// <param name="b">Node to be compared.</param>
 /// <param name="repository">Node repository holds the nodes that already appeared and
 /// the corresponding node in the other node tree.</param>
 /// <returns>true if they are equal to each other.</returns>
 internal abstract bool Equals(YamlNode b, ObjectRepository repository);
Example #8
0
 public void ToYaml(Stream s, YamlNode node, YamlConfig config)
 {
     using (var yaml = new StreamWriter(s))
         ToYaml(yaml, node, config);
 }
Example #9
0
 public string ToYaml(YamlNode node, YamlConfig config)
 {
     yaml = new StringWriter();
     ToYaml(yaml, node, config);
     return(yaml.ToString());
 }
Example #10
0
 public string ToYaml(YamlNode node)
 {
     return(ToYaml(node, YamlNode.DefaultConfig));
 }
Example #11
0
 internal override bool Equals(YamlNode b, ObjectRepository repository)
 {
     bool skip;
     if(! base.EqualsSub(b, repository, out skip) )
         return false;
     if(skip)
         return true;
     YamlScalar aa = this;
     YamlScalar bb = (YamlScalar)b;
     if ( NativeObjectAvailable ) {
         return bb.NativeObjectAvailable && 
                (aa.NativeObject == null ? 
                     bb.NativeObject==null :
                     aa.NativeObject.Equals(bb.NativeObject) );
     } else {
         if ( ShorthandTag() == "!!str" ) {
             return aa.Value == bb.Value;
         } else {
             // Node with non standard tag is compared by its identity.
             return false; 
         }
     }
 }