27 changed files with 831 additions and 12 deletions
@ -0,0 +1,41 @@
@@ -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<BlockStatement>("{}"); |
||||
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<BlockStatement>(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()); |
||||
} |
||||
} |
||||
} |
||||
@ -0,0 +1,45 @@
@@ -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<CheckedStatement>("checked { }"); |
||||
Assert.IsNotNull(checkedStatement.Block); |
||||
} |
||||
|
||||
[Test] |
||||
public void CheckedStatementAndExpressionTest() |
||||
{ |
||||
CheckedStatement checkedStatement = ParseUtilCSharp.ParseStatement<CheckedStatement>("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<UncheckedStatement>("unchecked { }"); |
||||
Assert.IsNotNull(uncheckedStatement.Block); |
||||
} |
||||
|
||||
[Test] |
||||
public void UncheckedStatementAndExpressionTest() |
||||
{ |
||||
UncheckedStatement uncheckedStatement = ParseUtilCSharp.ParseStatement<UncheckedStatement>("unchecked { unchecked(++i); }"); |
||||
ExpressionStatement es = (ExpressionStatement)uncheckedStatement.Block.Statements.Single(); |
||||
CheckedExpression ce = (CheckedExpression)es.Expression; |
||||
Assert.IsTrue(ce.Expression is UnaryOperatorExpression); |
||||
} |
||||
} |
||||
} |
||||
@ -0,0 +1,18 @@
@@ -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<EmptyStatement>(";"); |
||||
} |
||||
} |
||||
} |
||||
@ -0,0 +1,26 @@
@@ -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<ExpressionStatement>("my.Obj.PropCall;"); |
||||
Assert.IsTrue(stmtExprStmt.Expression is MemberReferenceExpression); |
||||
} |
||||
|
||||
[Test] |
||||
public void StatementExpressionTest1() |
||||
{ |
||||
ExpressionStatement stmtExprStmt = ParseUtilCSharp.ParseStatement<ExpressionStatement>("yield.yield();"); |
||||
Assert.IsTrue(stmtExprStmt.Expression is InvocationExpression); |
||||
} |
||||
} |
||||
} |
||||
@ -0,0 +1,19 @@
@@ -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<FixedStatement>("fixed (int* ptr = &myIntArr) { }"); |
||||
// TODO : Extend test.
|
||||
} |
||||
} |
||||
} |
||||
@ -0,0 +1,37 @@
@@ -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<ForeachStatement>("foreach (int i in myColl) {} "); |
||||
// TODO : Extend test.
|
||||
} |
||||
|
||||
[Test] |
||||
public void CSharpEmptyForStatementTest() |
||||
{ |
||||
ForStatement forStmt = ParseUtilCSharp.ParseStatement<ForStatement>("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<ForStatement>("for (int i = 5; i < 6; ++i) {} "); |
||||
// TODO : Extend test.
|
||||
} |
||||
} |
||||
} |
||||
@ -0,0 +1,48 @@
@@ -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<GotoStatement>("goto myLabel;"); |
||||
Assert.AreEqual(GotoType.Label, gotoStmt.GotoType); |
||||
Assert.AreEqual("myLabel", gotoStmt.Label); |
||||
} |
||||
|
||||
[Test] |
||||
public void GotoDefaultStatementTest() |
||||
{ |
||||
GotoStatement gotoCaseStmt = ParseUtilCSharp.ParseStatement<GotoStatement>("goto default;"); |
||||
Assert.AreEqual(GotoType.CaseDefault, gotoCaseStmt.GotoType); |
||||
} |
||||
|
||||
[Test] |
||||
public void GotoCaseStatementTest() |
||||
{ |
||||
GotoStatement gotoCaseStmt = ParseUtilCSharp.ParseStatement<GotoStatement>("goto case 6;"); |
||||
Assert.AreEqual(GotoType.Case, gotoCaseStmt.GotoType); |
||||
Assert.IsTrue(gotoCaseStmt.LabelExpression is PrimitiveExpression); |
||||
} |
||||
|
||||
[Test] |
||||
public void BreakStatementTest() |
||||
{ |
||||
BreakStatement breakStmt = ParseUtilCSharp.ParseStatement<BreakStatement>("break;"); |
||||
} |
||||
|
||||
[Test] |
||||
public void ContinueStatementTest() |
||||
{ |
||||
ContinueStatement continueStmt = ParseUtilCSharp.ParseStatement<ContinueStatement>("continue;"); |
||||
} |
||||
} |
||||
} |
||||
@ -0,0 +1,39 @@
@@ -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<IfElseStatement>("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<IfElseStatement>("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<IfElseStatement>("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); |
||||
} |
||||
} |
||||
} |
||||
@ -0,0 +1,26 @@
@@ -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<LabelStatement>("myLabel: ; "); |
||||
Assert.AreEqual("myLabel", labelStmt.Label); |
||||
} |
||||
|
||||
[Test] |
||||
public void Label2StatementTest() |
||||
{ |
||||
LabelStatement labelStmt = ParseUtilCSharp.ParseStatement<LabelStatement>("yield: ; "); |
||||
Assert.AreEqual("yield", labelStmt.Label); |
||||
} |
||||
} |
||||
} |
||||
@ -0,0 +1,19 @@
@@ -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<LockStatement>("lock (myObj) {}"); |
||||
// TODO : Extend test.
|
||||
} |
||||
} |
||||
} |
||||
@ -0,0 +1,33 @@
@@ -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<ReturnStatement>("return;"); |
||||
Assert.IsNull(returnStatement.Expression); |
||||
} |
||||
|
||||
[Test] |
||||
public void ReturnStatementTest() |
||||
{ |
||||
ReturnStatement returnStatement = ParseUtilCSharp.ParseStatement<ReturnStatement>("return 5;"); |
||||
Assert.IsTrue(returnStatement.Expression is PrimitiveExpression); |
||||
} |
||||
|
||||
[Test] |
||||
public void ReturnStatementTest1() |
||||
{ |
||||
ReturnStatement returnStatement = ParseUtilCSharp.ParseStatement<ReturnStatement>("return yield;"); |
||||
Assert.IsTrue(returnStatement.Expression is IdentifierExpression); |
||||
} |
||||
} |
||||
} |
||||
@ -0,0 +1,20 @@
@@ -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<SwitchStatement>("switch (a) { case 4: case 5: break; case 6: break; default: break; }"); |
||||
Assert.AreEqual("a", ((IdentifierExpression)switchStmt.Expression).Identifier); |
||||
// TODO: Extend test
|
||||
} |
||||
} |
||||
} |
||||
@ -0,0 +1,26 @@
@@ -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<ThrowStatement>("throw;"); |
||||
Assert.IsNull(throwStmt.Expression); |
||||
} |
||||
|
||||
[Test] |
||||
public void ThrowStatementTest() |
||||
{ |
||||
ThrowStatement throwStmt = ParseUtilCSharp.ParseStatement<ThrowStatement>("throw new Exception();"); |
||||
Assert.IsTrue(throwStmt.Expression is ObjectCreateExpression); |
||||
} |
||||
} |
||||
} |
||||
@ -0,0 +1,47 @@
@@ -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<TryCatchStatement>("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<TryCatchStatement>("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<TryCatchStatement>("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); |
||||
} |
||||
*/ |
||||
} |
||||
} |
||||
@ -0,0 +1,19 @@
@@ -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<UnsafeStatement>("unsafe { }"); |
||||
Assert.IsNotNull(unsafeStatement.Block); |
||||
} |
||||
} |
||||
} |
||||
@ -0,0 +1,19 @@
@@ -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<UsingStatement>("using (MyVar var = new MyVar()) { } "); |
||||
// TODO : Extend test.
|
||||
} |
||||
} |
||||
} |
||||
@ -0,0 +1,226 @@
@@ -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<VariableDeclarationStatement>("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<VariableDeclarationStatement>("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<VariableDeclarationStatement>("Generic<Namespace.Printable, G<Printable[]> > where = new Generic<Namespace.Printable, G<Printable[]>>();"); |
||||
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<VariableDeclarationStatement>("MyType<string>.InnerClass<int>.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<VariableDeclarationStatement>("G<int>[] 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<VariableDeclarationStatement>("G<int[]> 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<VariableDeclarationStatement>("G<G<int> > 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<VariableDeclarationStatement>("G<G<int>> 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<VariableDeclarationStatement>("G<int> 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<VariableDeclarationStatement>("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<VariableDeclarationStatement>("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<VariableDeclarationStatement>("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<VariableDeclarationStatement>("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<VariableDeclarationStatement>("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<VariableDeclarationStatement>("SomeStruct<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("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<VariableDeclarationStatement>("\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<VariableDeclarationStatement>("\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); |
||||
}*/ |
||||
} |
||||
} |
||||
@ -0,0 +1,30 @@
@@ -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<WhileStatement>("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<WhileStatement>("do { } while (true);"); |
||||
Assert.AreEqual(WhilePosition.End, loopStmt.WhilePosition); |
||||
Assert.IsTrue(loopStmt.Condition is PrimitiveExpression); |
||||
Assert.IsTrue(loopStmt.EmbeddedStatement is BlockStatement); |
||||
} |
||||
} |
||||
} |
||||
@ -0,0 +1,41 @@
@@ -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<YieldStatement>("yield return \"Foo\";"); |
||||
PrimitiveExpression expr = (PrimitiveExpression)yieldStmt.Expression; |
||||
Assert.AreEqual("Foo", expr.Value); |
||||
} |
||||
|
||||
[Test] |
||||
public void YieldBreakStatementTest() |
||||
{ |
||||
YieldStatement yieldStmt = ParseUtilCSharp.ParseStatement<YieldStatement>("yield break;"); |
||||
Assert.IsNull(yieldStmt.Expression); |
||||
} |
||||
|
||||
[Test] |
||||
public void YieldAsVariableTest() |
||||
{ |
||||
ExpressionStatement se = ParseUtilCSharp.ParseStatement<ExpressionStatement>("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); |
||||
} |
||||
} |
||||
} |
||||
Loading…
Reference in new issue