Example #1
0
 public static void Dump(string name, object o)
 {
     using (new WithInvariantCulture()) {
         lock (WriteLock) {
             Diag("dump of " + name + ": ");
             var yw = new YAMLWriter(Console.Out, 0, TAP.HorizontalThreshold, null);
             yw.Write(o);
         }
     }
 }
Example #2
0
        void WriteIsVal(bool leaf, OrderedDictionary dic, string label, string key, List <PathEntry> path, int side)
        {
            var val = dic[key];

            if (leaf)
            {
                Tw.Write("{0}: '{1}'", label, SafeToString(val));
            }
            else
            {
                Tw.WriteLine("  {0}:", label);
                var yw = new YAMLWriter(Tw, 4, TAP.HorizontalThreshold, BBD);
                yw.Annotate = (i, n) => {
                    return(GetAnnotation(i, n, path, side, 0));
                };
                yw.Write(val);
            }
        }
Example #3
0
        void WriteIsComment(OrderedDictionary dic, List <PathEntry> path)
        {
            bool leaf = path == null || (YAMLWriter.IsLeafType(dic["actual"]) && YAMLWriter.IsLeafType(dic["expected"]));

            if (!leaf)
            {
                Tw.WriteLine("actual not as expected");
            }
            WriteIsVal(leaf, dic, "got", "actual", path, 0);
            if (leaf)
            {
                Tw.Write(" ");
            }
            WriteIsVal(leaf, dic, "expected", "expected", path, 1);
            if (leaf)
            {
                Tw.WriteLine();
            }
        }
Example #4
0
        public override void WriteComment(int nr, OrderedDictionary dic, List <PathEntry> path, string name)
        {
            if (path != null)
            {
                path.Insert(0, new PathEntry(-1));
            }
            var yw      = new YAMLWriter(Tw, 2, TAP.HorizontalThreshold, BBD);
            int rootidx = -1;
            int side    = 0;

            yw.Annotate = (i, n) => {
                int depth = n.Depth;
                if (depth == 1)
                {
                    var k = n.Key as string;
                    if (k != null)
                    {
                        if (k == "actual")
                        {
                            side    = 0;
                            rootidx = i;
                        }
                        else if (k == "expected")
                        {
                            side    = 1;
                            rootidx = i;
                        }
                    }
                    else
                    {
                        rootidx = -1;
                    }
                }
                if (rootidx != -1)
                {
                    return(GetAnnotation(i - rootidx, n, path, side, 1));
                }
                return(null);
            };
            yw.Write(dic);
        }
Example #5
0
 public override bool IsLeafType(object o, Type t)
 {
     return(YAMLWriter.IsLeafType(o, t));
 }
Example #6
0
 public LeafWriter(YAMLWriter yamlWriter, Regex needsQuotes, Func <string, bool> lineBreakp)
 {
     NeedsQuotes = needsQuotes;
     LineBreakp  = lineBreakp;
     YAMLWriter  = yamlWriter;
 }
Example #7
0
 public LeafWriter(YAMLWriter yamlWriter,Regex needsQuotes,Func<string,bool> lineBreakp) {
     NeedsQuotes=needsQuotes;
     LineBreakp=lineBreakp;
     YAMLWriter=yamlWriter;
 }
Example #8
0
 string RunWriter(int initialdepth,object o,int horizontalthreshold,IDictionary<Type,bool> bbt,Func<int,YNode,string> anno)
 {
     var w=new YAMLWriter(new StringWriter(),initialdepth,horizontalthreshold,bbt);
     w.Annotate=anno;
     return w.Write(o).ToString();
 }
Example #9
0
 void TestEscape()
 {
     var yw=new YAMLWriter(Console.Out,0,60);
     Is(yw.Escape("\u0087"),"\"\\u0087\"");
     Is(yw.Escape("\ufffe"),"\"\\ufffe\"");
     Is(yw.Escape("\ud900"),"\"\\ud900\"");
     Is(yw.Escape("\u0085\uffff"),"\"\\N\\uffff\"");
 }