From f52338f265ab0a00e583ec4e3775627bb1c8a579 Mon Sep 17 00:00:00 2001 From: Daniel Grunwald Date: Sat, 20 Nov 2010 17:22:45 +0100 Subject: [PATCH] Add statement-level parser tests. --- .../GeneralScope/DelegateDeclarationTests.cs | 16 ++ .../CSharp/Parser/ParseUtil.cs | 2 +- .../Parser/Statements/BlockStatementTests.cs | 41 ++++ .../Statements/CheckedStatementTests.cs | 45 ++++ .../Parser/Statements/EmptyStatementTests.cs | 18 ++ .../Statements/ExpressionStatementTests.cs | 26 ++ .../Parser/Statements/FixedStatementTests.cs | 19 ++ .../Parser/Statements/ForStatementTests.cs | 37 +++ .../Parser/Statements/GotoStatementTests.cs | 48 ++++ .../Parser/Statements/IfElseStatementTests.cs | 39 +++ .../Parser/Statements/LabelStatementTests.cs | 26 ++ .../Parser/Statements/LockStatementTests.cs | 19 ++ .../Parser/Statements/ReturnStatementTests.cs | 33 +++ .../Parser/Statements/SwitchStatementTests.cs | 20 ++ .../Parser/Statements/ThrowStatementTests.cs | 26 ++ .../Statements/TryCatchStatementTests.cs | 47 ++++ .../Parser/Statements/UnsafeStatementTests.cs | 19 ++ .../Parser/Statements/UsingStatementTests.cs | 19 ++ .../VariableDeclarationStatementTests.cs | 226 ++++++++++++++++++ .../Parser/Statements/WhileStatementTests.cs | 30 +++ .../Parser/Statements/YieldStatementTests.cs | 41 ++++ .../ICSharpCode.NRefactory.Tests.csproj | 20 ++ .../CSharp/Dom/Statements/CheckedStatement.cs | 6 +- .../CSharp/Dom/Statements/GotoStatement.cs | 7 +- .../Dom/Statements/UncheckedStatement.cs | 6 +- .../CSharp/Dom/Statements/YieldStatement.cs | 3 +- .../CSharp/Parser/CSharpParser.cs | 4 +- 27 files changed, 831 insertions(+), 12 deletions(-) create mode 100644 ICSharpCode.NRefactory.Tests/CSharp/Parser/Statements/BlockStatementTests.cs create mode 100644 ICSharpCode.NRefactory.Tests/CSharp/Parser/Statements/CheckedStatementTests.cs create mode 100644 ICSharpCode.NRefactory.Tests/CSharp/Parser/Statements/EmptyStatementTests.cs create mode 100644 ICSharpCode.NRefactory.Tests/CSharp/Parser/Statements/ExpressionStatementTests.cs create mode 100644 ICSharpCode.NRefactory.Tests/CSharp/Parser/Statements/FixedStatementTests.cs create mode 100644 ICSharpCode.NRefactory.Tests/CSharp/Parser/Statements/ForStatementTests.cs create mode 100644 ICSharpCode.NRefactory.Tests/CSharp/Parser/Statements/GotoStatementTests.cs create mode 100644 ICSharpCode.NRefactory.Tests/CSharp/Parser/Statements/IfElseStatementTests.cs create mode 100644 ICSharpCode.NRefactory.Tests/CSharp/Parser/Statements/LabelStatementTests.cs create mode 100644 ICSharpCode.NRefactory.Tests/CSharp/Parser/Statements/LockStatementTests.cs create mode 100644 ICSharpCode.NRefactory.Tests/CSharp/Parser/Statements/ReturnStatementTests.cs create mode 100644 ICSharpCode.NRefactory.Tests/CSharp/Parser/Statements/SwitchStatementTests.cs create mode 100644 ICSharpCode.NRefactory.Tests/CSharp/Parser/Statements/ThrowStatementTests.cs create mode 100644 ICSharpCode.NRefactory.Tests/CSharp/Parser/Statements/TryCatchStatementTests.cs create mode 100644 ICSharpCode.NRefactory.Tests/CSharp/Parser/Statements/UnsafeStatementTests.cs create mode 100644 ICSharpCode.NRefactory.Tests/CSharp/Parser/Statements/UsingStatementTests.cs create mode 100644 ICSharpCode.NRefactory.Tests/CSharp/Parser/Statements/VariableDeclarationStatementTests.cs create mode 100644 ICSharpCode.NRefactory.Tests/CSharp/Parser/Statements/WhileStatementTests.cs create mode 100644 ICSharpCode.NRefactory.Tests/CSharp/Parser/Statements/YieldStatementTests.cs diff --git a/ICSharpCode.NRefactory.Tests/CSharp/Parser/GeneralScope/DelegateDeclarationTests.cs b/ICSharpCode.NRefactory.Tests/CSharp/Parser/GeneralScope/DelegateDeclarationTests.cs index 6f917f24de..52dd16414f 100644 --- a/ICSharpCode.NRefactory.Tests/CSharp/Parser/GeneralScope/DelegateDeclarationTests.cs +++ b/ICSharpCode.NRefactory.Tests/CSharp/Parser/GeneralScope/DelegateDeclarationTests.cs @@ -57,5 +57,21 @@ namespace ICSharpCode.NRefactory.CSharp.Parser.GeneralScope Assert.AreEqual(1, dd.Templates[0].Bases.Count); Assert.AreEqual("ICloneable", dd.Templates[0].Bases[0].Type);*/ throw new NotImplementedException(); } + + [Test] + public void DelegateDeclarationInNamespace() + { + string program = "namespace N { delegate void MyDelegate(); }"; + NamespaceDeclaration nd = ParseUtilCSharp.ParseGlobal(program); + Assert.AreEqual("MyDelegate", ((DelegateDeclaration)nd.Members.Single()).Name); + } + + [Test, Ignore("inner classes not yet implemented")] + public void DelegateDeclarationInClass() + { + string program = "class Outer { delegate void Inner(); }"; + TypeDeclaration td = ParseUtilCSharp.ParseGlobal(program); + Assert.AreEqual("Inner", ((DelegateDeclaration)td.Members.Single()).Name); + } } } diff --git a/ICSharpCode.NRefactory.Tests/CSharp/Parser/ParseUtil.cs b/ICSharpCode.NRefactory.Tests/CSharp/Parser/ParseUtil.cs index fdde613aa0..1d2805552e 100644 --- a/ICSharpCode.NRefactory.Tests/CSharp/Parser/ParseUtil.cs +++ b/ICSharpCode.NRefactory.Tests/CSharp/Parser/ParseUtil.cs @@ -28,7 +28,7 @@ namespace ICSharpCode.NRefactory.CSharp.Parser public static T ParseStatement(string stmt, bool expectErrors = false) where T : INode { - Assert.Ignore("ParseExpression not yet implemented"); + Assert.Ignore("ParseStatement not yet implemented"); CSharpParser parser = new CSharpParser(); BlockStatement parsedBlock = parser.ParseBlock(new StringReader(stmt)); diff --git a/ICSharpCode.NRefactory.Tests/CSharp/Parser/Statements/BlockStatementTests.cs b/ICSharpCode.NRefactory.Tests/CSharp/Parser/Statements/BlockStatementTests.cs new file mode 100644 index 0000000000..ebe4e2cc5c --- /dev/null +++ b/ICSharpCode.NRefactory.Tests/CSharp/Parser/Statements/BlockStatementTests.cs @@ -0,0 +1,41 @@ +// Copyright (c) AlphaSierraPapa for the SharpDevelop Team (for details please see \doc\copyright.txt) +// This code is distributed under MIT X11 license (for details please see \doc\license.txt) + +using System; +using System.Linq; +using NUnit.Framework; + +namespace ICSharpCode.NRefactory.CSharp.Parser.Statements +{ + [TestFixture] + public class BlockStatementTests + { + [Test] + public void CSharpBlockStatementTest() + { + BlockStatement blockStmt = ParseUtilCSharp.ParseStatement("{}"); + Assert.AreEqual(0, blockStmt.Statements.Count()); + } + + [Test] + public void CSharpComplexBlockStatementPositionTest() + { + string code = @"{ + WebClient wc = new WebClient(); + wc.Test(); + wc.UploadStringCompleted += delegate { + output.BeginInvoke((MethodInvoker)delegate { + output.Text += newText; + }); + }; +}"; + BlockStatement blockStmt = ParseUtilCSharp.ParseStatement(code); + Assert.AreEqual(1, blockStmt.StartLocation.Column); + Assert.AreEqual(1, blockStmt.StartLocation.Line); + Assert.AreEqual(2, blockStmt.EndLocation.Column); + Assert.AreEqual(9, blockStmt.EndLocation.Line); + + Assert.AreEqual(3, blockStmt.Statements.Count()); + } + } +} diff --git a/ICSharpCode.NRefactory.Tests/CSharp/Parser/Statements/CheckedStatementTests.cs b/ICSharpCode.NRefactory.Tests/CSharp/Parser/Statements/CheckedStatementTests.cs new file mode 100644 index 0000000000..a99a568b02 --- /dev/null +++ b/ICSharpCode.NRefactory.Tests/CSharp/Parser/Statements/CheckedStatementTests.cs @@ -0,0 +1,45 @@ +// Copyright (c) AlphaSierraPapa for the SharpDevelop Team (for details please see \doc\copyright.txt) +// This code is distributed under MIT X11 license (for details please see \doc\license.txt) + +using System; +using System.Linq; +using NUnit.Framework; + +namespace ICSharpCode.NRefactory.CSharp.Parser.Statements +{ + [TestFixture] + public class CheckedStatementTests + { + [Test] + public void CheckedStatementTest() + { + CheckedStatement checkedStatement = ParseUtilCSharp.ParseStatement("checked { }"); + Assert.IsNotNull(checkedStatement.Block); + } + + [Test] + public void CheckedStatementAndExpressionTest() + { + CheckedStatement checkedStatement = ParseUtilCSharp.ParseStatement("checked { checked(++i); }"); + ExpressionStatement es = (ExpressionStatement)checkedStatement.Block.Statements.Single(); + CheckedExpression ce = (CheckedExpression)es.Expression; + Assert.IsTrue(ce.Expression is UnaryOperatorExpression); + } + + [Test] + public void UncheckedStatementTest() + { + UncheckedStatement uncheckedStatement = ParseUtilCSharp.ParseStatement("unchecked { }"); + Assert.IsNotNull(uncheckedStatement.Block); + } + + [Test] + public void UncheckedStatementAndExpressionTest() + { + UncheckedStatement uncheckedStatement = ParseUtilCSharp.ParseStatement("unchecked { unchecked(++i); }"); + ExpressionStatement es = (ExpressionStatement)uncheckedStatement.Block.Statements.Single(); + CheckedExpression ce = (CheckedExpression)es.Expression; + Assert.IsTrue(ce.Expression is UnaryOperatorExpression); + } + } +} diff --git a/ICSharpCode.NRefactory.Tests/CSharp/Parser/Statements/EmptyStatementTests.cs b/ICSharpCode.NRefactory.Tests/CSharp/Parser/Statements/EmptyStatementTests.cs new file mode 100644 index 0000000000..3bd72ab9c6 --- /dev/null +++ b/ICSharpCode.NRefactory.Tests/CSharp/Parser/Statements/EmptyStatementTests.cs @@ -0,0 +1,18 @@ +// Copyright (c) AlphaSierraPapa for the SharpDevelop Team (for details please see \doc\copyright.txt) +// This code is distributed under MIT X11 license (for details please see \doc\license.txt) + +using System; +using NUnit.Framework; + +namespace ICSharpCode.NRefactory.CSharp.Parser.Statements +{ + [TestFixture] + public class EmptyStatementTests + { + [Test] + public void CSharpEmptyStatementTest() + { + EmptyStatement emptyStmt = ParseUtilCSharp.ParseStatement(";"); + } + } +} diff --git a/ICSharpCode.NRefactory.Tests/CSharp/Parser/Statements/ExpressionStatementTests.cs b/ICSharpCode.NRefactory.Tests/CSharp/Parser/Statements/ExpressionStatementTests.cs new file mode 100644 index 0000000000..7d2e206e21 --- /dev/null +++ b/ICSharpCode.NRefactory.Tests/CSharp/Parser/Statements/ExpressionStatementTests.cs @@ -0,0 +1,26 @@ +// Copyright (c) AlphaSierraPapa for the SharpDevelop Team (for details please see \doc\copyright.txt) +// This code is distributed under MIT X11 license (for details please see \doc\license.txt) + +using System; +using NUnit.Framework; + +namespace ICSharpCode.NRefactory.CSharp.Parser.Statements +{ + [TestFixture] + public class ExpressionStatementTests + { + [Test] + public void StatementExpressionTest() + { + ExpressionStatement stmtExprStmt = ParseUtilCSharp.ParseStatement("my.Obj.PropCall;"); + Assert.IsTrue(stmtExprStmt.Expression is MemberReferenceExpression); + } + + [Test] + public void StatementExpressionTest1() + { + ExpressionStatement stmtExprStmt = ParseUtilCSharp.ParseStatement("yield.yield();"); + Assert.IsTrue(stmtExprStmt.Expression is InvocationExpression); + } + } +} diff --git a/ICSharpCode.NRefactory.Tests/CSharp/Parser/Statements/FixedStatementTests.cs b/ICSharpCode.NRefactory.Tests/CSharp/Parser/Statements/FixedStatementTests.cs new file mode 100644 index 0000000000..c9cd89a5c6 --- /dev/null +++ b/ICSharpCode.NRefactory.Tests/CSharp/Parser/Statements/FixedStatementTests.cs @@ -0,0 +1,19 @@ +// Copyright (c) AlphaSierraPapa for the SharpDevelop Team (for details please see \doc\copyright.txt) +// This code is distributed under MIT X11 license (for details please see \doc\license.txt) + +using System; +using NUnit.Framework; + +namespace ICSharpCode.NRefactory.CSharp.Parser.Statements +{ + [TestFixture] + public class FixedStatementTests + { + [Test] + public void CSharpFixedStatementTest() + { + FixedStatement fixedStmt = ParseUtilCSharp.ParseStatement("fixed (int* ptr = &myIntArr) { }"); + // TODO : Extend test. + } + } +} diff --git a/ICSharpCode.NRefactory.Tests/CSharp/Parser/Statements/ForStatementTests.cs b/ICSharpCode.NRefactory.Tests/CSharp/Parser/Statements/ForStatementTests.cs new file mode 100644 index 0000000000..f09d97c958 --- /dev/null +++ b/ICSharpCode.NRefactory.Tests/CSharp/Parser/Statements/ForStatementTests.cs @@ -0,0 +1,37 @@ +// Copyright (c) AlphaSierraPapa for the SharpDevelop Team (for details please see \doc\copyright.txt) +// This code is distributed under MIT X11 license (for details please see \doc\license.txt) + +using System; +using System.Linq; +using NUnit.Framework; + +namespace ICSharpCode.NRefactory.CSharp.Parser.Statements +{ + [TestFixture] + public class ForStatementTests + { + [Test] + public void CSharpForeachStatementTest() + { + ForeachStatement foreachStmt = ParseUtilCSharp.ParseStatement("foreach (int i in myColl) {} "); + // TODO : Extend test. + } + + [Test] + public void CSharpEmptyForStatementTest() + { + ForStatement forStmt = ParseUtilCSharp.ParseStatement("for (;;) ;"); + Assert.AreEqual(0, forStmt.Initializers.Count()); + Assert.AreEqual(0, forStmt.Iterators.Count()); + Assert.IsNull(forStmt.Condition); + Assert.IsTrue(forStmt.EmbeddedStatement is EmptyStatement); + } + + [Test] + public void CSharpForStatementTest() + { + ForStatement forStmt = ParseUtilCSharp.ParseStatement("for (int i = 5; i < 6; ++i) {} "); + // TODO : Extend test. + } + } +} diff --git a/ICSharpCode.NRefactory.Tests/CSharp/Parser/Statements/GotoStatementTests.cs b/ICSharpCode.NRefactory.Tests/CSharp/Parser/Statements/GotoStatementTests.cs new file mode 100644 index 0000000000..100c8481c1 --- /dev/null +++ b/ICSharpCode.NRefactory.Tests/CSharp/Parser/Statements/GotoStatementTests.cs @@ -0,0 +1,48 @@ +// Copyright (c) AlphaSierraPapa for the SharpDevelop Team (for details please see \doc\copyright.txt) +// This code is distributed under MIT X11 license (for details please see \doc\license.txt) + + +using System; +using NUnit.Framework; + +namespace ICSharpCode.NRefactory.CSharp.Parser.Statements +{ + [TestFixture] + public class GotoStatementTests + { + [Test] + public void GotoStatementTest() + { + GotoStatement gotoStmt = ParseUtilCSharp.ParseStatement("goto myLabel;"); + Assert.AreEqual(GotoType.Label, gotoStmt.GotoType); + Assert.AreEqual("myLabel", gotoStmt.Label); + } + + [Test] + public void GotoDefaultStatementTest() + { + GotoStatement gotoCaseStmt = ParseUtilCSharp.ParseStatement("goto default;"); + Assert.AreEqual(GotoType.CaseDefault, gotoCaseStmt.GotoType); + } + + [Test] + public void GotoCaseStatementTest() + { + GotoStatement gotoCaseStmt = ParseUtilCSharp.ParseStatement("goto case 6;"); + Assert.AreEqual(GotoType.Case, gotoCaseStmt.GotoType); + Assert.IsTrue(gotoCaseStmt.LabelExpression is PrimitiveExpression); + } + + [Test] + public void BreakStatementTest() + { + BreakStatement breakStmt = ParseUtilCSharp.ParseStatement("break;"); + } + + [Test] + public void ContinueStatementTest() + { + ContinueStatement continueStmt = ParseUtilCSharp.ParseStatement("continue;"); + } + } +} diff --git a/ICSharpCode.NRefactory.Tests/CSharp/Parser/Statements/IfElseStatementTests.cs b/ICSharpCode.NRefactory.Tests/CSharp/Parser/Statements/IfElseStatementTests.cs new file mode 100644 index 0000000000..2a2d4b905c --- /dev/null +++ b/ICSharpCode.NRefactory.Tests/CSharp/Parser/Statements/IfElseStatementTests.cs @@ -0,0 +1,39 @@ +// Copyright (c) AlphaSierraPapa for the SharpDevelop Team (for details please see \doc\copyright.txt) +// This code is distributed under MIT X11 license (for details please see \doc\license.txt) + +using System; +using NUnit.Framework; + +namespace ICSharpCode.NRefactory.CSharp.Parser.Statements +{ + [TestFixture] + public class IfElseStatementTests + { + [Test] + public void SimpleIfStatementTest() + { + IfElseStatement ifElseStatement = ParseUtilCSharp.ParseStatement("if (true) { }"); + Assert.IsTrue(ifElseStatement.Condition is PrimitiveExpression); + Assert.IsTrue(ifElseStatement.TrueEmbeddedStatement is BlockStatement); + Assert.IsNull(ifElseStatement.FalseEmbeddedStatement); + } + + [Test] + public void SimpleIfElseStatementTest() + { + IfElseStatement ifElseStatement = ParseUtilCSharp.ParseStatement("if (true) { } else { }"); + Assert.IsTrue(ifElseStatement.Condition is PrimitiveExpression); + Assert.IsTrue(ifElseStatement.TrueEmbeddedStatement is BlockStatement); + Assert.IsTrue(ifElseStatement.FalseEmbeddedStatement is BlockStatement); + } + + [Test] + public void IfElseIfStatementTest() + { + IfElseStatement ifElseStatement = ParseUtilCSharp.ParseStatement("if (1) { } else if (2) { } else if (3) { } else { }"); + Assert.IsTrue(ifElseStatement.Condition is PrimitiveExpression); + Assert.IsTrue(ifElseStatement.TrueEmbeddedStatement is BlockStatement); + Assert.IsTrue(ifElseStatement.FalseEmbeddedStatement is IfElseStatement); + } + } +} diff --git a/ICSharpCode.NRefactory.Tests/CSharp/Parser/Statements/LabelStatementTests.cs b/ICSharpCode.NRefactory.Tests/CSharp/Parser/Statements/LabelStatementTests.cs new file mode 100644 index 0000000000..24ccb16dfa --- /dev/null +++ b/ICSharpCode.NRefactory.Tests/CSharp/Parser/Statements/LabelStatementTests.cs @@ -0,0 +1,26 @@ +// Copyright (c) AlphaSierraPapa for the SharpDevelop Team (for details please see \doc\copyright.txt) +// This code is distributed under MIT X11 license (for details please see \doc\license.txt) + +using System; +using NUnit.Framework; + +namespace ICSharpCode.NRefactory.CSharp.Parser.Statements +{ + [TestFixture] + public class LabelStatementTests + { + [Test] + public void LabelStatementTest() + { + LabelStatement labelStmt = ParseUtilCSharp.ParseStatement("myLabel: ; "); + Assert.AreEqual("myLabel", labelStmt.Label); + } + + [Test] + public void Label2StatementTest() + { + LabelStatement labelStmt = ParseUtilCSharp.ParseStatement("yield: ; "); + Assert.AreEqual("yield", labelStmt.Label); + } + } +} diff --git a/ICSharpCode.NRefactory.Tests/CSharp/Parser/Statements/LockStatementTests.cs b/ICSharpCode.NRefactory.Tests/CSharp/Parser/Statements/LockStatementTests.cs new file mode 100644 index 0000000000..e415eb96b9 --- /dev/null +++ b/ICSharpCode.NRefactory.Tests/CSharp/Parser/Statements/LockStatementTests.cs @@ -0,0 +1,19 @@ +// Copyright (c) AlphaSierraPapa for the SharpDevelop Team (for details please see \doc\copyright.txt) +// This code is distributed under MIT X11 license (for details please see \doc\license.txt) + +using System; +using NUnit.Framework; + +namespace ICSharpCode.NRefactory.CSharp.Parser.Statements +{ + [TestFixture] + public class LockStatementTests + { + [Test] + public void CSharpLockStatementTest() + { + LockStatement lockStmt = ParseUtilCSharp.ParseStatement("lock (myObj) {}"); + // TODO : Extend test. + } + } +} diff --git a/ICSharpCode.NRefactory.Tests/CSharp/Parser/Statements/ReturnStatementTests.cs b/ICSharpCode.NRefactory.Tests/CSharp/Parser/Statements/ReturnStatementTests.cs new file mode 100644 index 0000000000..0a9d23e97c --- /dev/null +++ b/ICSharpCode.NRefactory.Tests/CSharp/Parser/Statements/ReturnStatementTests.cs @@ -0,0 +1,33 @@ +// Copyright (c) AlphaSierraPapa for the SharpDevelop Team (for details please see \doc\copyright.txt) +// This code is distributed under MIT X11 license (for details please see \doc\license.txt) + +using System; +using NUnit.Framework; + +namespace ICSharpCode.NRefactory.CSharp.Parser.Statements +{ + [TestFixture] + public class ReturnStatementTests + { + [Test] + public void EmptyReturnStatementTest() + { + ReturnStatement returnStatement = ParseUtilCSharp.ParseStatement("return;"); + Assert.IsNull(returnStatement.Expression); + } + + [Test] + public void ReturnStatementTest() + { + ReturnStatement returnStatement = ParseUtilCSharp.ParseStatement("return 5;"); + Assert.IsTrue(returnStatement.Expression is PrimitiveExpression); + } + + [Test] + public void ReturnStatementTest1() + { + ReturnStatement returnStatement = ParseUtilCSharp.ParseStatement("return yield;"); + Assert.IsTrue(returnStatement.Expression is IdentifierExpression); + } + } +} diff --git a/ICSharpCode.NRefactory.Tests/CSharp/Parser/Statements/SwitchStatementTests.cs b/ICSharpCode.NRefactory.Tests/CSharp/Parser/Statements/SwitchStatementTests.cs new file mode 100644 index 0000000000..0800ffb613 --- /dev/null +++ b/ICSharpCode.NRefactory.Tests/CSharp/Parser/Statements/SwitchStatementTests.cs @@ -0,0 +1,20 @@ +// Copyright (c) AlphaSierraPapa for the SharpDevelop Team (for details please see \doc\copyright.txt) +// This code is distributed under MIT X11 license (for details please see \doc\license.txt) + +using System; +using NUnit.Framework; + +namespace ICSharpCode.NRefactory.CSharp.Parser.Statements +{ + [TestFixture] + public class SwitchStatementTests + { + [Test] + public void SwitchStatementTest() + { + SwitchStatement switchStmt = ParseUtilCSharp.ParseStatement("switch (a) { case 4: case 5: break; case 6: break; default: break; }"); + Assert.AreEqual("a", ((IdentifierExpression)switchStmt.Expression).Identifier); + // TODO: Extend test + } + } +} diff --git a/ICSharpCode.NRefactory.Tests/CSharp/Parser/Statements/ThrowStatementTests.cs b/ICSharpCode.NRefactory.Tests/CSharp/Parser/Statements/ThrowStatementTests.cs new file mode 100644 index 0000000000..43a5d7b592 --- /dev/null +++ b/ICSharpCode.NRefactory.Tests/CSharp/Parser/Statements/ThrowStatementTests.cs @@ -0,0 +1,26 @@ +// Copyright (c) AlphaSierraPapa for the SharpDevelop Team (for details please see \doc\copyright.txt) +// This code is distributed under MIT X11 license (for details please see \doc\license.txt) + +using System; +using NUnit.Framework; + +namespace ICSharpCode.NRefactory.CSharp.Parser.Statements +{ + [TestFixture] + public class ThrowStatementTests + { + [Test] + public void EmptyThrowStatementTest() + { + ThrowStatement throwStmt = ParseUtilCSharp.ParseStatement("throw;"); + Assert.IsNull(throwStmt.Expression); + } + + [Test] + public void ThrowStatementTest() + { + ThrowStatement throwStmt = ParseUtilCSharp.ParseStatement("throw new Exception();"); + Assert.IsTrue(throwStmt.Expression is ObjectCreateExpression); + } + } +} diff --git a/ICSharpCode.NRefactory.Tests/CSharp/Parser/Statements/TryCatchStatementTests.cs b/ICSharpCode.NRefactory.Tests/CSharp/Parser/Statements/TryCatchStatementTests.cs new file mode 100644 index 0000000000..09a47fb175 --- /dev/null +++ b/ICSharpCode.NRefactory.Tests/CSharp/Parser/Statements/TryCatchStatementTests.cs @@ -0,0 +1,47 @@ +// Copyright (c) AlphaSierraPapa for the SharpDevelop Team (for details please see \doc\copyright.txt) +// This code is distributed under MIT X11 license (for details please see \doc\license.txt) + +using System; +using System.Linq; +using NUnit.Framework; + +namespace ICSharpCode.NRefactory.CSharp.Parser.Statements +{ + [TestFixture, Ignore] + public class TryCatchStatementTests + { + [Test] + public void CSharpSimpleTryCatchStatementTest() + { + TryCatchStatement tryCatchStatement = ParseUtilCSharp.ParseStatement("try { } catch { } "); + Assert.IsNull(tryCatchStatement.FinallyBlock); + Assert.AreEqual(1, tryCatchStatement.CatchClauses.Count()); + Assert.IsNull(tryCatchStatement.CatchClauses.Single().ReturnType); + Assert.IsNull(tryCatchStatement.CatchClauses.Single().VariableName); + } + + /* TODO port tests + [Test] + public void CSharpSimpleTryCatchStatementTest2() + { + TryCatchStatement tryCatchStatement = ParseUtilCSharp.ParseStatement("try { } catch (Exception e) { } "); + Assert.IsTrue(tryCatchStatement.FinallyBlock.IsNull); + Assert.AreEqual(1, tryCatchStatement.CatchClauses.Count); + Assert.AreEqual("Exception", tryCatchStatement.CatchClauses[0].TypeReference.Type); + Assert.AreEqual("e", tryCatchStatement.CatchClauses[0].VariableName); + } + + [Test] + public void CSharpSimpleTryCatchFinallyStatementTest() + { + TryCatchStatement tryCatchStatement = ParseUtilCSharp.ParseStatement("try { } catch (Exception) { } catch { } finally { } "); + Assert.IsFalse(tryCatchStatement.FinallyBlock.IsNull); + Assert.AreEqual(2, tryCatchStatement.CatchClauses.Count); + Assert.AreEqual("Exception", tryCatchStatement.CatchClauses[0].TypeReference.Type); + Assert.IsEmpty(tryCatchStatement.CatchClauses[0].VariableName); + Assert.IsTrue(tryCatchStatement.CatchClauses[1].TypeReference.IsNull); + Assert.IsEmpty(tryCatchStatement.CatchClauses[1].VariableName); + } + */ + } +} diff --git a/ICSharpCode.NRefactory.Tests/CSharp/Parser/Statements/UnsafeStatementTests.cs b/ICSharpCode.NRefactory.Tests/CSharp/Parser/Statements/UnsafeStatementTests.cs new file mode 100644 index 0000000000..eb89abdbe4 --- /dev/null +++ b/ICSharpCode.NRefactory.Tests/CSharp/Parser/Statements/UnsafeStatementTests.cs @@ -0,0 +1,19 @@ +// Copyright (c) AlphaSierraPapa for the SharpDevelop Team (for details please see \doc\copyright.txt) +// This code is distributed under MIT X11 license (for details please see \doc\license.txt) + +using System; +using NUnit.Framework; + +namespace ICSharpCode.NRefactory.CSharp.Parser.Statements +{ + [TestFixture] + public class UnsafeStatementTests + { + [Test] + public void CSharpUnsafeStatementTest() + { + UnsafeStatement unsafeStatement = ParseUtilCSharp.ParseStatement("unsafe { }"); + Assert.IsNotNull(unsafeStatement.Block); + } + } +} diff --git a/ICSharpCode.NRefactory.Tests/CSharp/Parser/Statements/UsingStatementTests.cs b/ICSharpCode.NRefactory.Tests/CSharp/Parser/Statements/UsingStatementTests.cs new file mode 100644 index 0000000000..07f7148c3b --- /dev/null +++ b/ICSharpCode.NRefactory.Tests/CSharp/Parser/Statements/UsingStatementTests.cs @@ -0,0 +1,19 @@ +// Copyright (c) AlphaSierraPapa for the SharpDevelop Team (for details please see \doc\copyright.txt) +// This code is distributed under MIT X11 license (for details please see \doc\license.txt) + +using System; +using NUnit.Framework; + +namespace ICSharpCode.NRefactory.CSharp.Parser.Statements +{ + [TestFixture] + public class UsingStatementTests + { + [Test] + public void CSharpUsingStatementTest() + { + UsingStatement usingStmt = ParseUtilCSharp.ParseStatement("using (MyVar var = new MyVar()) { } "); + // TODO : Extend test. + } + } +} diff --git a/ICSharpCode.NRefactory.Tests/CSharp/Parser/Statements/VariableDeclarationStatementTests.cs b/ICSharpCode.NRefactory.Tests/CSharp/Parser/Statements/VariableDeclarationStatementTests.cs new file mode 100644 index 0000000000..e9217e189b --- /dev/null +++ b/ICSharpCode.NRefactory.Tests/CSharp/Parser/Statements/VariableDeclarationStatementTests.cs @@ -0,0 +1,226 @@ +// Copyright (c) AlphaSierraPapa for the SharpDevelop Team (for details please see \doc\copyright.txt) +// This code is distributed under MIT X11 license (for details please see \doc\license.txt) + +using System; +using System.Linq; +using NUnit.Framework; + +namespace ICSharpCode.NRefactory.CSharp.Parser.Statements +{ + [TestFixture, Ignore] + public class VariableDeclarationStatementTests + { + [Test] + public void VariableDeclarationStatementTest() + { + VariableDeclarationStatement lvd = ParseUtilCSharp.ParseStatement("int a = 5;"); + Assert.AreEqual(1, lvd.Variables.Count()); + /*Assert.AreEqual("a", ((VariableDeclaration)lvd.Variables[0]).Name); + TypeReference type = lvd.GetTypeForVariable(0); + Assert.AreEqual("System.Int32", type.Type); + Assert.AreEqual(5, ((PrimitiveExpression)lvd.Variables[0].Initializer).Value);*/ throw new NotImplementedException(); + } + + /* TODO port unit tests + [Test] + public void VoidPointerVariableDeclarationTest() + { + VariableDeclarationStatement lvd = ParseUtilCSharp.ParseStatement("void *a;"); + Assert.AreEqual(1, lvd.Variables.Count); + Assert.AreEqual("a", ((VariableDeclaration)lvd.Variables[0]).Name); + TypeReference type = lvd.GetTypeForVariable(0); + Assert.AreEqual("System.Void", type.Type); + Assert.AreEqual(1, type.PointerNestingLevel); + } + + [Test] + public void ComplexGenericVariableDeclarationStatementTest() + { + VariableDeclarationStatement lvd = ParseUtilCSharp.ParseStatement("Generic > where = new Generic>();"); + Assert.AreEqual(1, lvd.Variables.Count); + Assert.AreEqual("where", ((VariableDeclaration)lvd.Variables[0]).Name); + TypeReference type = lvd.GetTypeForVariable(0); + Assert.AreEqual("Generic", type.Type); + Assert.AreEqual(2, type.GenericTypes.Count); + Assert.AreEqual("Namespace.Printable", type.GenericTypes[0].Type); + Assert.AreEqual(0, type.GenericTypes[0].GenericTypes.Count); + Assert.AreEqual("G", type.GenericTypes[1].Type); + Assert.AreEqual(1, type.GenericTypes[1].GenericTypes.Count); + Assert.AreEqual("Printable", type.GenericTypes[1].GenericTypes[0].Type); + + // TODO: Check initializer + } + + [Test] + public void NestedGenericVariableDeclarationStatementTest() + { + VariableDeclarationStatement lvd = ParseUtilCSharp.ParseStatement("MyType.InnerClass.InnerInnerClass a;"); + Assert.AreEqual(1, lvd.Variables.Count); + InnerClassTypeReference ic = (InnerClassTypeReference)lvd.GetTypeForVariable(0); + Assert.AreEqual("InnerInnerClass", ic.Type); + Assert.AreEqual(0, ic.GenericTypes.Count); + ic = (InnerClassTypeReference)ic.BaseType; + Assert.AreEqual("InnerClass", ic.Type); + Assert.AreEqual(1, ic.GenericTypes.Count); + Assert.AreEqual("System.Int32", ic.GenericTypes[0].Type); + Assert.AreEqual("MyType", ic.BaseType.Type); + Assert.AreEqual(1, ic.BaseType.GenericTypes.Count); + Assert.AreEqual("System.String", ic.BaseType.GenericTypes[0].Type); + } + + [Test] + public void GenericWithArrayVariableDeclarationStatementTest1() + { + VariableDeclarationStatement lvd = ParseUtilCSharp.ParseStatement("G[] a;"); + Assert.AreEqual(1, lvd.Variables.Count); + TypeReference type = lvd.GetTypeForVariable(0); + Assert.AreEqual("G", type.Type); + Assert.AreEqual(1, type.GenericTypes.Count); + Assert.AreEqual("System.Int32", type.GenericTypes[0].Type); + Assert.AreEqual(0, type.GenericTypes[0].GenericTypes.Count); + Assert.IsFalse(type.GenericTypes[0].IsArrayType); + Assert.AreEqual(new int[] {0}, type.RankSpecifier); + } + + [Test] + public void GenericWithArrayVariableDeclarationStatementTest2() + { + VariableDeclarationStatement lvd = ParseUtilCSharp.ParseStatement("G a;"); + Assert.AreEqual(1, lvd.Variables.Count); + TypeReference type = lvd.GetTypeForVariable(0); + Assert.AreEqual("G", type.Type); + Assert.AreEqual(1, type.GenericTypes.Count); + Assert.AreEqual("System.Int32", type.GenericTypes[0].Type); + Assert.AreEqual(0, type.GenericTypes[0].GenericTypes.Count); + Assert.IsFalse(type.IsArrayType); + Assert.AreEqual(new int[] {0}, type.GenericTypes[0].RankSpecifier); + } + + [Test] + public void GenericVariableDeclarationStatementTest2() + { + VariableDeclarationStatement lvd = ParseUtilCSharp.ParseStatement("G > a;"); + Assert.AreEqual(1, lvd.Variables.Count); + TypeReference type = lvd.GetTypeForVariable(0); + Assert.AreEqual("G", type.Type); + Assert.AreEqual(1, type.GenericTypes.Count); + Assert.AreEqual("G", type.GenericTypes[0].Type); + Assert.AreEqual(1, type.GenericTypes[0].GenericTypes.Count); + Assert.AreEqual("System.Int32", type.GenericTypes[0].GenericTypes[0].Type); + } + + [Test] + public void GenericVariableDeclarationStatementTest2WithoutSpace() + { + VariableDeclarationStatement lvd = ParseUtilCSharp.ParseStatement("G> a;"); + Assert.AreEqual(1, lvd.Variables.Count); + TypeReference type = lvd.GetTypeForVariable(0); + Assert.AreEqual("G", type.Type); + Assert.AreEqual(1, type.GenericTypes.Count); + Assert.AreEqual("G", type.GenericTypes[0].Type); + Assert.AreEqual(1, type.GenericTypes[0].GenericTypes.Count); + Assert.AreEqual("System.Int32", type.GenericTypes[0].GenericTypes[0].Type); + } + + [Test] + public void GenericVariableDeclarationStatementTest() + { + VariableDeclarationStatement lvd = ParseUtilCSharp.ParseStatement("G a;"); + Assert.AreEqual(1, lvd.Variables.Count); + TypeReference type = lvd.GetTypeForVariable(0); + Assert.AreEqual("G", type.Type); + Assert.AreEqual(1, type.GenericTypes.Count); + Assert.AreEqual("System.Int32", type.GenericTypes[0].Type); + } + + [Test] + public void SimpleVariableDeclarationStatementTest() + { + VariableDeclarationStatement lvd = ParseUtilCSharp.ParseStatement("MyVar var = new MyVar();"); + Assert.AreEqual(1, lvd.Variables.Count); + Assert.AreEqual("var", ((VariableDeclaration)lvd.Variables[0]).Name); + TypeReference type = lvd.GetTypeForVariable(0); + Assert.AreEqual("MyVar", type.Type); + // TODO: Check initializer + } + + [Test] + public void SimpleVariableDeclarationStatementTest1() + { + VariableDeclarationStatement lvd = ParseUtilCSharp.ParseStatement("yield yield = new yield();"); + Assert.AreEqual(1, lvd.Variables.Count); + Assert.AreEqual("yield", ((VariableDeclaration)lvd.Variables[0]).Name); + TypeReference type = lvd.GetTypeForVariable(0); + Assert.AreEqual("yield", type.Type); + // TODO: Check initializer + } + + [Test] + public void NullableVariableDeclarationStatementTest1() + { + VariableDeclarationStatement lvd = ParseUtilCSharp.ParseStatement("int? a;"); + Assert.AreEqual(1, lvd.Variables.Count); + Assert.AreEqual("a", ((VariableDeclaration)lvd.Variables[0]).Name); + TypeReference type = lvd.GetTypeForVariable(0); + Assert.AreEqual("System.Nullable", type.Type); + Assert.AreEqual("System.Int32", type.GenericTypes[0].Type); + } + + [Test] + public void NullableVariableDeclarationStatementTest2() + { + VariableDeclarationStatement lvd = ParseUtilCSharp.ParseStatement("DateTime? a;"); + Assert.AreEqual(1, lvd.Variables.Count); + Assert.AreEqual("a", ((VariableDeclaration)lvd.Variables[0]).Name); + TypeReference type = lvd.GetTypeForVariable(0); + Assert.AreEqual("System.Nullable", type.Type); + Assert.AreEqual("DateTime", type.GenericTypes[0].Type); + } + + [Test] + public void NullableVariableDeclarationStatementTest3() + { + VariableDeclarationStatement lvd = ParseUtilCSharp.ParseStatement("DateTime?[] a;"); + Assert.AreEqual(1, lvd.Variables.Count); + Assert.AreEqual("a", ((VariableDeclaration)lvd.Variables[0]).Name); + TypeReference type = lvd.GetTypeForVariable(0); + Assert.IsTrue(type.IsArrayType); + Assert.AreEqual("System.Nullable", type.Type); + Assert.AreEqual("DateTime", type.GenericTypes[0].Type); + } + + [Test] + public void NullableVariableDeclarationStatementTest4() + { + VariableDeclarationStatement lvd = ParseUtilCSharp.ParseStatement("SomeStruct? a;"); + Assert.AreEqual(1, lvd.Variables.Count); + Assert.AreEqual("a", ((VariableDeclaration)lvd.Variables[0]).Name); + TypeReference type = lvd.GetTypeForVariable(0); + Assert.AreEqual("System.Nullable", type.Type); + Assert.AreEqual("SomeStruct", type.GenericTypes[0].Type); + Assert.AreEqual("System.Nullable", type.GenericTypes[0].GenericTypes[0].Type); + Assert.AreEqual("System.Int32", type.GenericTypes[0].GenericTypes[0].GenericTypes[0].Type); + } + + [Test] + public void PositionTestWithoutModifier() + { + VariableDeclarationStatement lvd = ParseUtilCSharp.ParseStatement("\ndouble w = 7;"); + Assert.AreEqual(2, lvd.StartLocation.Line); + Assert.AreEqual(1, lvd.StartLocation.Column); + Assert.AreEqual(2, lvd.EndLocation.Line); + Assert.AreEqual(14, lvd.EndLocation.Column); + } + + [Test] + public void PositionTestWithModifier() + { + VariableDeclarationStatement lvd = ParseUtilCSharp.ParseStatement("\nconst double w = 7;"); + Assert.AreEqual(Modifiers.Const, lvd.Modifier); + Assert.AreEqual(2, lvd.StartLocation.Line); + Assert.AreEqual(1, lvd.StartLocation.Column); + Assert.AreEqual(2, lvd.EndLocation.Line); + Assert.AreEqual(20, lvd.EndLocation.Column); + }*/ + } +} diff --git a/ICSharpCode.NRefactory.Tests/CSharp/Parser/Statements/WhileStatementTests.cs b/ICSharpCode.NRefactory.Tests/CSharp/Parser/Statements/WhileStatementTests.cs new file mode 100644 index 0000000000..6ad09465da --- /dev/null +++ b/ICSharpCode.NRefactory.Tests/CSharp/Parser/Statements/WhileStatementTests.cs @@ -0,0 +1,30 @@ +// Copyright (c) AlphaSierraPapa for the SharpDevelop Team (for details please see \doc\copyright.txt) +// This code is distributed under MIT X11 license (for details please see \doc\license.txt) + +using System; +using NUnit.Framework; + +namespace ICSharpCode.NRefactory.CSharp.Parser.Statements +{ + [TestFixture] + public class WhileStatementTests + { + [Test] + public void WhileStatementTest() + { + WhileStatement loopStmt = ParseUtilCSharp.ParseStatement("while (true) { }"); + Assert.AreEqual(WhilePosition.Begin, loopStmt.WhilePosition); + Assert.IsTrue(loopStmt.Condition is PrimitiveExpression); + Assert.IsTrue(loopStmt.EmbeddedStatement is BlockStatement); + } + + [Test] + public void DoWhileStatementTest() + { + WhileStatement loopStmt = ParseUtilCSharp.ParseStatement("do { } while (true);"); + Assert.AreEqual(WhilePosition.End, loopStmt.WhilePosition); + Assert.IsTrue(loopStmt.Condition is PrimitiveExpression); + Assert.IsTrue(loopStmt.EmbeddedStatement is BlockStatement); + } + } +} diff --git a/ICSharpCode.NRefactory.Tests/CSharp/Parser/Statements/YieldStatementTests.cs b/ICSharpCode.NRefactory.Tests/CSharp/Parser/Statements/YieldStatementTests.cs new file mode 100644 index 0000000000..e2cc8ce560 --- /dev/null +++ b/ICSharpCode.NRefactory.Tests/CSharp/Parser/Statements/YieldStatementTests.cs @@ -0,0 +1,41 @@ +// Copyright (c) AlphaSierraPapa for the SharpDevelop Team (for details please see \doc\copyright.txt) +// This code is distributed under MIT X11 license (for details please see \doc\license.txt) + + +using System; +using NUnit.Framework; + +namespace ICSharpCode.NRefactory.CSharp.Parser.Statements +{ + [TestFixture] + public class YieldStatementTests + { + [Test] + public void YieldReturnStatementTest() + { + YieldStatement yieldStmt = ParseUtilCSharp.ParseStatement("yield return \"Foo\";"); + PrimitiveExpression expr = (PrimitiveExpression)yieldStmt.Expression; + Assert.AreEqual("Foo", expr.Value); + } + + [Test] + public void YieldBreakStatementTest() + { + YieldStatement yieldStmt = ParseUtilCSharp.ParseStatement("yield break;"); + Assert.IsNull(yieldStmt.Expression); + } + + [Test] + public void YieldAsVariableTest() + { + ExpressionStatement se = ParseUtilCSharp.ParseStatement("yield = 3;"); + AssignmentExpression ae = se.Expression as AssignmentExpression; + + Assert.AreEqual(AssignmentOperatorType.Assign, ae.AssignmentOperatorType); + + Assert.IsTrue(ae.Left is IdentifierExpression); + Assert.AreEqual("yield", ((IdentifierExpression)ae.Left).Identifier); + Assert.IsTrue(ae.Right is PrimitiveExpression); + } + } +} diff --git a/ICSharpCode.NRefactory.Tests/ICSharpCode.NRefactory.Tests.csproj b/ICSharpCode.NRefactory.Tests/ICSharpCode.NRefactory.Tests.csproj index 0aa0e766f7..0178799475 100644 --- a/ICSharpCode.NRefactory.Tests/ICSharpCode.NRefactory.Tests.csproj +++ b/ICSharpCode.NRefactory.Tests/ICSharpCode.NRefactory.Tests.csproj @@ -62,6 +62,25 @@ + + + + + + + + + + + + + + + + + + + @@ -125,6 +144,7 @@ + \ No newline at end of file diff --git a/ICSharpCode.NRefactory/CSharp/Dom/Statements/CheckedStatement.cs b/ICSharpCode.NRefactory/CSharp/Dom/Statements/CheckedStatement.cs index 2d912d684d..ca1d4e8c3b 100644 --- a/ICSharpCode.NRefactory/CSharp/Dom/Statements/CheckedStatement.cs +++ b/ICSharpCode.NRefactory/CSharp/Dom/Statements/CheckedStatement.cs @@ -1,4 +1,4 @@ -// +// // CheckedStatement.cs // // Author: @@ -31,8 +31,8 @@ namespace ICSharpCode.NRefactory.CSharp { public class CheckedStatement : AbstractNode { - public INode EmbeddedStatement { - get { return (INode)GetChildByRole (Roles.EmbeddedStatement); } + public BlockStatement Block { + get { return (BlockStatement)GetChildByRole (Roles.Body); } } public override S AcceptVisitor (IDomVisitor visitor, T data) diff --git a/ICSharpCode.NRefactory/CSharp/Dom/Statements/GotoStatement.cs b/ICSharpCode.NRefactory/CSharp/Dom/Statements/GotoStatement.cs index 7f2c0c95a6..c670ac005a 100644 --- a/ICSharpCode.NRefactory/CSharp/Dom/Statements/GotoStatement.cs +++ b/ICSharpCode.NRefactory/CSharp/Dom/Statements/GotoStatement.cs @@ -1,4 +1,4 @@ -// +// // GotoStatement.cs // // Author: @@ -40,7 +40,10 @@ namespace ICSharpCode.NRefactory.CSharp } public string Label { - get { return ((Identifier)LabelExpression).Name; } + get { + Identifier i = this.LabelExpression as Identifier; + return i != null ? i.Name : null; + } } public INode LabelExpression { diff --git a/ICSharpCode.NRefactory/CSharp/Dom/Statements/UncheckedStatement.cs b/ICSharpCode.NRefactory/CSharp/Dom/Statements/UncheckedStatement.cs index b60760db01..6f3cf0354c 100644 --- a/ICSharpCode.NRefactory/CSharp/Dom/Statements/UncheckedStatement.cs +++ b/ICSharpCode.NRefactory/CSharp/Dom/Statements/UncheckedStatement.cs @@ -1,4 +1,4 @@ -// +// // UncheckedStatement.cs // // Author: @@ -31,8 +31,8 @@ namespace ICSharpCode.NRefactory.CSharp { public class UncheckedStatement : AbstractNode { - public INode EmbeddedStatement { - get { return (INode)GetChildByRole (Roles.EmbeddedStatement); } + public BlockStatement Block { + get { return (BlockStatement)GetChildByRole (Roles.Body); } } public override S AcceptVisitor (IDomVisitor visitor, T data) diff --git a/ICSharpCode.NRefactory/CSharp/Dom/Statements/YieldStatement.cs b/ICSharpCode.NRefactory/CSharp/Dom/Statements/YieldStatement.cs index 36c3d396f8..3825df16c2 100644 --- a/ICSharpCode.NRefactory/CSharp/Dom/Statements/YieldStatement.cs +++ b/ICSharpCode.NRefactory/CSharp/Dom/Statements/YieldStatement.cs @@ -1,4 +1,4 @@ -// +// // YieldStatement.cs // // Author: @@ -34,6 +34,7 @@ namespace ICSharpCode.NRefactory.CSharp public const int YieldKeywordRole = 100; public const int ReturnKeywordRole = 101; public const int BreakKeywordRole = 102; + public INode Expression { get { return GetChildByRole (Roles.Expression); } } diff --git a/ICSharpCode.NRefactory/CSharp/Parser/CSharpParser.cs b/ICSharpCode.NRefactory/CSharp/Parser/CSharpParser.cs index cb6adb0965..102b4e9bc6 100644 --- a/ICSharpCode.NRefactory/CSharp/Parser/CSharpParser.cs +++ b/ICSharpCode.NRefactory/CSharp/Parser/CSharpParser.cs @@ -1133,7 +1133,7 @@ namespace ICSharpCode.NRefactory.CSharp { var result = new UncheckedStatement (); result.AddChild (new CSharpTokenNode (Convert (uncheckedStatement.loc), "unchecked".Length), UncheckedStatement.Roles.Keyword); - result.AddChild ((INode)uncheckedStatement.Block.Accept (this), UncheckedStatement.Roles.EmbeddedStatement); + result.AddChild ((INode)uncheckedStatement.Block.Accept (this), UncheckedStatement.Roles.Body); return result; } @@ -1142,7 +1142,7 @@ namespace ICSharpCode.NRefactory.CSharp { var result = new CheckedStatement (); result.AddChild (new CSharpTokenNode (Convert (checkedStatement.loc), "checked".Length), CheckedStatement.Roles.Keyword); - result.AddChild ((INode)checkedStatement.Block.Accept (this), CheckedStatement.Roles.EmbeddedStatement); + result.AddChild ((INode)checkedStatement.Block.Accept (this), CheckedStatement.Roles.Body); return result; }