public void FixedStatementWithMultipleVariables()
 {
     ParseUtilCSharp.AssertStatement(
         "fixed (int* ptr1 = &myIntArr[1], ptr2 = myIntArr) { }",
         new FixedStatement
     {
         Type      = new PrimitiveType("int").MakePointerType(),
         Variables =
         {
             new VariableInitializer       {
                 Name        = "ptr1",
                 Initializer = new UnaryOperatorExpression(
                     UnaryOperatorType.AddressOf,
                     new IndexerExpression {
                     Target = new IdentifierExpression("myIntArr"), Arguments ={ new PrimitiveExpression(1)                                      }
                 })
             },
             new VariableInitializer       {
                 Name        = "ptr2",
                 Initializer = new IdentifierExpression("myIntArr")
             }
         },
         EmbeddedStatement = new BlockStatement()
     });
 }
Exemplo n.º 2
0
 public void UsingStatementWithExpression()
 {
     ParseUtilCSharp.AssertStatement(
         "using (MyVar var = new MyVar()) { }",
         new UsingStatement {
         ResourceAcquisition = new ObjectCreateExpression(new SimpleType("MyVar")),
         EmbeddedStatement   = new BlockStatement()
     });
 }
Exemplo n.º 3
0
 public void DefaultValueInReturnStatement()
 {
     ParseUtilCSharp.AssertStatement(
         "return default(T);",
         new ReturnStatement {
         Expression = new DefaultValueExpression {
             Type = new SimpleType("T")
         }
     });
 }
Exemplo n.º 4
0
 public void ForeachStatementTest()
 {
     ParseUtilCSharp.AssertStatement(
         "foreach (int i in myColl) {} ",
         new ForeachStatement {
         VariableType      = new PrimitiveType("int"),
         VariableName      = "i",
         InExpression      = new IdentifierExpression("myColl"),
         EmbeddedStatement = new BlockStatement()
     });
 }
Exemplo n.º 5
0
 public void MakeTypedRef()
 {
     ParseUtilCSharp.AssertStatement(
         "TypedReference tr = __makeref(o);",
         new VariableDeclarationStatement(
             new SimpleType("TypedReference"),
             "tr",
             new UndocumentedExpression {
         UndocumentedExpressionType = UndocumentedExpressionType.MakeRef,
         Arguments = { new IdentifierExpression("o") }
     }));
 }
Exemplo n.º 6
0
 public void DefaultValueAsIntializer()
 {
     // This test was problematic (in old NRefactory) because we need a resolver for the "default:" / "default(" conflict.
     ParseUtilCSharp.AssertStatement(
         "T a = default(T);",
         new VariableDeclarationStatement {
         Type      = new SimpleType("T"),
         Variables =
         {
             new VariableInitializer("a", new DefaultValueExpression {
                 Type = new SimpleType("T")
             })
         }
     });
 }
Exemplo n.º 7
0
 public void SimpleTryCatchStatementTest2()
 {
     ParseUtilCSharp.AssertStatement(
         "try { } catch (Exception e) { } ",
         new TryCatchStatement {
         TryBlock     = new BlockStatement(),
         CatchClauses =
         {
             new CatchClause {
                 Type         = new SimpleType("Exception"),
                 VariableName = "e",
                 Body         = new BlockStatement()
             }
         }
     });
 }
Exemplo n.º 8
0
 public void UsingStatementWithMultipleVariableDeclaration()
 {
     ParseUtilCSharp.AssertStatement(
         "using (MyVar a = new MyVar(), b = null);",
         new UsingStatement {
         ResourceAcquisition = new VariableDeclarationStatement {
             Type      = new SimpleType("MyVar"),
             Variables =
             {
                 new VariableInitializer("a", new ObjectCreateExpression(new SimpleType("MyVar"))),
                 new VariableInitializer("b", new NullReferenceExpression())
             }
         },
         EmbeddedStatement = new EmptyStatement()
     });
 }
Exemplo n.º 9
0
 public void FixedStatementTest()
 {
     ParseUtilCSharp.AssertStatement(
         "fixed (int* ptr = myIntArr) { }",
         new FixedStatement {
         Type      = new PrimitiveType("int").MakePointerType(),
         Variables =
         {
             new VariableInitializer {
                 Name        = "ptr",
                 Initializer = new IdentifierExpression("myIntArr")
             }
         },
         EmbeddedStatement = new BlockStatement()
     });
 }
 public void ArrayDeclarationWithInitializer()
 {
     ParseUtilCSharp.AssertStatement(
         "int[] a = { 0 };",
         new VariableDeclarationStatement {
         Type      = new PrimitiveType("int").MakeArrayType(),
         Variables =
         {
             new VariableInitializer {
                 Name        = "a",
                 Initializer = new ArrayInitializerExpression{
                     Elements =      { new PrimitiveExpression(0)}
                 }
             }
         }
     });
 }
Exemplo n.º 11
0
        public void FixedStatementTest()
        {
            FixedStatement fixedStmt = ParseUtilCSharp.ParseStatement <FixedStatement>("fixed (int* ptr = &myIntArr) { }");

            ParseUtilCSharp.AssertStatement(
                "fixed (int* ptr = &myIntArr) { }",
                new FixedStatement {
                Type      = new PrimitiveType("int").MakePointerType(),
                Variables =
                {
                    new VariableInitializer {
                        Name        = "ptr",
                        Initializer = new UnaryOperatorExpression(UnaryOperatorType.AddressOf, new IdentifierExpression("myIntArr"))
                    }
                },
                EmbeddedStatement = new BlockStatement()
            });
        }
Exemplo n.º 12
0
 public void SimpleTryCatchFinallyStatementTest()
 {
     ParseUtilCSharp.AssertStatement(
         "try { } catch (Exception) { } catch { } finally { } ",
         new TryCatchStatement {
         TryBlock     = new BlockStatement(),
         CatchClauses =
         {
             new CatchClause {
                 Type = new SimpleType("Exception"),
                 Body = new BlockStatement()
             },
             new CatchClause {
                 Body = new BlockStatement()
             }
         },
         FinallyBlock = new BlockStatement()
     });
 }
 public void Global()
 {
     ParseUtilCSharp.AssertStatement(
         "global::System.String a;",
         new VariableDeclarationStatement {
         Type = new MemberType {
             Target = new MemberType {
                 Target        = new SimpleType("global"),
                 IsDoubleColon = true,
                 MemberName    = "System"
             },
             IsDoubleColon = false,
             MemberName    = "String",
         },
         Variables =
         {
             new VariableInitializer("a")
         }
     });
 }