mirror of
https://github.com/BepInEx/mono.git
synced 2026-11-17 11:21:39 -10:00
CodeCatchClauseTest.cs, CodeChecksumPragmaTest.cs, CodeConstructorTest.cs, CodeDefaultValueExpressionTest.cs; CodeDelegateCreateExpressionTest.cs, CodeEventReferenceExpressionTest.cs CodeGotoStatementTest.cs, CodeLabeledStatementTest.cs, CodeLinePragmaTest.cs, CodeMemberMethodTest.cs, CodeMethodInvokeExpressionTest.cs, CodeMethodReferenceExpressionTest.cs, CodeNamespaceImportTest.cs, CodeNamespaceTest.cs, CodeObjectCreateExpressionTest.cs, CodeParameterDeclarationExpressionTest.cs, CodePropertyReferenceExpressionTest.cs, CodeRegionDirectiveTest.cs, CodeSnippetCompileUnitTest.cs, CodeSnippetExpressionTest.cs, CodeSnippetStatementTest.cs, CodeSnippetTypeMemberTest.cs, CodeStatementCollectionTest.cs, CodeTypeConstructorTest.cs, CodeTypeParameterTest.cs, CodeTypeOfExpressionTest.cs, CodeTypeReferenceExpressionTest.cs, CodeVariableDeclarationStatementTest.cs, CodeVariableReferenceExpressionTest.cs * CSharpCodeGenerator.cs: Ignore ChecksumData of CodeChecksumPragma if null. * CodeTypeReferenceExpressionTest.cs: Added tests. * CodeVariableDeclarationStatementTest.cs: Added tests. * CodePropertyReferenceExpressionTest.cs: Added tests. * CodeNamespaceImportTest.cs: Added tests. * CodeTypeConstructorTest.cs: Added tests. * CodeSnippetExpressionTest.cs: Added tests. * CodeParameterDeclarationExpressionTest.cs: Added tests. * CodeObjectCreateExpressionTest.cs: Added tests. * CodeTypeDelegateTest.cs: Set eol-style to native. * CodeLabeledStatementTest.cs: Added tests. * CodeConstructorTest.cs: Added tests. * CodeTypeOfExpressionTest.cs: Added tests. * CodeGotoStatementTest.cs: Added tests. * CodeCastExpressionTest.cs: Added tests. * CodeMemberFieldTest.cs: Set eol-style to native. * CodeMethodInvokeExpressionTest.cs: Added tests. * CodeEventReferenceExpressionTest.cs: Added tests. * CodeChecksumPragmaTest.cs: Added tests. * CodeSnippetCompileUnitTest.cs: Added tests. * CodeNamespaceTest.cs: Added tests. * CodeSnippetStatementTest.cs: Added tests. * CodeMemberMethodTest.cs: Added tests. * CodeMemberPropertyTest.cs: Set eol-style to native. * CodeCatchClauseTest.cs: Added tests. * CodeStatementCollectionTest.cs: Added tests. * CodeRegionDirectiveTest.cs: Added tests. * CodeTypeParameterTest.cs: Added tests. * CodeVariableReferenceExpressionTest.cs: Added tests. * CodeDefaultValueExpressionTest.cs: Added tests. * CodeSnippetTypeMemberTest.cs: Added tests. * CodeDelegateCreateExpressionTest.cs: Added tests. * CodeLinePragmaTest.cs: Added tests. * CodeMethodReferenceExpressionTest.cs: Added tests. * CodeEventReferenceExpression.cs: EventName now returns zero-length string if underlying value is null. * CodeParameterDeclarationExpressionCollection.cs: Fixed AddRange to add each item to collection using Add method to ensure validation is performed. * CodeChecksumPragma.cs: FileName now returns zero-length string if underlying value is null. * CodeSnippetCompileUnit.cs: Value now returns zero-length string if underlying value is null. * CodeNamespace.cs: Name now returns zero-length string if underlying value is null. * CodeSnippetStatement.cs: Value now returns zero-length string if underlying value is null. * CodeMemberMethod.cs: code formatting change. * CodeCatchClause.cs: CatchExceptionType now returns CodeTypeReference instance for System.Exception if underlying value is null. LocalName now returns zero-length string if underlying value is null. * CodeStatementCollection.cs: Fixed AddRange to add each item to collection using Add method to ensure validation is performed. Code formatting changes. * CodeRegionDirective.cs: RegionText now returns zero-length string if underlying value is null. * CodeTypeParameter.cs: Name now returns zero-length string if underlying value is null. * CodeVariableReferenceExpression.cs: VariableName now returns zero-length string if underlying value is null. * CodeDefaultValueExpression.cs: Type now returns CodeTypeReference for void if underlying value is null. * CodeExpressionCollection.cs: Fixed AddRange to add each item to collection using Add method to ensure validation is performed. * CodeSnippetTypeMember.cs: Text now returns zero-length string if underlying value is null. * CodeTypeReferenceCollection.cs: Fixed AddRange to add each item to collection using Add method to ensure validation is performed. * CodeDelegateCreateExpression.cs: DelegateType now returns CodeTypeReference for void if underlying value is null. MethodName now returns zero-length string if underlying value is null. * CodeMethodReferenceExpression.cs: MethodName now returns zero-length string if underlying value is null. * CodeLinePragma.cs: FileName now returns zero-length string if underlying value is null. * CodeTypeReferenceExpression.cs: Type now return CodeTypeReference for void if underlying value is null. * CodeVariableDeclarationStatement.cs: Name now return zero-length string if underlying value is null. Type returns CodeTypeReference for void if underlying value is null. * CodePropertyReferenceExpression.cs: PropertyName now returns zero-length string if underlying value is null. * CodeNamespaceImport.cs: Namespace now returns zero-length string if underlying value is null. * CodeTypeConstructor.cs: Name is fixed to ".cctor" to match MS.NET. * CodeSnippetExpression.cs: Value now returns zero-length string if underlying value is null. * CodeParameterDeclarationExpression.cs: Name now returns zero-length string if underlying value is null. Type now returns CodeTypeReference for void if underlying value is null. * CodeObjectCreateExpression.cs: CreateType now returns CodeTypeReference for void if underlying value is null. * CodeLabeledStatement.cs: Label returns zero-length string if underlying value is null. * CodeConstructor.cs: Name is fixed to ".ctor" to match MS.NET. * CodeTypeOfExpression.cs: Type returns CodeTypeReference for void if underlying value is null. * CodeGotoStatement.cs: Only throw ArgumentNullException for null or zero-length label on 2.0 profile. * CodeCastExpression.cs: TargetType returns CodeTypeReference for void if underlying value is null. * CodeMethodInvokeExpression.cs: Method returns a default CodeMethodReferenceExpression instance if the underlying value is null. svn path=/trunk/mcs/; revision=52579
255 lines
8.4 KiB
C#
255 lines
8.4 KiB
C#
//
|
|
// CodeVariableDeclarationStatementTest.cs
|
|
// - Unit tests for System.CodeDom.CodeVariableDeclarationStatement
|
|
//
|
|
// Author:
|
|
// Gert Driesen <[email protected]>
|
|
//
|
|
// Copyright (C) 2005 Novell, Inc (http://www.novell.com)
|
|
//
|
|
// Permission is hereby granted, free of charge, to any person obtaining
|
|
// a copy of this software and associated documentation files (the
|
|
// "Software"), to deal in the Software without restriction, including
|
|
// without limitation the rights to use, copy, modify, merge, publish,
|
|
// distribute, sublicense, and/or sell copies of the Software, and to
|
|
// permit persons to whom the Software is furnished to do so, subject to
|
|
// the following conditions:
|
|
//
|
|
// The above copyright notice and this permission notice shall be
|
|
// included in all copies or substantial portions of the Software.
|
|
//
|
|
// THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND,
|
|
// EXPRESS OR IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF
|
|
// MERCHANTABILITY, FITNESS FOR A PARTICULAR PURPOSE AND
|
|
// NONINFRINGEMENT. IN NO EVENT SHALL THE AUTHORS OR COPYRIGHT HOLDERS BE
|
|
// LIABLE FOR ANY CLAIM, DAMAGES OR OTHER LIABILITY, WHETHER IN AN ACTION
|
|
// OF CONTRACT, TORT OR OTHERWISE, ARISING FROM, OUT OF OR IN CONNECTION
|
|
// WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN THE SOFTWARE.
|
|
//
|
|
|
|
using NUnit.Framework;
|
|
|
|
using System;
|
|
using System.CodeDom;
|
|
|
|
namespace MonoTests.System.CodeDom
|
|
{
|
|
[TestFixture]
|
|
public class CodeVariableDeclarationStatementTest
|
|
{
|
|
[Test]
|
|
public void Constructor0 ()
|
|
{
|
|
CodeVariableDeclarationStatement cvds = new CodeVariableDeclarationStatement ();
|
|
Assert.IsNull (cvds.InitExpression, "#1");
|
|
Assert.IsNotNull (cvds.Name, "#2");
|
|
Assert.AreEqual (string.Empty, cvds.Name, "#3");
|
|
Assert.IsNotNull (cvds.Type, "#4");
|
|
Assert.AreEqual (typeof (void).FullName, cvds.Type.BaseType, "#5");
|
|
|
|
string name = "mono";
|
|
cvds.Name = name;
|
|
Assert.AreSame (name, cvds.Name, "#6");
|
|
|
|
cvds.Name = null;
|
|
Assert.IsNotNull (cvds.Name, "#7");
|
|
Assert.AreEqual (string.Empty, cvds.Name, "#8");
|
|
|
|
CodeExpression expression = new CodeExpression ();
|
|
cvds.InitExpression = expression;
|
|
Assert.AreSame (expression, cvds.InitExpression, "#9");
|
|
|
|
CodeTypeReference type = new CodeTypeReference ("mono");
|
|
cvds.Type = type;
|
|
Assert.AreSame (type, cvds.Type, "#10");
|
|
|
|
cvds.Type = null;
|
|
Assert.IsNotNull (cvds.Type, "#11");
|
|
Assert.AreEqual (typeof (void).FullName, cvds.Type.BaseType, "#12");
|
|
|
|
#if NET_2_0
|
|
Assert.IsNotNull (cvds.StartDirectives, "#13");
|
|
Assert.AreEqual (0, cvds.StartDirectives.Count, "#14");
|
|
|
|
Assert.IsNotNull (cvds.EndDirectives, "#15");
|
|
Assert.AreEqual (0, cvds.EndDirectives.Count, "#16");
|
|
#endif
|
|
|
|
Assert.IsNull (cvds.LinePragma, "#17");
|
|
|
|
CodeLinePragma clp = new CodeLinePragma ("mono", 10);
|
|
cvds.LinePragma = clp;
|
|
Assert.IsNotNull (cvds.LinePragma, "#18");
|
|
Assert.AreSame (clp, cvds.LinePragma, "#19");
|
|
|
|
cvds.LinePragma = null;
|
|
Assert.IsNull (cvds.LinePragma, "#20");
|
|
}
|
|
|
|
[Test]
|
|
public void Constructor1 ()
|
|
{
|
|
CodeTypeReference type = new CodeTypeReference ("mono");
|
|
string name = "mono";
|
|
|
|
CodeVariableDeclarationStatement cvds = new CodeVariableDeclarationStatement (
|
|
type, name);
|
|
Assert.IsNull (cvds.InitExpression, "#1");
|
|
Assert.IsNotNull (cvds.Name, "#2");
|
|
Assert.AreSame (name, cvds.Name, "#3");
|
|
Assert.IsNotNull (cvds.Type, "#4");
|
|
Assert.AreSame (type, cvds.Type, "#5");
|
|
|
|
cvds = new CodeVariableDeclarationStatement ((CodeTypeReference) null,
|
|
(string) null);
|
|
Assert.IsNotNull (cvds.Name, "#6");
|
|
Assert.AreEqual (string.Empty, cvds.Name, "#7");
|
|
Assert.IsNotNull (cvds.Type, "#8");
|
|
Assert.AreEqual (typeof (void).FullName, cvds.Type.BaseType, "#9");
|
|
}
|
|
|
|
[Test]
|
|
public void Constructor2 ()
|
|
{
|
|
string baseType = "monotype";
|
|
string name = "mono";
|
|
|
|
CodeVariableDeclarationStatement cvds = new CodeVariableDeclarationStatement (
|
|
baseType, name);
|
|
Assert.IsNull (cvds.InitExpression, "#1");
|
|
Assert.IsNotNull (cvds.Name, "#2");
|
|
Assert.AreSame (name, cvds.Name, "#3");
|
|
Assert.IsNotNull (cvds.Type, "#4");
|
|
Assert.AreSame (baseType, cvds.Type.BaseType, "#5");
|
|
|
|
cvds = new CodeVariableDeclarationStatement ((string) null,
|
|
(string) null);
|
|
Assert.IsNotNull (cvds.Name, "#6");
|
|
Assert.AreEqual (string.Empty, cvds.Name, "#7");
|
|
Assert.IsNotNull (cvds.Type, "#8");
|
|
Assert.AreEqual (typeof (void).FullName, cvds.Type.BaseType, "#9");
|
|
}
|
|
|
|
[Test]
|
|
public void Constructor3 ()
|
|
{
|
|
Type baseType = typeof (int);
|
|
string name = "mono";
|
|
|
|
CodeVariableDeclarationStatement cvds = new CodeVariableDeclarationStatement (
|
|
baseType, name);
|
|
Assert.IsNull (cvds.InitExpression, "#1");
|
|
Assert.IsNotNull (cvds.Name, "#2");
|
|
Assert.AreSame (name, cvds.Name, "#3");
|
|
Assert.IsNotNull (cvds.Type, "#4");
|
|
Assert.AreEqual (baseType.FullName, cvds.Type.BaseType, "#5");
|
|
|
|
cvds = new CodeVariableDeclarationStatement (baseType,
|
|
(string) null);
|
|
Assert.IsNotNull (cvds.Name, "#6");
|
|
Assert.AreEqual (string.Empty, cvds.Name, "#7");
|
|
Assert.IsNotNull (cvds.Type, "#8");
|
|
Assert.AreEqual (baseType.FullName, cvds.Type.BaseType, "#9");
|
|
}
|
|
|
|
[Test]
|
|
#if NET_2_0
|
|
[ExpectedException (typeof (ArgumentNullException))]
|
|
#else
|
|
[ExpectedException (typeof (NullReferenceException))]
|
|
#endif
|
|
public void Constructor3_NullType ()
|
|
{
|
|
CodeVariableDeclarationStatement cvds = new CodeVariableDeclarationStatement (
|
|
(Type) null, "mono");
|
|
}
|
|
|
|
[Test]
|
|
public void Constructor4 ()
|
|
{
|
|
CodeTypeReference type = new CodeTypeReference ("mono");
|
|
string name = "mono";
|
|
CodeExpression expression = new CodeExpression ();
|
|
|
|
CodeVariableDeclarationStatement cvds = new CodeVariableDeclarationStatement (
|
|
type, name, expression);
|
|
Assert.IsNotNull (cvds.InitExpression, "#1");
|
|
Assert.AreSame (expression, cvds.InitExpression, "#2");
|
|
Assert.IsNotNull (cvds.Name, "#3");
|
|
Assert.AreSame (name, cvds.Name, "#4");
|
|
Assert.IsNotNull (cvds.Type, "#5");
|
|
Assert.AreSame (type, cvds.Type, "#6");
|
|
|
|
cvds = new CodeVariableDeclarationStatement ((CodeTypeReference) null,
|
|
(string) null, (CodeExpression) null);
|
|
Assert.IsNull (cvds.InitExpression, "#7");
|
|
Assert.IsNotNull (cvds.Name, "#8");
|
|
Assert.AreEqual (string.Empty, cvds.Name, "#9");
|
|
Assert.IsNotNull (cvds.Type, "#10");
|
|
Assert.AreEqual (typeof (void).FullName, cvds.Type.BaseType, "#11");
|
|
}
|
|
|
|
[Test]
|
|
public void Constructor5 ()
|
|
{
|
|
string baseType = "monotype";
|
|
string name = "mono";
|
|
CodeExpression expression = new CodeExpression ();
|
|
|
|
CodeVariableDeclarationStatement cvds = new CodeVariableDeclarationStatement (
|
|
baseType, name, expression);
|
|
Assert.IsNotNull (cvds.InitExpression, "#1");
|
|
Assert.AreSame (expression, cvds.InitExpression, "#2");
|
|
Assert.IsNotNull (cvds.Name, "#3");
|
|
Assert.AreSame (name, cvds.Name, "#4");
|
|
Assert.IsNotNull (cvds.Type, "#5");
|
|
Assert.AreEqual (baseType, cvds.Type.BaseType, "#6");
|
|
|
|
cvds = new CodeVariableDeclarationStatement ((string) null,
|
|
(string) null, (CodeExpression) null);
|
|
Assert.IsNull (cvds.InitExpression, "#7");
|
|
Assert.IsNotNull (cvds.Name, "#8");
|
|
Assert.AreEqual (string.Empty, cvds.Name, "#9");
|
|
Assert.IsNotNull (cvds.Type, "#10");
|
|
Assert.AreEqual (typeof (void).FullName, cvds.Type.BaseType, "#11");
|
|
}
|
|
|
|
[Test]
|
|
public void Constructor6 ()
|
|
{
|
|
Type baseType = typeof (int);
|
|
string name = "mono";
|
|
CodeExpression expression = new CodeExpression ();
|
|
|
|
CodeVariableDeclarationStatement cvds = new CodeVariableDeclarationStatement (
|
|
baseType, name, expression);
|
|
Assert.IsNotNull (cvds.InitExpression, "#1");
|
|
Assert.AreSame (expression, cvds.InitExpression, "#2");
|
|
Assert.IsNotNull (cvds.Name, "#3");
|
|
Assert.AreSame (name, cvds.Name, "#4");
|
|
Assert.IsNotNull (cvds.Type, "#5");
|
|
Assert.AreEqual (baseType.FullName, cvds.Type.BaseType, "#6");
|
|
|
|
cvds = new CodeVariableDeclarationStatement (baseType,
|
|
(string) null, (CodeExpression) null);
|
|
Assert.IsNull (cvds.InitExpression, "#7");
|
|
Assert.IsNotNull (cvds.Name, "#8");
|
|
Assert.AreEqual (string.Empty, cvds.Name, "#9");
|
|
Assert.IsNotNull (cvds.Type, "#10");
|
|
Assert.AreEqual (baseType.FullName, cvds.Type.BaseType, "#11");
|
|
}
|
|
|
|
[Test]
|
|
#if NET_2_0
|
|
[ExpectedException (typeof (ArgumentNullException))]
|
|
#else
|
|
[ExpectedException (typeof (NullReferenceException))]
|
|
#endif
|
|
public void Constructor6_NullType ()
|
|
{
|
|
CodeVariableDeclarationStatement cvds = new CodeVariableDeclarationStatement (
|
|
(Type) null, "mono", new CodeExpression ());
|
|
}
|
|
}
|
|
}
|