コード例 #1
0
        public override string dump(string prefix)
        {
            string        pfx1    = prefix + PrettyPrinter.Spacer;
            StringBuilder builder = new StringBuilder();

            builder.AppendLine("[NotificationStream " + (zeroOne == 0 ? "Tuple01" : "SubStream") + "]");
            PrettyPrinter.Print(builder, pfx1, notice);
            return(builder.ToString());
        }
コード例 #2
0
        public override string dump(string prefix)
        {
            string        pfx1    = prefix + PrettyPrinter.Spacer;
            StringBuilder builder = new StringBuilder();

            builder.AppendLine("ErrorResponse: msgType=" + causingMessageType + " code=" + errorCode);
            PrettyPrinter.Print(builder, pfx1, errorPayload);
            return(builder.ToString());
        }
コード例 #3
0
        public override string dump(string prefix)
        {
            string        pfx1    = prefix + PrettyPrinter.Spacer;
            StringBuilder builder = new StringBuilder();

            builder.AppendLine("[CallRsp " + (subStream ? "PySubStream" : "PyTuple") + "]");
            PrettyPrinter.Print(builder, pfx1, response);
            return(builder.ToString());
        }
コード例 #4
0
        private void button1_Click(object sender, EventArgs e)
        {
            if (txtInput.Text.Length == 0)
            {
                txtOutput.Text = "";
                return;
            }
            string hex = txtInput.Text.Replace(" ", "").Replace(System.Environment.NewLine, "");

            try
            {
                //txtOutput.Text = hex;
                byte[] raw = new Byte[hex.Length / 2];
                for (int i = 0; i < raw.Length; i++)
                {
                    raw[i] = Convert.ToByte(hex.Substring(i * 2, 2), 16);
                }
                Console.WriteLine(raw.Length + ", " + hex.Length);
                Unmarshal un = new Unmarshal();
                //un.DebugMode = true;
                //PyObject obj = un.Process(BinaryReader.);
                PyRep         obj = un.Process(raw);
                PrettyPrinter pp  = new PrettyPrinter();
                txtOutput.Text = pp.Print(obj);
            }
            catch
            {
                hex = txtInput.Text.Substring(8, txtInput.Text.Length - 8).Replace(" ", "").Replace(System.Environment.NewLine, "");
                byte[] raw = new Byte[hex.Length / 2];
                for (int i = 0; i < raw.Length; i++)
                {
                    raw[i] = Convert.ToByte(hex.Substring(i * 2, 2), 16);
                }
                Console.WriteLine(raw.Length + ", " + hex.Length);
                Unmarshal un = new Unmarshal();
                un.DebugMode = true;
                // un.DebugMode = true;
                //PyObject obj = un.Process(BinaryReader.);
                PyRep         obj = un.Process(raw);
                PrettyPrinter pp  = new PrettyPrinter();
                txtOutput.Text = pp.Print(obj);
            }

            /*
             * //txtOutput.Text = hex;
             * byte[] raw = new Byte[hex.Length / 2];
             * for (int i = 0; i < raw.Length; i++) {
             *  raw[i] = Convert.ToByte(hex.Substring(i * 2, 2), 16);
             * }
             * Console.WriteLine(raw.Length+", "+hex.Length);
             * Unmarshal un = new Unmarshal();
             * // un.DebugMode = true;
             * //PyObject obj = un.Process(BinaryReader.);
             * PyObject obj = un.Process(raw);
             * txtOutput.Text = PrettyPrinter.Print(obj);
             */
        }
コード例 #5
0
ファイル: TextTests.cs プロジェクト: superdullwolf/PT.PM
        public void EscapeString()
        {
            string origin  = "\"\\\r\n";
            var    printer = new PrettyPrinter
            {
                Escape = true
            };

            Assert.AreEqual("\\\"\\\\", printer.Print(origin));
        }
コード例 #6
0
        public override string ToString()
        {
            StringBuilder sb = new StringBuilder();

            foreach (Statement s in Statements)
            {
                sb.AppendLine(PrettyPrinter.Print(s));
            }
            return(sb.ToString());
        }
コード例 #7
0
ファイル: TextTests.cs プロジェクト: superdullwolf/PT.PM
        public void ReduceWhitespaces()
        {
            string origin  = " a   =   b ";
            var    printer = new PrettyPrinter
            {
                Trim = true,
                ReduceWhitespaces = true
            };

            Assert.AreEqual("a = b", printer.Print(origin));
        }
コード例 #8
0
ファイル: JsonTests.cs プロジェクト: mbrezu/FancyPen
        public void Primitives()
        {
            // Arrange
            var json = JsonDocument.Parse("[\"a\", 2, true, false, null]");

            // Act
            var result = PrettyPrinter.Print(json);

            // Assert
            result.Should().Be("[ \"a\", 2, true, false, null ]");
        }
コード例 #9
0
ファイル: JsonTests.cs プロジェクト: mbrezu/FancyPen
        public void JsonEscape()
        {
            // Arrange
            var json = JsonDocument.Parse("[\"\\\"a\", \"\\\"b\"]");

            // Act
            var result = PrettyPrinter.Print(json);

            // Assert
            result.Should().Be("[ \"\\\"a\", \"\\\"b\" ]");
        }
コード例 #10
0
ファイル: JsonTests.cs プロジェクト: mbrezu/FancyPen
        public void BasicObject()
        {
            // Arrange
            var json = JsonDocument.Parse("{\"a\": 2}");

            // Act
            var result = PrettyPrinter.Print(json);

            // Assert
            result.Should().Be("{ \"a\": 2 }");
        }
コード例 #11
0
ファイル: JsonTests.cs プロジェクト: mbrezu/FancyPen
        public void BasicArray()
        {
            // Arrange
            var json = JsonDocument.Parse("[\"a\", 2]");

            // Act
            var result = PrettyPrinter.Print(json);

            // Assert
            result.Should().Be("[ \"a\", 2 ]");
        }
コード例 #12
0
 public void TestPrettyPrintException()
 {
     try
     {
         ThrowStuff();
     }
     catch (Exception e)
     {
         _outputHelper.WriteLine(PrettyPrinter.Print(e));
     }
 }
コード例 #13
0
ファイル: TextTests.cs プロジェクト: superdullwolf/PT.PM
        public void PrettyPrintMessages()
        {
            var printer = new PrettyPrinter()
            {
                MaxMessageLength = 32
            };
            string origin = "The sample of very long message.";
            string actual = printer.Print(origin);

            Assert.AreEqual(origin, actual);

            printer = new PrettyPrinter
            {
                MaxMessageLength = 30,
                CutWords         = true
            };
            actual = printer.Print(origin);
            Assert.AreEqual(30, actual.Length);
            Assert.AreEqual("The sample of v ... g message.", actual);

            printer = new PrettyPrinter
            {
                MaxMessageLength = 30,
                CutWords         = false
            };
            actual = printer.Print(origin);
            Assert.AreEqual("The sample of ... message.", actual);

            printer = new PrettyPrinter
            {
                Trim             = false,
                MaxMessageLength = 10,
                CutWords         = false
            };
            Assert.AreEqual(" ... ", printer.Print("                          "));

            origin  = "aaaaaaaaaaaaaaaaaaaaaaaaaaaaaa";
            printer = new PrettyPrinter
            {
                MaxMessageLength = 20,
                CutWords         = false
            };
            Assert.AreEqual("aaaaaaaaaa ... aaaaa", printer.Print(origin));

            origin  = "aaaaaaaaaaaaaaaaaaaaaaaaaaaaaa";
            printer = new PrettyPrinter
            {
                MaxMessageLength = 20,
                StartRatio       = 1.0,
                CutWords         = false
            };
            Assert.AreEqual("aaaaaaaaaaaaaaaaaaaa ... ", printer.Print(origin));
        }
コード例 #14
0
 public void TestPrettyPrintSelfReferencingException()
 {
     try
     {
         var o = new Exception("foo");
         o.Data.Add("Self", o);
         throw o;
     }
     catch (Exception e)
     {
         _outputHelper.WriteLine(PrettyPrinter.Print(e));
     }
 }
コード例 #15
0
        private void RenderNode(Ust ust)
        {
            int    index    = currentIndex;
            string typeName = graphTooltipPrinter.Print(ust.GetType().Name);

            string labelName, tooltip;

            if (ust is ArgsUst ||
                ust is BlockStatement ||
                ust is ExpressionStatement ||
                ust is ConditionalExpression)
            {
                labelName = typeName;
                tooltip   = graphTooltipPrinter.Print(ust.ToString());
            }
            else
            {
                labelName = graphNodePrinter.Print(ust.ToString());
                tooltip   = typeName;
            }
            vertexesString.Append($@"{index} [label=""{labelName}""");
            vertexesString.Append($@", tooltip=""{tooltip}""");

            /*if (ust is Token)
             * {
             *  vertexesString.Append(", fillcolor=khaki, style=filled");
             * }
             * else if (ust is Expression)
             * {
             *  vertexesString.Append(", fillcolor=rosybrown1, style=filled");
             * }
             * else if (ust is Statement)
             * {
             *  vertexesString.Append(", fillcolor=skyblue1, style=filled");
             * }
             * else if (ust is ArgsUst)
             * {
             *  vertexesString.Append(", fillcolor=palegreen, style=filled");
             * }*/
            vertexesString.AppendLine("];");

            foreach (Ust child in ust.Children)
            {
                if (child != null)
                {
                    currentIndex++;
                    edgesString.AppendEdge(index, currentIndex);
                    RenderNode(child);
                }
            }
        }
コード例 #16
0
 static void Main(string[] args)
 {
     if (args.Length < 1)
     {
         PrettyPrinter.Print("Use `help` to list all available commands");
         IsInteractive = true;
         LaunchInteractive();
     }
     else
     {
         IsInteractive = false;
         ExecuteCommandArgument(args);
     }
 }
コード例 #17
0
ファイル: JsonTests.cs プロジェクト: mbrezu/FancyPen
        public void ObjectKeepIndentation()
        {
            // Arrange
            var json = JsonDocument.Parse("{\"a\": 1000, \"b\": 2000, \"c\": 3000}");

            // Act
            var result = PrettyPrinter.Print(
                json,
                new PrettyPrinterOptions(new KeepIndentationOption(), 10));

            // Assert
            result.Should().Be(@"{ ""a"": 1000,
  ""b"": 2000,
  ""c"": 3000 }".Replace("\n", Environment.NewLine));
        }
コード例 #18
0
        public override string dump(string prefix)
        {
            string        pfx1    = prefix + PrettyPrinter.Spacer;
            StringBuilder builder = new StringBuilder();

            builder.AppendLine("[BuiltinSet]" + PrettyPrinter.PrintRawData(this));
            foreach (var item in values)
            {
                PrettyPrinter.Print(builder, pfx1, item);
            }
            if (values.Items.Count == 0)
            {
                builder.AppendLine(pfx1 + "<Empty List>");
            }
            return(builder.ToString());
        }
コード例 #19
0
ファイル: JsonTests.cs プロジェクト: mbrezu/FancyPen
        public void MildlyComplexKeepIndentation()
        {
            // Arrange
            string jsonStr = CreateComplexJson();
            var    json    = JsonDocument.Parse(jsonStr);

            // Act
            var result = PrettyPrinter.Print(json);

            // Assert
            result.Should().Be(@"{ ""age"": 20,
  ""name"": ""John"",
  ""address"": { ""street"": ""Main"", ""number"": 20, ""city"": ""Smallville"" },
  ""array"": [ 1000, 2000, 3000, 4000, 5000, 6000, 7000, 8000, 9000, 10000 ] }"
                               .Replace("\n", Environment.NewLine));
        }
コード例 #20
0
        public override string dump(string prefix)
        {
            string        pfx1    = prefix + PrettyPrinter.Spacer;
            string        pfx2    = pfx1 + PrettyPrinter.Spacer;
            string        pfx3    = pfx2 + PrettyPrinter.Spacer + PrettyPrinter.Spacer;
            StringBuilder builder = new StringBuilder();

            builder.AppendLine("[CRowSet]" + PrettyPrinter.PrintRawData(this));
            builder.AppendLine(pfx1 + descriptor.dump(pfx1).TrimEnd('\r', '\n'));
            builder.AppendLine(pfx1 + "Rows:");
            foreach (var item in rows)
            {
                PrettyPrinter.Print(builder, pfx2, item);
            }
            return(builder.ToString());
        }
コード例 #21
0
 public void TestPrettyPrintObjectWithException()
 {
     try
     {
         ThrowStuff();
     }
     catch (Exception e)
     {
         _outputHelper.WriteLine(PrettyPrinter.Print(new
         {
             Name  = "foo",
             Age   = 42,
             Error = e
         }));
     }
 }
コード例 #22
0
 public static void Main(string[] args)
 {
     if (args.Length > 0)
     {
         Stream stream = File.OpenRead(args[0]);
         /* The default entry point is used. For other options see class Parser */
         Scanner scanner = Scanner.CreateScanner(stream);
         Parser  parser  = new Parser(scanner);
         // Uncomment to enable trace information:
         // parser.Trace shows what the parser is doing
         // parser.Trace = true;
         // scanner.Trace prints the tokens as they are parsed, one token per line
         // scanner.Trace = true;
         // parser.scanner = scanner;
         try
         {
             OCLfile parse_tree = parser.ParseOCLfile();
             if (parse_tree != null)
             {
                 Console.Out.WriteLine("Parse Successful!");
                 Console.Out.WriteLine("");
                 Console.Out.WriteLine("[Abstract Syntax]");
                 Console.Out.WriteLine("{0}", PrettyPrinter.Show(parse_tree));
                 Console.Out.WriteLine("");
                 Console.Out.WriteLine("[Linearized Tree]");
                 Console.Out.WriteLine("{0}", PrettyPrinter.Print(parse_tree));
             }
             else
             {
                 Console.Out.WriteLine("Parse NOT Successful!");
             }
         }
         catch (Exception e)
         {
             Console.Out.WriteLine("Parse NOT Successful:");
             Console.Out.WriteLine(e.Message);
             Console.Out.WriteLine("");
             Console.Out.WriteLine("Stack Trace:");
             Console.Out.WriteLine(e.StackTrace);
         }
     }
     else
     {
         Console.Out.WriteLine("You must specify a filename!");
     }
 }
コード例 #23
0
ファイル: JsonTests.cs プロジェクト: mbrezu/FancyPen
        public void ArrayKeepIndentation()
        {
            // Arrange
            var json = JsonDocument.Parse("[100, 200, 300, 400, 500]");

            // Act
            var result = PrettyPrinter.Print(
                json,
                new PrettyPrinterOptions(new KeepIndentationOption(), 10));

            // Assert
            result.Should().Be(@"[ 100,
  200,
  300,
  400,
  500 ]".Replace("\n", Environment.NewLine));
        }
コード例 #24
0
        public override string dump(string prefix)
        {
            string        pfx1    = prefix + PrettyPrinter.Spacer;
            string        pfx2    = pfx1 + PrettyPrinter.Spacer;
            StringBuilder builder = new StringBuilder();

            builder.AppendLine("[CIndexedRowSet]" + PrettyPrinter.PrintRawData(this));
            builder.AppendLine(pfx1 + "index: " + columnName);
            builder.AppendLine(pfx1 + descriptor.dump(pfx1).TrimEnd('\r', '\n'));
            builder.AppendLine(pfx1 + "Rows:");
            foreach (var item in rows)
            {
                PrettyPrinter.Print(builder, pfx2 + "Key:", item.Key);
                PrettyPrinter.Print(builder, pfx2, item.Value);
            }
            return(builder.ToString());
        }
コード例 #25
0
ファイル: PlaceboRequest.cs プロジェクト: Tratos/EVESharp
        // We dont need to encode it, just decode as this is only sent by the client
        public bool Decode(PyObject data)
        {
            if (data.Type != PyObjectType.Tuple)
            {
                Log.Error("PlaceboRequest", "Wrong type");
                return(false);
            }

            PyTuple tmp = data.As <PyTuple>();

            if (tmp.Items.Count != 2)
            {
                Log.Error("PlaceboRequest", "Wrong item count, expected 2 but got " + tmp.Items.Count);
                return(false);
            }

            if (tmp.Items[0].Type != PyObjectType.String)
            {
                Log.Error("PlaceboRequest", "Wrong item 1 type");
                return(false);
            }

            if (tmp.Items[1].Type != PyObjectType.Dict)
            {
                Log.Error("PlaceboRequest", "Wrong item 2 type");
                return(false);
            }

            PyString command = tmp.Items[0].As <PyString>();

            if (command.Value != "placebo")
            {
                Log.Error("PlaceboRequest", "Wrong value for command, expected \"" + request + "\", but got \"" + command.Value + "\"");
                return(false);
            }

            PyDict args = tmp.Items[1].As <PyDict>();

            if (args.Dictionary.Count != 0)
            {
                Log.Warning("PlaceboRequest", "PlaceboRequest arguments are not supported yet");
                Log.Warning("PlaceboRequest", PrettyPrinter.Print(args));
            }

            return(true);
        }
コード例 #26
0
        //constants

        //custom body
        //methods
        //equals trait
        //hash code trait
        //pretty print
        public override void Print(PrettyPrinter printer)
        {
            printer.Println("SummonerModel (");
            using (printer.IndentCookie()) {
                printer.Print("myString = "); _MyString.PrintEx(printer); printer.Println();
                printer.Print("myBool = "); _MyBool.PrintEx(printer); printer.Println();
                printer.Print("myEnum = "); _MyEnum.PrintEx(printer); printer.Println();
                printer.Print("data = "); _Data.PrintEx(printer); printer.Println();
                printer.Print("myStructure = "); _MyStructure.PrintEx(printer); printer.Println();
            }
            printer.Print(")");
        }
コード例 #27
0
 //custom body
 //equals trait
 //hash code trait
 //pretty print
 public override void Print(PrettyPrinter printer)
 {
     printer.Println("UnitTestLaunch (");
     using (printer.IndentCookie()) {
         printer.Print("testNames = "); TestNames.PrintEx(printer); printer.Println();
         printer.Print("testGroups = "); TestGroups.PrintEx(printer); printer.Println();
         printer.Print("testCategories = "); TestCategories.PrintEx(printer); printer.Println();
         printer.Print("testResult = "); _TestResult.PrintEx(printer); printer.Println();
         printer.Print("runResult = "); _RunResult.PrintEx(printer); printer.Println();
     }
     printer.Print(")");
 }
コード例 #28
0
 public void PrintTypeCtorDef(TextWriter writer)
 {
     writer.WriteLine($"{nameof(TypeCtorMap)} size: {TypeCtorMap.Count}");
     foreach (var pair in TypeCtorMap)
     {
         var adt = pair.Value;
         writer.WriteLine($"type constructor {pair.Key}, type:{adt.GetType()},kind:{PrettyPrinter.Print(adt.Kind)}");
         for (var i = 0; i < adt.CtorNmLst.Length; i++)
         {
             writer.Write($"  {adt.CtorNmLst[i]} :: ");
             writer.WriteLine($"{PrettyPrinter.Print(adt.CtorTyLst[i])}");
         }
         if (adt.CtorNmLst.Length == 0)
         {
             writer.WriteLine("  no value constructor");
         }
     }
 }
コード例 #29
0
        public void TestPrettyPrintDeepObject()
        {
            var fixture = new Fixture();

            fixture.Customizations.Add(new TypeRelay(typeof(IEnumerable),
                                                     typeof(ArrayList)));
            fixture.Behaviors.OfType <ThrowingRecursionBehavior>()
            .ToList()
            .ForEach(b => fixture.Behaviors.Remove(b));
            fixture.Behaviors.Add(new GenerationDepthBehavior(2));

            var deepObject = fixture.Build <DeepObject>()
                             .WithAutoProperties()
                             .With(p => p.EnumerableOfSomething, fixture.Create <List <decimal> >())
                             .Create();

            _outputHelper.WriteLine(PrettyPrinter.Print(deepObject));
        }
コード例 #30
0
        private void listBox1_SelectedIndexChanged(object sender, EventArgs e)
        {
            if (listBox1.SelectedItem == null)
            {
                richTextBox2.Text = "";
                return;
            }

            if (Cache.UpdateCache(listBox1.SelectedItem.ToString()) == false)
            {
                WindowLog.Error("Main::LoadCache", "Error loading cache");
                return;
            }

            PyObject cache = Cache.GetCache(listBox1.SelectedItem.ToString());

            PyCachedObject obj = new PyCachedObject();

            if (obj.Decode(cache) == false)
            {
                WindowLog.Error("Main::LoadCache", "Cannot decode the cache data");
                return;
            }

            if (Program.cacheDataDisplayMode == "Pretty")
            {
                try
                {
                    richTextBox2.Text = PrettyPrinter.Print(Unmarshal.Process <PyObject>(obj.cache.Data));
                }
                catch (Exception)
                {
                    WindowLog.Error("Main::LoadCache", "Cannot Unmarshal the cache data");
                    richTextBox2.Text = "Error";
                }
            }
            else
            {
                richTextBox2.Text = ByteToString(obj.cache.Data);
            }

            WindowLog.Debug("Main::LoadCache", "Cache loaded");
        }