Ejemplo n.º 1
0
        public void KleinDefinition_ShouldPrint()
        {
            var ast = new Definition
                      (
                identifier: new Identifier(0, "main"),
                typeDeclaration: new BooleanTypeDeclaration(0),
                formals: new List <Formal>
            {
                new Formal(new Identifier(0, "arg1"), new BooleanTypeDeclaration(0)),
                new Formal(new Identifier(0, "arg2"), new IntegerTypeDeclaration(0)),
            },
                body: new Body(expr: new BooleanLiteral(0, false))
                      );

            Assert.That(PrettyPrinter.ToString(ast), Is.EqualTo(
                            @"Definition(main)
    Type(Boolean)
    Formals
        Formal(arg1)
            Type(Boolean)
        Formal(arg2)
            Type(Integer)
    Body
        Expr
            Boolean(False)
"));
        }
Ejemplo n.º 2
0
        public override string ToString()
        {
            var prettyPrinter = new PrettyPrinter();

            Print(prettyPrinter);
            return(prettyPrinter.ToString());
        }
Ejemplo n.º 3
0
        public static string PrintToString(this object me)
        {
            var prettyPrinter = new PrettyPrinter();

            me.PrintEx(prettyPrinter);
            return(prettyPrinter.ToString());
        }
Ejemplo n.º 4
0
        public void KleinProgram_ShouldPrint()
        {
            var ast = new Program(
                new Definition
                (
                    identifier: new Identifier(0, "main"),
                    typeDeclaration: new BooleanTypeDeclaration(0),
                    formals: new List <Formal>(),
                    body: new Body(expr: new BooleanLiteral(0, false))
                ),
                new Definition
                (
                    identifier: new Identifier(0, "subsidiary"),
                    typeDeclaration: new IntegerTypeDeclaration(0),
                    formals: new List <Formal>(),
                    body: new Body(expr: new BooleanLiteral(0, false))
                )
                );

            Assert.That(PrettyPrinter.ToString(ast), Is.EqualTo(
                            @"Program
    Definition(main)
        Type(Boolean)
        Formals
        Body
            Expr
                Boolean(False)
    Definition(subsidiary)
        Type(Integer)
        Formals
        Body
            Expr
                Boolean(False)
"));
        }
Ejemplo n.º 5
0
        public static string PrintToString(this Object thIs)
        {
            var prettyPrinter = new PrettyPrinter();

            thIs.PrintEx(prettyPrinter);
            return(prettyPrinter.ToString());
        }
Ejemplo n.º 6
0
        public void IntegerLiteral_ShouldPrint()
        {
            var ast = new IntegerLiteral(0, "123");

            Assert.That(PrettyPrinter.ToString(ast), Is.EqualTo(
                            @"Integer(123)
"));
        }
Ejemplo n.º 7
0
        public void BooleanLiteral_ShouldPrint()
        {
            var ast = new BooleanLiteral(0, true);

            Assert.That(PrettyPrinter.ToString(ast), Is.EqualTo(
                            @"Boolean(True)
"));
        }
Ejemplo n.º 8
0
        public void Formal_ShouldPrint()
        {
            var ast = new Formal(identifier: new Identifier(0, "arg1"), typeDeclaration: new BooleanTypeDeclaration(0));

            Assert.That(PrettyPrinter.ToString(ast), Is.EqualTo(
                            @"Formal(arg1)
    Type(Boolean)
"));
        }
Ejemplo n.º 9
0
        public static string PrintToStringNoLimits(this object me)
        {
            var prettyPrinter = new PrettyPrinter {
                CollectionMaxLength = Int32.MaxValue
            };

            me.PrintEx(prettyPrinter);
            return(prettyPrinter.ToString());
        }
Ejemplo n.º 10
0
        public void Actual_ShouldPrint()
        {
            var ast = new Actual(new Identifier(0, "x"));

            Assert.That(PrettyPrinter.ToString(ast), Is.EqualTo(
                            @"Actual
    Identifier(x)
"));
        }
Ejemplo n.º 11
0
        private void DisplayAstDifferences(MessageWriter writer, Ast expected, Ast actual)
        {
            writer.WriteLine("Expected:");
            writer.Write(PrettyPrinter.ToString(expected));
            writer.WriteMessageLine("");

            writer.WriteLine("But was:");
            writer.Write(PrettyPrinter.ToString(actual));
            writer.WriteMessageLine("");
        }
Ejemplo n.º 12
0
    private void UpdateDisplay()
    {
        textview1.Buffer.Text = String.Empty;
        if (asn == null)
        {
            return;
        }
        if (pp == null)
        {
            pp = new PrettyPrinter(asn);
        }
        pp.Options            = options;
        textview1.Buffer.Text = pp.ToString();
        Highlight(findhighlight);
        findfwd = textview1.Buffer.StartIter;
        findbck = textview1.Buffer.EndIter;

        // process possible encapsulated ASN.1 element
        // (i.e. ASN.1 elements contained in other ASN.1 elements)
        if (options.IncludeEncapsulated)
        {
            TextIter start;
            TextIter end;
            TextIter search = textview1.Buffer.StartIter;
            while (search.ForwardSearch(", encapsulates {", tsf, out start, out end, textview1.Buffer.EndIter))
            {
                start.ForwardChars(2);
                int num1 = 1;
                while (end.ForwardChar())
                {
                    if (end.Char == "}")
                    {
                        num1--;
                        if (num1 == 0)
                        {
                            end.ForwardChar();
                            break;
                        }
                        continue;
                    }
                    if (end.Char == "{")
                    {
                        num1++;
                    }
                }
                textview1.Buffer.ApplyTag(encapsulated, start, end);
                search = end;
            }
        }
        else
        {
            textview1.Buffer.RemoveTag(encapsulated, textview1.Buffer.StartIter, textview1.Buffer.EndIter);
        }
    }
Ejemplo n.º 13
0
        public void NegateOperator_ShouldPrint()
        {
            var ast = new NegateOperator
                      (
                position: 0,
                right: new Identifier(0, "y")
                      );

            Assert.That(PrettyPrinter.ToString(ast), Is.EqualTo(
                            @"Negate
    Identifier(y)
"));
        }
Ejemplo n.º 14
0
        protected void After()
        {
            SpinWaitEx.SpinUntil(ModelLifetime, 10_000, () => Finished);
            SpinWaitEx.SpinUntil(ModelLifetime, 1_000, () => false);

            SocketLifetimeDef.Terminate();
            ModelLifetimeDef.Terminate();

            using (myOutputFile)
            {
                myOutputFile.Write(Printer.ToString());
            }
        }
Ejemplo n.º 15
0
        public void DivideOperator_ShouldPrint()
        {
            var ast = new DivideOperator
                      (
                position: 0,
                left: new Identifier(0, "x"),
                right: new Identifier(0, "y")
                      );

            Assert.That(PrettyPrinter.ToString(ast), Is.EqualTo(
                            @"Divide
    Identifier(x)
    Identifier(y)
"));
        }
Ejemplo n.º 16
0
        public void FunctionCall_ShouldPrint()
        {
            var ast = new FunctionCall(
                new Identifier(0, "func"),
                new List <Actual>()
            {
                new Actual(new Identifier(0, "x")),
                new Actual(new Identifier(0, "y"))
            }
                );

            Assert.That(PrettyPrinter.ToString(ast), Is.EqualTo(
                            @"FunctionCall(func)
    Actual
        Identifier(x)
    Actual
        Identifier(y)
"));
        }
Ejemplo n.º 17
0
        public void IfThenElse_ShouldPrint()
        {
            var ast = new IfThenElse
                      (
                position: 0,
                ifExpr: new Identifier(0, "x"),
                thenExpr: new Identifier(0, "y"),
                elseExpr: new Identifier(0, "z")
                      );

            Assert.That(PrettyPrinter.ToString(ast), Is.EqualTo(
                            @"If
    Identifier(x)
Then
    Identifier(y)
Else
    Identifier(z)
"));
        }
Ejemplo n.º 18
0
        public void Body_ShouldPrint_Prints()
        {
            var ast = new Body
                      (
                new IntegerLiteral(0, "123"),
                new List <Print>
            {
                new Print(0, new Identifier(0, "x")),
                new Print(0, new Identifier(0, "y"))
            }
                      );

            Assert.That(PrettyPrinter.ToString(ast), Is.EqualTo(
                            @"Body
    Print
        Identifier(x)
    Print
        Identifier(y)
    Expr
        Integer(123)
"));
        }
Ejemplo n.º 19
0
        public void IntegerTypeDeclaration_ShouldPrint()
        {
            var ast = new IntegerTypeDeclaration(0);

            Assert.That(PrettyPrinter.ToString(ast), Is.EqualTo("Type(Integer)\r\n"));
        }
Ejemplo n.º 20
0
        public void BooleanTypeDeclaration_ShouldPrint()
        {
            var ast = new BooleanTypeDeclaration(0);

            Assert.That(PrettyPrinter.ToString(ast), Is.EqualTo("Type(Boolean)\r\n"));
        }
Ejemplo n.º 21
0
 protected override void ProcessRecord()
 {
     WriteObject(PrettyPrinter.ToString(Ast));
 }