Browse Source

Add failing unit test for using-statement with multiple variable declarations.

newNRvisualizers
Daniel Grunwald 14 years ago
parent
commit
c5c1337aee
  1. 2
      ICSharpCode.NRefactory.ConsistencyCheck/ResolverTest.cs
  2. 43
      ICSharpCode.NRefactory.Tests/CSharp/Parser/Statements/UsingStatementTests.cs
  3. 1
      ICSharpCode.NRefactory/TypeSystem/ITypeParameter.cs

2
ICSharpCode.NRefactory.ConsistencyCheck/ResolverTest.cs

@ -51,7 +51,7 @@ namespace ICSharpCode.NRefactory.ConsistencyCheck
this.fileName = fileName; this.fileName = fileName;
// We allow errors in XAML codebehind because we're currently not adding the XAML-generated // We allow errors in XAML codebehind because we're currently not adding the XAML-generated
// members to the type system. // members to the type system.
this.allowErrors = (fileName.Contains(".xaml") || File.Exists(Path.ChangeExtension(fileName, ".xaml"))); this.allowErrors = (fileName.Contains(".xaml") || File.Exists(Path.ChangeExtension(fileName, ".xaml")) || fileName.EndsWith("AvalonDockLayout.cs"));
} }
HashSet<AstNode> resolvedNodes = new HashSet<AstNode>(); HashSet<AstNode> resolvedNodes = new HashSet<AstNode>();

43
ICSharpCode.NRefactory.Tests/CSharp/Parser/Statements/UsingStatementTests.cs

@ -25,22 +25,45 @@ namespace ICSharpCode.NRefactory.CSharp.Parser.Statements
[TestFixture] [TestFixture]
public class UsingStatementTests public class UsingStatementTests
{ {
[Test, Ignore("Parser doesn't report the VariableDeclarationStatement")] [Test]
public void UsingStatementWithVariableDeclaration() public void UsingStatementWithVariableDeclaration()
{ {
UsingStatement usingStmt = ParseUtilCSharp.ParseStatement<UsingStatement>("using (MyVar var = new MyVar()) { } "); ParseUtilCSharp.AssertStatement(
VariableDeclarationStatement varDecl = (VariableDeclarationStatement)usingStmt.ResourceAcquisition; "using (MyVar var = new MyVar()) { }",
Assert.AreEqual("var", varDecl.Variables.Single().Name); new UsingStatement {
Assert.IsTrue(varDecl.Variables.Single().Initializer is ObjectCreateExpression); ResourceAcquisition = new VariableDeclarationStatement(
Assert.AreEqual("MyVar", ((SimpleType)varDecl.Type).Identifier); new SimpleType("MyVar"),
Assert.IsTrue(usingStmt.EmbeddedStatement is BlockStatement); "var",
new ObjectCreateExpression(new SimpleType("MyVar"))),
EmbeddedStatement = new BlockStatement()
});
}
[Test]
public void UsingStatementWithMultipleVariableDeclaration()
{
ParseUtilCSharp.AssertStatement(
"using (MyVar a = new MyVar(), b = null);",
new UsingStatement {
ResourceAcquisition = new VariableDeclarationStatement {
Type = new SimpleType("MyVar"),
Variables = {
new VariableInitializer("a", new ObjectCreateExpression(new SimpleType("MyVar"))),
new VariableInitializer("b", new NullReferenceExpression())
}
},
EmbeddedStatement = new EmptyStatement()
});
} }
public void UsingStatementWithExpression() public void UsingStatementWithExpression()
{ {
UsingStatement usingStmt = ParseUtilCSharp.ParseStatement<UsingStatement>("using (new MyVar()) { } "); ParseUtilCSharp.AssertStatement(
Assert.IsTrue(usingStmt.ResourceAcquisition is ObjectCreateExpression); "using (MyVar var = new MyVar()) { }",
Assert.IsTrue(usingStmt.EmbeddedStatement is BlockStatement); new UsingStatement {
ResourceAcquisition = new ObjectCreateExpression(new SimpleType("MyVar")),
EmbeddedStatement = new BlockStatement()
});
} }
} }
} }

1
ICSharpCode.NRefactory/TypeSystem/ITypeParameter.cs

@ -70,6 +70,7 @@ namespace ICSharpCode.NRefactory.TypeSystem
/// <summary> /// <summary>
/// Gets the owning method/class. /// Gets the owning method/class.
/// This property may return null (for example for the dummy type parameters used by <see cref="ParameterListComparer.NormalizeMethodTypeParameters"/>).
/// </summary> /// </summary>
IEntity Owner { get; } IEntity Owner { get; }

Loading…
Cancel
Save