|
// <file>
// <copyright see="prj:///doc/copyright.txt"/>
// <license see="prj:///doc/license.txt"/>
// <owner name="Mike Krüger" email="mike@icsharpcode.net"/>
// <version>$Revision: 1611 $</version>
// </file>
using System;
using ICSharpCode.NRefactory.Ast;
using NUnit.Framework;
namespace ICSharpCode.NRefactory.Tests.Ast
{
[TestFixture]
public class ConstructorDeclarationTests
{
#region C#
[Test]
public void CSharpConstructorDeclarationTest1()
{
ConstructorDeclaration cd = ParseUtilCSharp.ParseTypeMember<ConstructorDeclaration>("MyClass() {}");
Assert.IsTrue(cd.ConstructorInitializer.IsNull);
}
[Test]
public void CSharpConstructorDeclarationTest2()
{
ConstructorDeclaration cd = ParseUtilCSharp.ParseTypeMember<ConstructorDeclaration>("MyClass() : this(5) {}");
Assert.AreEqual(ConstructorInitializerType.This, cd.ConstructorInitializer.ConstructorInitializerType);
Assert.AreEqual(1, cd.ConstructorInitializer.Arguments.Count);
}
[Test]
public void CSharpConstructorDeclarationTest3()
{
ConstructorDeclaration cd = ParseUtilCSharp.ParseTypeMember<ConstructorDeclaration>("MyClass() : base(1, 2, 3) {}");
Assert.AreEqual(ConstructorInitializerType.Base, cd.ConstructorInitializer.ConstructorInitializerType);
Assert.AreEqual(3, cd.ConstructorInitializer.Arguments.Count);
}
#endregion
#region VB.NET
[Test]
public void VBNetConstructorDeclarationTest1()
{
string program = @"Sub New()
End Sub";
ConstructorDeclaration cd = ParseUtilVBNet.ParseTypeMember<ConstructorDeclaration>(program);
Assert.IsTrue(cd.ConstructorInitializer.IsNull);
}
[Test]
public void VBNetConstructorDeclarationTest2()
{
ConstructorDeclaration cd = ParseUtilVBNet.ParseTypeMember<ConstructorDeclaration>("Sub New(x As Integer, Optional y As String) \nEnd Sub");
Assert.AreEqual(2, cd.Parameters.Count);
Assert.AreEqual("Integer", cd.Parameters[0].TypeReference.Type);
Assert.AreEqual("String", cd.Parameters[1].TypeReference.Type);
Assert.AreEqual(ParameterModifiers.Optional, cd.Parameters[1].ParamModifier & ParameterModifiers.Optional);
}
#endregion
}
}
|
By viewing downloads associated with this article you agree to the Terms of Service and the article's licence.
If a file you wish to view isn't highlighted, and is a text file (not binary), please
let us know and we'll add colourisation support for it.
This article has no explicit license attached to it but may contain usage terms in the article text or the download files themselves. If in doubt please contact the author via the discussion board below.
A list of licenses authors might use can be found here
This member has not yet provided a Biography. Assume it's interesting and varied, and probably something to do with programming.