Permalink
Browse files

Squashed 'NRefactory/' changes from 2200240..a92606c

a92606c Some improvements to output visitor.
136fd88 Fix some parser issues.
41b4385 Port NRefactory to .NET 3.5.
3b6fe6f Adjust resolver to AST changes and disable failing unit tests.
93e9d1e Use implicit conversion operator to convert from Pattern to AST nodes.
b37ea77 Re-enabled the unit tests that were commented out.
defd426 AST bugfixes.
60d4fe9 Add pattern matching for query expressions. Pattern matching should now work for the complete C# AST.
b51f5a6 Add pattern matching for MemberDeclarations.

git-subtree-dir: NRefactory
git-subtree-split: a92606cb97ef6739d59b30a278d017cf64677f88
  • Loading branch information...
dgrunwald committed Mar 2, 2011
1 parent 7ac091e commit 39fcd7d72f73d386455d00d63446601c99eafb83
Showing with 2,055 additions and 1,038 deletions.
  1. +15 −0 ICSharpCode.NRefactory.Tests/CSharp/AstStructureTests.cs
  2. +27 −11 ICSharpCode.NRefactory.Tests/CSharp/Parser/Expression/AliasReferenceExpressionTests.cs
  3. +1 −0 ICSharpCode.NRefactory.Tests/CSharp/Parser/Expression/AnonymousMethodTests.cs
  4. +36 −16 ICSharpCode.NRefactory.Tests/CSharp/Parser/Expression/ArrayObjectCreateExpressionTests.cs
  5. +88 −63 ICSharpCode.NRefactory.Tests/CSharp/Parser/Expression/CastExpressionTests.cs
  6. +43 −17 ICSharpCode.NRefactory.Tests/CSharp/Parser/Expression/DefaultValueExpressionTests.cs
  7. +18 −10 ICSharpCode.NRefactory.Tests/CSharp/Parser/Expression/IdentifierExpressionTests.cs
  8. +97 −80 ICSharpCode.NRefactory.Tests/CSharp/Parser/Expression/InvocationExpressionTests.cs
  9. +8 −7 ICSharpCode.NRefactory.Tests/CSharp/Parser/Expression/IsExpressionTests.cs
  10. +68 −49 ICSharpCode.NRefactory.Tests/CSharp/Parser/Expression/LambdaExpressionTests.cs
  11. +55 −42 ICSharpCode.NRefactory.Tests/CSharp/Parser/Expression/MemberReferenceExpressionTests.cs
  12. +15 −3 ICSharpCode.NRefactory.Tests/CSharp/Parser/Expression/PointerReferenceExpressionTests.cs
  13. +174 −58 ICSharpCode.NRefactory.Tests/CSharp/Parser/Expression/QueryExpressionTests.cs
  14. +2 −2 ICSharpCode.NRefactory.Tests/CSharp/Parser/Expression/SizeOfExpressionTests.cs
  15. +6 −3 ICSharpCode.NRefactory.Tests/CSharp/Parser/Expression/StackAllocExpressionTests.cs
  16. +62 −35 ICSharpCode.NRefactory.Tests/CSharp/Parser/Expression/TypeOfExpressionTests.cs
  17. +3 −3 ICSharpCode.NRefactory.Tests/CSharp/Parser/Expression/UnaryOperatorExpressionTests.cs
  18. +27 −41 ICSharpCode.NRefactory.Tests/CSharp/Parser/GeneralScope/DelegateDeclarationTests.cs
  19. +117 −81 ICSharpCode.NRefactory.Tests/CSharp/Parser/GeneralScope/TypeDeclarationTests.cs
  20. +1 −1 ICSharpCode.NRefactory.Tests/CSharp/Parser/GeneralScope/UsingDeclarationTests.cs
  21. +40 −1 ICSharpCode.NRefactory.Tests/CSharp/Parser/ParseUtil.cs
  22. +13 −2 ICSharpCode.NRefactory.Tests/CSharp/Parser/Statements/FixedStatementTests.cs
  23. +14 −6 ICSharpCode.NRefactory.Tests/CSharp/Parser/Statements/ForStatementTests.cs
  24. +41 −15 ICSharpCode.NRefactory.Tests/CSharp/Parser/Statements/TryCatchStatementTests.cs
  25. +1 −2 ICSharpCode.NRefactory.Tests/CSharp/Parser/Statements/YieldStatementTests.cs
  26. +59 −54 ICSharpCode.NRefactory.Tests/CSharp/Parser/TypeMembers/EventDeclarationTests.cs
  27. +51 −11 ICSharpCode.NRefactory.Tests/CSharp/Parser/TypeMembers/FieldDeclarationTests.cs
  28. +24 −13 ICSharpCode.NRefactory.Tests/CSharp/Parser/TypeMembers/IndexerDeclarationTests.cs
  29. +153 −113 ICSharpCode.NRefactory.Tests/CSharp/Parser/TypeMembers/MethodDeclarationTests.cs
  30. +8 −8 ICSharpCode.NRefactory.Tests/CSharp/Parser/TypeMembers/OperatorDeclarationTests.cs
  31. +4 −6 ICSharpCode.NRefactory.Tests/CSharp/Parser/TypeMembers/PropertyDeclarationTests.cs
  32. +1 −1 ICSharpCode.NRefactory.Tests/CSharp/Resolver/InvocationTests.cs
  33. +5 −5 ICSharpCode.NRefactory.Tests/CSharp/Resolver/NameLookupTests.cs
  34. +1 −1 ICSharpCode.NRefactory.Tests/CSharp/Resolver/UnsafeCodeTests.cs
  35. +1 −0 ICSharpCode.NRefactory.Tests/ICSharpCode.NRefactory.Tests.csproj
  36. +1 −0 ICSharpCode.NRefactory.VB.Tests/ICSharpCode.NRefactory.VB.Tests.csproj
  37. +1 −0 ICSharpCode.NRefactory.VB/ICSharpCode.NRefactory.VB.csproj
  38. +3 −3 ICSharpCode.NRefactory/CSharp/Ast/AstLocation.cs
  39. +5 −0 ICSharpCode.NRefactory/CSharp/Ast/AstNode.cs
  40. +6 −12 ICSharpCode.NRefactory/CSharp/Ast/AstNodeCollection.cs
  41. +1 −1 ICSharpCode.NRefactory/CSharp/Ast/AstType.cs
  42. +6 −0 ICSharpCode.NRefactory/CSharp/Ast/CSharpModifierToken.cs
  43. +1 −1 ICSharpCode.NRefactory/CSharp/Ast/CSharpTokenNode.cs
  44. +1 −1 ICSharpCode.NRefactory/CSharp/Ast/Expressions/ArrayCreateExpression.cs
  45. +54 −7 ICSharpCode.NRefactory/CSharp/Ast/Expressions/QueryExpression.cs
  46. +9 −0 ICSharpCode.NRefactory/CSharp/Ast/GeneralScope/AttributeSection.cs
  47. +3 −2 ICSharpCode.NRefactory/CSharp/Ast/GeneralScope/Constraint.cs
  48. +14 −5 ICSharpCode.NRefactory/CSharp/Ast/GeneralScope/DelegateDeclaration.cs
  49. +9 −0 ICSharpCode.NRefactory/CSharp/Ast/GeneralScope/TypeDeclaration.cs
  50. +6 −1 ICSharpCode.NRefactory/CSharp/Ast/GeneralScope/TypeParameterDeclaration.cs
  51. +6 −1 ICSharpCode.NRefactory/CSharp/Ast/Identifier.cs
  52. +1 −1 ICSharpCode.NRefactory/CSharp/Ast/MemberType.cs
  53. +10 −15 ICSharpCode.NRefactory/CSharp/Ast/PatternMatching/Pattern.cs
  54. +52 −16 ICSharpCode.NRefactory/CSharp/Ast/PatternMatching/Placeholder.cs
  55. +1 −1 ICSharpCode.NRefactory/CSharp/Ast/SimpleType.cs
  56. +1 −1 ICSharpCode.NRefactory/CSharp/Ast/Statements/BlockStatement.cs
  57. +1 −1 ICSharpCode.NRefactory/CSharp/Ast/Statements/FixedStatement.cs
  58. +2 −1 ICSharpCode.NRefactory/CSharp/Ast/TypeMembers/Accessor.cs
  59. +2 −2 ICSharpCode.NRefactory/CSharp/Ast/TypeMembers/AttributedNode.cs
  60. +13 −1 ICSharpCode.NRefactory/CSharp/Ast/TypeMembers/ConstructorDeclaration.cs
  61. +7 −1 ICSharpCode.NRefactory/CSharp/Ast/TypeMembers/DestructorDeclaration.cs
  62. +9 −2 ICSharpCode.NRefactory/CSharp/Ast/TypeMembers/EnumMemberDeclaration.cs
  63. +24 −1 ICSharpCode.NRefactory/CSharp/Ast/TypeMembers/EventDeclaration.cs
  64. +19 −3 ICSharpCode.NRefactory/CSharp/Ast/TypeMembers/FieldDeclaration.cs
  65. +31 −3 ICSharpCode.NRefactory/CSharp/Ast/TypeMembers/IndexerDeclaration.cs
  66. +6 −0 ICSharpCode.NRefactory/CSharp/Ast/TypeMembers/MemberDeclaration.cs
  67. +11 −3 ICSharpCode.NRefactory/CSharp/Ast/TypeMembers/MethodDeclaration.cs
  68. +24 −3 ICSharpCode.NRefactory/CSharp/Ast/TypeMembers/OperatorDeclaration.cs
  69. +13 −1 ICSharpCode.NRefactory/CSharp/Ast/TypeMembers/ParameterDeclaration.cs
  70. +9 −2 ICSharpCode.NRefactory/CSharp/Ast/TypeMembers/PropertyDeclaration.cs
  71. +57 −20 ICSharpCode.NRefactory/CSharp/OutputVisitor/OutputVisitor.cs
  72. +26 −20 ICSharpCode.NRefactory/CSharp/Parser/CSharpParser.cs
  73. +42 −41 ICSharpCode.NRefactory/CSharp/Parser/TypeSystemConvertVisitor.cs
  74. +19 −9 ICSharpCode.NRefactory/CSharp/Resolver/CSharpResolver.cs
  75. +5 −5 ICSharpCode.NRefactory/CSharp/Resolver/MemberLookup.cs
  76. +1 −1 ICSharpCode.NRefactory/CSharp/Resolver/MemberTypeOrNamespaceReference.cs
  77. +1 −1 ICSharpCode.NRefactory/CSharp/Resolver/OverloadResolution.cs
  78. +31 −18 ICSharpCode.NRefactory/CSharp/Resolver/ResolveVisitor.cs
  79. +1 −1 ICSharpCode.NRefactory/CSharp/Resolver/SimpleTypeOrNamespaceReference.cs
  80. +1 −1 ICSharpCode.NRefactory/CSharp/Resolver/TypeInference.cs
  81. +12 −5 ICSharpCode.NRefactory/ICSharpCode.NRefactory.csproj
  82. +1 −1 ICSharpCode.NRefactory/TypeSystem/CecilLoader.cs
  83. +5 −3 ICSharpCode.NRefactory/TypeSystem/ExtensionMethods.cs
  84. +4 −0 ICSharpCode.NRefactory/TypeSystem/IAttribute.cs
  85. +4 −0 ICSharpCode.NRefactory/TypeSystem/IConstantValue.cs
  86. +4 −0 ICSharpCode.NRefactory/TypeSystem/IEntity.cs
  87. +4 −0 ICSharpCode.NRefactory/TypeSystem/IExplicitInterfaceImplementation.cs
  88. +4 −0 ICSharpCode.NRefactory/TypeSystem/IField.cs
  89. +4 −0 ICSharpCode.NRefactory/TypeSystem/IFreezable.cs
  90. +4 −0 ICSharpCode.NRefactory/TypeSystem/IInterningProvider.cs
  91. +4 −0 ICSharpCode.NRefactory/TypeSystem/IMember.cs
  92. +4 −7 ICSharpCode.NRefactory/TypeSystem/IMethod.cs
  93. +4 −0 ICSharpCode.NRefactory/TypeSystem/INamedElement.cs
  94. +4 −0 ICSharpCode.NRefactory/TypeSystem/IParameter.cs
  95. +4 −0 ICSharpCode.NRefactory/TypeSystem/IParameterizedMember.cs
  96. +4 −0 ICSharpCode.NRefactory/TypeSystem/IProjectContent.cs
  97. +4 −0 ICSharpCode.NRefactory/TypeSystem/ISupportsInterning.cs
  98. +4 −0 ICSharpCode.NRefactory/TypeSystem/IType.cs
  99. +4 −0 ICSharpCode.NRefactory/TypeSystem/ITypeDefinition.cs
  100. +4 −0 ICSharpCode.NRefactory/TypeSystem/ITypeParameter.cs
  101. +4 −0 ICSharpCode.NRefactory/TypeSystem/ITypeReference.cs
  102. +4 −0 ICSharpCode.NRefactory/TypeSystem/ITypeResolveContext.cs
  103. +4 −0 ICSharpCode.NRefactory/TypeSystem/IVariable.cs
  104. +1 −3 ICSharpCode.NRefactory/TypeSystem/Implementation/AbstractType.cs
  105. +0 −9 ICSharpCode.NRefactory/TypeSystem/Implementation/DefaultParameter.cs
  106. +6 −17 ICSharpCode.NRefactory/TypeSystem/Implementation/DefaultTypeDefinition.cs
  107. +18 −6 ICSharpCode.NRefactory/TypeSystem/Implementation/SimpleInterningProvider.cs
  108. +58 −0 ICSharpCode.NRefactory/Utils/DotNet35Compat.cs
  109. +4 −4 NRefactory.sln
  110. +23 −2 README
  111. +1 −0 VBDomGenerator/VBDomGenerator.csproj
  112. +21 −12 doc/TODO
@@ -27,5 +27,20 @@ public void RolesAreStaticReadOnly()
}
}
}
+
+ [Test]
+ public void AstNodesDoNotDeriveFromEachOther()
+ {
+ // Ast nodes should derive only from abstract classes; not from concrete types.
+ // For example, we want to avoid that an AST consumer doing "if (node is PropertyDeclaration)"
+ // unknowingly also handles IndexerDeclarations.
+ foreach (Type type in typeof(AstNode).Assembly.GetExportedTypes()) {
+ if (type == typeof(CSharpModifierToken)) // CSharpModifierToken is the exception (though I'm not too happy about that)
+ continue;
+ if (type.IsSubclassOf(typeof(AstNode))) {
+ Assert.IsTrue(type.BaseType.IsAbstract, type.FullName);
+ }
+ }
+ }
}
}
@@ -8,27 +8,43 @@
namespace ICSharpCode.NRefactory.CSharp.Parser.Expression
{
- [TestFixture]
+ [TestFixture, Ignore("Aliases not yet implemented")]
public class AliasReferenceExpressionTests
{
- [Test, Ignore]
+ [Test]
public void GlobalReferenceExpressionTest()
{
CSharpParser parser = new CSharpParser();
- parser.ParseTypeReference(new StringReader("global::System"));
- //Assert.IsTrue(tre.TypeReference.IsGlobal);
- //Assert.AreEqual("System", tre.TypeReference.Type);
- throw new NotImplementedException();
+ AstType type = parser.ParseTypeReference(new StringReader("global::System"));
+ Assert.IsNotNull(
+ new MemberType {
+ Target = new SimpleType("global"),
+ IsDoubleColon = true,
+ MemberName = "System"
+ }.Match(type)
+ );
}
- [Test, Ignore]
+ [Test]
public void GlobalTypeDeclaration()
{
VariableDeclarationStatement lvd = ParseUtilCSharp.ParseStatement<VariableDeclarationStatement>("global::System.String a;");
- //TypeReference typeRef = lvd.GetTypeForVariable(0);
- //Assert.IsTrue(typeRef.IsGlobal);
- //Assert.AreEqual("System.String", typeRef.Type);
- throw new NotImplementedException();
+ Assert.IsNotNull(
+ new VariableDeclarationStatement {
+ Type = new MemberType {
+ Target = new MemberType {
+ Target = new SimpleType("global"),
+ IsDoubleColon = true,
+ MemberName = "System"
+ },
+ IsDoubleColon = false,
+ MemberName = "String",
+ },
+ Variables = {
+ new VariableInitializer("a")
+ }
+ }.Match(lvd)
+ );
}
// TODO: add tests for aliases other than 'global'
@@ -47,6 +47,7 @@ public void EmptyAnonymousMethod()
public void SimpleAnonymousMethod()
{
AnonymousMethodExpression ame = Parse("delegate(int a, int b) { return a + b; }");
+ Assert.IsTrue(ame.HasParameterList);
Assert.AreEqual(2, ame.Parameters.Count());
Assert.AreEqual(1, ame.Body.Statements.Count());
Assert.IsTrue(ame.Body.Children.First() is ReturnStatement);
@@ -6,31 +6,51 @@
namespace ICSharpCode.NRefactory.CSharp.Parser.Expression
{
- [TestFixture, Ignore("Needs to be ported to new NRefactory")]
+ [TestFixture]
public class ArrayObjectCreateExpressionTests
{
[Test]
public void ArrayCreateExpressionTest1()
{
- /*
- ArrayCreateExpression ace = ParseUtilCSharp.ParseExpression<ArrayCreateExpression>("new int[5]");
- Assert.AreEqual("System.Int32", ace.CreateType.Type);
- Assert.IsTrue(ace.CreateType.IsKeyword);
- Assert.AreEqual(1, ace.Arguments.Count);
- Assert.AreEqual(new int[] {0}, ace.CreateType.RankSpecifier);
- */
- throw new NotImplementedException();
+ ParseUtilCSharp.AssertExpression(
+ "new int[5]",
+ new ArrayCreateExpression {
+ Type = new PrimitiveType("int"),
+ Arguments = { new PrimitiveExpression(5) }
+ });
}
- [Test]
+ [Test, Ignore("AdditionalArraySpecifiers not yet implemented")]
+ public void MultidimensionalNestedArray()
+ {
+ ParseUtilCSharp.AssertExpression(
+ "new int[5,2][,,][]",
+ new ArrayCreateExpression {
+ Type = new PrimitiveType("int"),
+ Arguments = { new PrimitiveExpression(5), new PrimitiveExpression(2) },
+ AdditionalArraySpecifiers = {
+ new ArraySpecifier(3),
+ new ArraySpecifier(1)
+ }
+ });
+ }
+
+ [Test, Ignore("Array initializers not yet implemented")]
public void ImplicitlyTypedArrayCreateExpression()
{
- /*
- ArrayCreateExpression ace = ParseUtilCSharp.ParseExpression<ArrayCreateExpression>("new[] { 1, 10, 100, 1000 }");
- Assert.AreEqual("", ace.CreateType.Type);
- Assert.AreEqual(0, ace.Arguments.Count);
- Assert.AreEqual(4, ace.ArrayInitializer.CreateExpressions.Count);*/
- throw new NotImplementedException();
+ ParseUtilCSharp.AssertExpression(
+ "new[] { 1, 10, 100, 1000 }",
+ new ArrayCreateExpression {
+ Initializer = new ArrayInitializerExpression {
+ Elements = {
+ new PrimitiveExpression(1),
+ new PrimitiveExpression(10),
+ new PrimitiveExpression(100),
+ new PrimitiveExpression(1000)
+ }
+ }
+ });
+
}
}
}
@@ -9,132 +9,157 @@ namespace ICSharpCode.NRefactory.CSharp.Parser.Expression
[TestFixture, Ignore("Port unit tests to new DOM")]
public class CastExpressionTests
{
- /*
[Test]
public void SimpleCastExpression()
{
- CastExpression ce = ParseUtilCSharp.ParseExpression<CastExpression>("(MyObject)o");
- Assert.AreEqual("MyObject", ce.CastTo.Type);
- Assert.IsTrue(ce.Expression is IdentifierExpression);
- Assert.AreEqual(CastType.Cast, ce.CastType);
+ ParseUtilCSharp.AssertExpression(
+ "(MyObject)o",
+ new CastExpression {
+ Type = new SimpleType("MyObject"),
+ Expression = new IdentifierExpression("o")
+ });
}
[Test]
public void ArrayCastExpression()
{
- CastExpression ce = ParseUtilCSharp.ParseExpression<CastExpression>("(MyType[])o");
- Assert.AreEqual("MyType", ce.CastTo.Type);
- Assert.AreEqual(new int[] { 0 }, ce.CastTo.RankSpecifier);
- Assert.IsTrue(ce.Expression is IdentifierExpression);
- Assert.AreEqual(CastType.Cast, ce.CastType);
+ ParseUtilCSharp.AssertExpression(
+ "(MyType[])o",
+ new CastExpression {
+ Type = new SimpleType("MyType").MakeArrayType(1),
+ Expression = new IdentifierExpression("o")
+ });
}
[Test]
public void NullablePrimitiveCastExpression()
{
- CastExpression ce = ParseUtilCSharp.ParseExpression<CastExpression>("(int?)o");
- Assert.AreEqual("System.Nullable", ce.CastTo.Type);
- Assert.AreEqual("System.Int32", ce.CastTo.GenericTypes[0].Type);
- Assert.IsTrue(ce.Expression is IdentifierExpression);
- Assert.AreEqual(CastType.Cast, ce.CastType);
+ ParseUtilCSharp.AssertExpression(
+ "(int?)o",
+ new CastExpression {
+ Type = new ComposedType { BaseType = new PrimitiveType("int"), HasNullableSpecifier = true },
+ Expression = new IdentifierExpression("o")
+ });
}
[Test]
public void NullableCastExpression()
{
- CastExpression ce = ParseUtilCSharp.ParseExpression<CastExpression>("(MyType?)o");
- Assert.AreEqual("System.Nullable", ce.CastTo.Type);
- Assert.AreEqual("MyType", ce.CastTo.GenericTypes[0].Type);
- Assert.IsTrue(ce.Expression is IdentifierExpression);
- Assert.AreEqual(CastType.Cast, ce.CastType);
+ ParseUtilCSharp.AssertExpression(
+ "(MyType?)o",
+ new CastExpression {
+ Type = new ComposedType { BaseType = new SimpleType("MyType"), HasNullableSpecifier = true },
+ Expression = new IdentifierExpression("o")
+ });
}
[Test]
public void NullableTryCastExpression()
{
- CastExpression ce = ParseUtilCSharp.ParseExpression<CastExpression>("o as int?");
- Assert.AreEqual("System.Nullable", ce.CastTo.Type);
- Assert.IsTrue(ce.CastTo.IsKeyword);
- Assert.AreEqual("System.Int32", ce.CastTo.GenericTypes[0].Type);
- Assert.IsTrue(ce.Expression is IdentifierExpression);
- Assert.AreEqual(CastType.TryCast, ce.CastType);
+ ParseUtilCSharp.AssertExpression(
+ "o as int?",
+ new AsExpression {
+ Type = new ComposedType { BaseType = new PrimitiveType("int"), HasNullableSpecifier = true },
+ Expression = new IdentifierExpression("o")
+ });
}
[Test]
public void GenericCastExpression()
{
- CastExpression ce = ParseUtilCSharp.ParseExpression<CastExpression>("(List<string>)o");
- Assert.AreEqual("List", ce.CastTo.Type);
- Assert.AreEqual("System.String", ce.CastTo.GenericTypes[0].Type);
- Assert.IsTrue(ce.Expression is IdentifierExpression);
- Assert.AreEqual(CastType.Cast, ce.CastType);
+ ParseUtilCSharp.AssertExpression(
+ "(List<string>)o",
+ new CastExpression {
+ Type = new SimpleType("List") { TypeArguments = { new PrimitiveType("string") } },
+ Expression = new IdentifierExpression("o")
+ });
}
[Test]
public void GenericArrayCastExpression()
{
- CastExpression ce = ParseUtilCSharp.ParseExpression<CastExpression>("(List<string>[])o");
- Assert.AreEqual("List", ce.CastTo.Type);
- Assert.AreEqual("System.String", ce.CastTo.GenericTypes[0].Type);
- Assert.AreEqual(new int[] { 0 }, ce.CastTo.RankSpecifier);
- Assert.IsTrue(ce.Expression is IdentifierExpression);
- Assert.AreEqual(CastType.Cast, ce.CastType);
+ ParseUtilCSharp.AssertExpression(
+ "(List<string>[])o",
+ new CastExpression {
+ Type = new ComposedType {
+ BaseType = new SimpleType("List") { TypeArguments = { new PrimitiveType("string") } },
+ ArraySpecifiers = { new ArraySpecifier(1) }
+ },
+ Expression = new IdentifierExpression("o")
+ });
}
[Test]
public void GenericArrayAsCastExpression()
{
- CastExpression ce = ParseUtilCSharp.ParseExpression<CastExpression>("o as List<string>[]");
- Assert.AreEqual("List", ce.CastTo.Type);
- Assert.AreEqual("System.String", ce.CastTo.GenericTypes[0].Type);
- Assert.AreEqual(new int[] { 0 }, ce.CastTo.RankSpecifier);
- Assert.IsTrue(ce.Expression is IdentifierExpression);
- Assert.AreEqual(CastType.TryCast, ce.CastType);
+ ParseUtilCSharp.AssertExpression(
+ "o as List<string>[]",
+ new AsExpression {
+ Type = new ComposedType {
+ BaseType = new SimpleType("List") { TypeArguments = { new PrimitiveType("string") } },
+ ArraySpecifiers = { new ArraySpecifier(1) }
+ },
+ Expression = new IdentifierExpression("o")
+ });
}
[Test]
public void CastMemberReferenceOnParenthesizedExpression()
{
- // yes, we really wanted to evaluate .Member on expr and THEN cast the result to MyType
- CastExpression ce = ParseUtilCSharp.ParseExpression<CastExpression>("(MyType)(expr).Member");
- Assert.AreEqual("MyType", ce.CastTo.Type);
- Assert.IsTrue(ce.Expression is MemberReferenceExpression);
- Assert.AreEqual(CastType.Cast, ce.CastType);
+ // yes, we really want to evaluate .Member on expr and THEN cast the result to MyType
+ ParseUtilCSharp.AssertExpression(
+ "(MyType)(expr).Member",
+ new CastExpression {
+ Type = new SimpleType("MyType"),
+ Expression = new ParenthesizedExpression { Expression = new IdentifierExpression("expr") }.Member("Member")
+ });
}
[Test]
public void TryCastParenthesizedExpression()
{
- CastExpression ce = ParseUtilCSharp.ParseExpression<CastExpression>("(o) as string");
- Assert.AreEqual("System.String", ce.CastTo.ToString());
- Assert.IsTrue(ce.Expression is ParenthesizedExpression);
- Assert.AreEqual(CastType.TryCast, ce.CastType);
+ ParseUtilCSharp.AssertExpression(
+ "(o) as string",
+ new AsExpression {
+ Expression = new ParenthesizedExpression { Expression = new IdentifierExpression("o") },
+ Type = new PrimitiveType("string")
+ });
}
[Test]
public void CastNegation()
{
- CastExpression ce = ParseUtilCSharp.ParseExpression<CastExpression>("(uint)-negativeValue");
- Assert.AreEqual("System.UInt32", ce.CastTo.ToString());
- Assert.IsTrue(ce.Expression is UnaryOperatorExpression);
- Assert.AreEqual(CastType.Cast, ce.CastType);
+ ParseUtilCSharp.AssertExpression(
+ "(uint)-negativeValue",
+ new CastExpression {
+ Type = new PrimitiveType("uint"),
+ Expression = new UnaryOperatorExpression(
+ UnaryOperatorType.Minus,
+ new IdentifierExpression("negativeValue")
+ )});
}
- */
[Test]
public void SubtractionIsNotCast()
{
- BinaryOperatorExpression boe = ParseUtilCSharp.ParseExpression<BinaryOperatorExpression>("(BigInt)-negativeValue");
- Assert.IsTrue(boe.Left is ParenthesizedExpression);
- Assert.IsTrue(boe.Right is IdentifierExpression);
+ ParseUtilCSharp.AssertExpression(
+ "(BigInt)-negativeValue",
+ new BinaryOperatorExpression {
+ Left = new ParenthesizedExpression { Expression = new IdentifierExpression("BigInt") },
+ Operator = BinaryOperatorType.Subtract,
+ Right = new IdentifierExpression("negativeValue")
+ });
}
[Test]
public void IntMaxValueToBigInt()
{
- CastExpression ce = ParseUtilCSharp.ParseExpression<CastExpression>("(BigInt)int.MaxValue");
- Assert.AreEqual("BigInt", ce.Type.ToString());
- Assert.IsTrue(ce.Expression is MemberReferenceExpression);
+ ParseUtilCSharp.AssertExpression(
+ "(BigInt)int.MaxValue",
+ new CastExpression {
+ Type = new SimpleType("BigInt"),
+ Expression = new PrimitiveExpression("int").Member("MaxValue")
+ });
}
}
}
Oops, something went wrong.

0 comments on commit 39fcd7d

Please sign in to comment.