Imported Upstream version 3.6.0

Former-commit-id: da6be194a6b1221998fc28233f2503bd61dd9d14
This commit is contained in:
Jo Shields
2014-08-13 10:39:27 +01:00
commit a575963da9
50588 changed files with 8155799 additions and 0 deletions

View File

@ -0,0 +1,118 @@
//
// CSharpCodeProviderCas.cs
// - CAS unit tests for Microsoft.CSharp.CSharpCodeProvider
//
// Author:
// Sebastien Pouliot <sebastien@ximian.com>
//
// 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;
using System.CodeDom.Compiler;
using System.IO;
using System.Reflection;
using System.Security;
using System.Security.Permissions;
using Microsoft.CSharp;
namespace MonoCasTests.Microsoft.CSharp {
[TestFixture]
[Category ("CAS")]
public class CSharpCodeProviderCas {
[SetUp]
public virtual void SetUp ()
{
if (!SecurityManager.SecurityEnabled)
Assert.Ignore ("SecurityManager.SecurityEnabled is OFF");
}
[Test]
[PermissionSet (SecurityAction.Deny, Unrestricted = true)]
public void Deny_Unrestricted ()
{
CSharpCodeProvider csprov = new CSharpCodeProvider ();
Assert.AreEqual ("cs", csprov.FileExtension, "FileExtension");
Assert.IsNotNull (csprov.CreateCompiler (), "CreateCompiler");
Assert.IsNotNull (csprov.CreateGenerator (), "CreateGenerator");
try {
Assert.IsNotNull (csprov.GetConverter (typeof (string)), "GetConverter");
}
catch (NotImplementedException) {
// mono
}
#if NET_2_0
CodeTypeMember ctm = new CodeTypeMember ();
StringWriter sw = new StringWriter ();
CodeGeneratorOptions cgo = new CodeGeneratorOptions ();
try {
csprov.GenerateCodeFromMember (ctm, sw, cgo);
}
catch (NotImplementedException) {
// mono
}
#endif
}
// LinkDemand
// we use reflection to call this class as it is protected by a LinkDemand
// (which will be converted into full demand, i.e. a stack walk) when
// reflection is used (i.e. it gets testable).
public virtual object Create ()
{
ConstructorInfo ci = typeof (CSharpCodeProvider).GetConstructor (new Type[0]);
Assert.IsNotNull (ci, "default .ctor");
return ci.Invoke (null);
}
[Test]
[PermissionSet (SecurityAction.Deny, Unrestricted = true)]
[ExpectedException (typeof (SecurityException))]
public void LinkDemand_Deny_Unrestricted ()
{
Assert.IsNotNull (Create ());
}
[Test]
[EnvironmentPermission (SecurityAction.Deny, Read = "MONO")]
[ExpectedException (typeof (SecurityException))]
public void LinkDemand_Deny_Anything ()
{
// denying any permissions -> not full trust!
Assert.IsNotNull (Create ());
}
[Test]
[PermissionSet (SecurityAction.PermitOnly, Unrestricted = true)]
public void LinkDemand_PermitOnly_Unrestricted ()
{
Assert.IsNotNull (Create ());
}
}
}

File diff suppressed because it is too large Load Diff

View File

@ -0,0 +1,268 @@
2010-04-12 Jonathan Pryor <jpryor@novell.com>
* CodeGeneratorFromExpressionTest.cs: Test CodeDefaultValueExpression
generation.
2009-06-26 Robert Jordan <robertj@gmx.net>
* CodeGeneratorIdentifierTest.cs: Upgrade to new NUnit style.
2009-06-08 Zoltan Varga <vargaz@gmail.com>
* CSharpCodeProviderTest.cs: Avoid depending on the order in which
GetManifestResourceNames () returns resource names.
2008-05-09 Gert Driesen <drieseng@users.sourceforge.net>
* CodeGeneratorFromTypeTest.cs: Added tests for
System.ParamArrayAttribute custom attribute.
2008-04-08 Jb Evain <jbevain@novell.com>
* CodeGeneratorFromTypeTest.cs: add test for abstract properties.
2008-01-27 Gert Driesen <drieseng@users.sourceforge.net>
* CodeGeneratorFromExpressionTest.cs: Copied some tests from VB, and
improved existing tests.
2008-01-16 Gert Driesen <drieseng@users.sourceforge.net>
* CodeGeneratorFromCompileUnitTest.cs: Avoid using "", and use
Assert instead of Assertion.
* CodeGeneratorFromNamespaceTest.cs: Added tests for type parameters.
2007-12-21 Rolf Bjarne Kvinge <RKvinge@novell.com>
* CodeGeneratorFromTypeTest.cs: Added PartialTypeTest.
2007-10-26 Atsushi Enomoto <atsushi@ximian.com>
* CodeGeneratorFromTypeTest.cs : added test case for escaped
CodeProperty output name (keyword).
2007-02-21 Gert Driesen <drieseng@users.sourceforge.net>
* CSharpCodeProviderTest.cs: No longer use Assert class in separate
AppDomain since it will only work if nunit.framework assembly is in
the GAC.
2007-02-21 Gert Driesen <drieseng@users.sourceforge.net>
* CSharpCodeProviderTest.cs: Added test for generating executable.
Modified existing test to use zero-length OutputAssembly, and verify
expected OutputAssembly after generating assembly.
2007-01-18 Atsushi Enomoto <atsushi@ximian.com>
* CodeGeneratorFromTypeTest.cs :
Added test for generic type references output.
2006-12-30 Marek Habersack <grendello@gmail.com>
* CodeGeneratorIdentifierTest.cs: added tests for C# code generator
IsValidIdentifier method.
2006-08-08 Gert Driesen <drieseng@users.sourceforge.net>
* CSharpCodeProviderTest.cs: Modified tests to verify fix for bug
#78384, and check support for linked resources.
2006-04-20 Gert Driesen <drieseng@users.sourceforge.net>
* CodeGeneratorFromNamespaceTest.cs: Added tests for namespace imports
and types.
2005-12-07 Gert Driesen <drieseng@users.sourceforge.net>
* CodeGeneratorFromExpressionTest.cs: Added tests for
CodePrimitiveExpression.
2005-11-30 Gert Driesen <drieseng@users.sourceforge.net>
* CodeGeneratorFromStatementTest.cs: Added tests for
CodeAssignStatement, CodeAttachEventStatement,
CodeConditionStatement, CodeExpressionStatement,
CodeIterationStatement, CodeLabeledStatement,
CodeMethodReturnStatement, CodeRemoveEventStatement,
CodeSnippetStatement, CodeStatement, CodeVariableDeclarationStatement.
2005-11-26 Gert Driesen <drieseng@users.sourceforge.net>
* CodeGeneratorFromExpressionTest.cs: Added test for
CodeParameterDeclarationExpression.
* CodeGeneratorFromTypeTest.cs: Modified tests to check result
for zero-length event, field and parameter name.
* CodeGeneratorFromStatementTest.cs: Added CodeCommentStatement,
CodeThrowExceptionStatement, CodeGotoStatement and
CodeTryCatchFinallyStatement tests.
2005-10-28 Gert Driesen <drieseng@users.sourceforge.net>
* CodeGeneratorFromTypeTest.cs: Added tests for CodeEntryPointMethod
and bug #76580.
2005-10-25 Gert Driesen <drieseng@users.sourceforge.net>
* CodeGeneratorTestBase.cs: Fixed line endings. Set eol-style to
native.
* CodeGeneratorFromCompileUnitTest.cs: Fixed line endings. Set
eol-style to native. Modified test to also check output for
CodeAttributeArgument with no name.
* CodeGeneratorFromNamespaceTest.cs: Fixed line endings. Set eol-style
to native.
* CodeGeneratorIdentifierTest.cs: Set eol-style to native.
* CodeGeneratorFromExpressionTest.cs: Fixed line endings. Set
eol-style to native.
* CSharpCodeProviderTest.cs: Set eol-style to native.
* CodeGeneratorFromTypeTest.cs: Fixed line endings. Set eol-style to
native.
* CodeGeneratorFromStatementTest.cs: Fixed line endings. Set
eol-style to native.
2005-10-17 Sebastien Pouliot <sebastien@ximian.com>
* CSharpCodeProviderCas.cs: New. CAS unit tests.
2005-10-15 Gert Driesen <drieseng@users.sourceforge.net>
* CodeGeneratorTestBase.cs: Generate now returns code that was output,
and take CodeGeneratorOptions instance in order to support testing
bracing style.
* CodeGeneratorFromCompileUnitTest.cs: Added tests for C bracing style.
* CodeGeneratorFromNamespaceTest.cs: Added tests for C bracing style.
* CodeGeneratorFromExpressionTest.cs: Clean up.
* CodeGeneratorFromTypeTest.cs: Added tests for C bracing style.
2005-10-07 Gert Driesen <drieseng@users.sourceforge.net>
* CodeGeneratorTypeOutputTest.cs: Added tests for
CSharpCodeGenerator.GetTypeOutput.
2005-07-30 Gert Driesen <drieseng@users.sourceforge.net>
* CodeGeneratorFromTypeTest.cs: Added NewSlot tests.
2005-07-24 Gert Driesen <drieseng@users.sourceforge.net>
* CodeGeneratorFromTypeTest.cs: Added BaseTypes and TypeConstructor
tests. Added enum, interface and delegate tests.
2005-07-02 Gert Driesen <drieseng@users.sourceforge.net>
* CodeGeneratorFromTypeTest.cs: Added test for
ReturnTypeCustomAttributes.
2005-07-02 Gert Driesen <drieseng@users.sourceforge.net>
* CodeGeneratorFromTypeTest.cs: Added event ImplementationTypes
tests. Added PrivateImplementationType and property and method
overload tests. Added property indexer tests.
2005-07-01 Gert Driesen <drieseng@users.sourceforge.net>
* CodeGeneratorFromTypeTest.cs: Added tests to ensure Implementation
Types are ignored in C# CodeDOM.
2005-06-30 Gert Driesen <drieseng@users.sourceforge.net>
* CodeGeneratorFromTypeTest.cs: Added property indexer and parameter
tests.
2005-06-28 Gert Driesen <drieseng@users.sourceforge.net>
* CodeGeneratorFromTypeTest.cs: Added additional property tests.
2005-06-28 Gert Driesen <drieseng@users.sourceforge.net>
* CodeGeneratorFromExpressionTest.cs: No longer inherit from
CodeGeneratorTestBase. Added tests for CodeTypeReference.
2005-06-26 Gert Driesen <drieseng@users.sourceforge.net>
* CodeGeneratorFromTypeTest.cs: Added tests to verify code generated
for events, fields, properties, methods and ctors to match MS.NET.
2005-06-25 Gert Driesen <drieseng@users.sourceforge.net>
* CodeGeneratorFromTypeTest.cs: Added tests to verify code generated
for Type (with and without custom attributes).
2005-06-25 Gert Driesen <drieseng@users.sourceforge.net>
* CodeGeneratorFromCompileUnitTest.cs: Added tests to verify code
that is generated for assembly-level custom attributes.
2005-06-25 Gert Driesen <drieseng@users.sourceforge.net>
* CodeGeneratorFromCompileUnitTest.cs: enabled test for bug
#75190.
2005-06-10 Gert Driesen <drieseng@users.sourceforge.net>
* CSharpCodeProviderTest.cs: added tests for bug #75221 and
#75218.
2005-06-09 Gert Driesen <drieseng@users.sourceforge.net>
* CodeGeneratorFromCompileUnitTest.cs: added test for bug #75190.
2005-06-05 Gert Driesen <drieseng@users.sourceforge.net>
* CodeGeneratorFromCompileUnitTest.cs: re-enabled tests as
IndentedTextWriter now matches MS.NET
2005-06-04 Gert Driesen <drieseng@users.sourceforge.net>
* CodeGeneratorFromNamespaceTest.cs: re-enabled SimpleNamespaceTest
and InvalidNamespaceTest as IndentedTextWriter now matches MS.NET
2005-05-30 Gert Driesen <drieseng@users.sourceforge.net>
* CSharpCodeGeneratorTest.cs: Added tests for GenerateInMemory
compiler parameter.
2004-06-18 Atsushi Enomoto <atsushi@ximian.com>
* CodeGeneratorIdentifierTest.cs : [TestFixture] was missing.
2004-01-21 Atsushi Enomoto <atsushi@ximian.com>
* Added CodeGeneratorIdentifierTest.cs.
2003-11-21 Gonzalo Paniagua Javier <gonzalo@ximian.com>
* Test/Microsoft.CSharp/CodeGeneratorFromCompileUnitTest.cs: don't
compare whitespace for assembly level attribute.
2003-07-09 Gonzalo Paniagua Javier <gonzalo@ximian.com>
* system_linux_test.args: added new tests in Microsoft.CSharp.
* Microsoft.CSharp/CodeGeneratorFromCompileUnitTest.cs:
* Microsoft.CSharp/CodeGeneratorFromExpressionTest.cs:
* Microsoft.CSharp/CodeGeneratorFromNamespaceTest.cs:
* Microsoft.CSharp/CodeGeneratorFromStatementTest.cs:
* Microsoft.CSharp/CodeGeneratorFromTypeTest.cs:
* Microsoft.CSharp/CodeGeneratorTestBase.cs: new tests from Erik LeBel
<eriklebel@yahoo.ca>.
2002-12-08 Jackson Harper <jackson@latitudegeo.com>
* CompilerTest.cs CompilerErrorTest.cs: Removed files
2002-12-08 Jackson Harper <jackson@latitudegeo.com>
* AllTests.cs: Remove references to soon to be removed Tests
2002-11-13 Jackson Harper <jackson@latitudegeo.com>
* CompilerTest.cs: Added more tests
2002-11-11 Jackson Harper <jackson@latitudegeo.com>
* CompilerErrorTest.cs AllTests.cs: Added tests for the Microsoft.CSharp.CompilerError class
2002-11-06 Jackson Harper <jackson@latitudegeo.com>
* AllTests.cs CompilerTest.cs: Added files

View File

@ -0,0 +1,225 @@
//
// Microsoft.CSharp.* Test Cases
//
// Authors:
// Erik LeBel (eriklebel@yahoo.ca)
// Ilker Cetinkaya (mail@ilker.de)
//
// (c) 2003 Erik LeBel
//
using System;
using System.CodeDom;
using System.CodeDom.Compiler;
using System.Globalization;
using System.IO;
using System.Text;
using NUnit.Framework;
namespace MonoTests.Microsoft.CSharp
{
/// <summary>
/// Test ICodeGenerator's GenerateCodeFromCompileUnit, along with a
/// minimal set CodeDom components.
/// </summary>
[TestFixture]
public class CodeGeneratorFromCompileUnitTest : CodeGeneratorTestBase
{
private string codeUnitHeader = string.Empty;
private CodeCompileUnit codeUnit;
public CodeGeneratorFromCompileUnitTest ()
{
Init();
codeUnitHeader = Generate ();
}
[SetUp]
public void Init ()
{
InitBase ();
codeUnit = new CodeCompileUnit ();
}
protected override string Generate (CodeGeneratorOptions options)
{
StringWriter writer = new StringWriter ();
writer.NewLine = NewLine;
generator.GenerateCodeFromCompileUnit (codeUnit, writer, options);
writer.Close ();
return writer.ToString ().Substring (codeUnitHeader.Length);
}
[Test]
public void DefaultCodeUnitTest ()
{
Assert.AreEqual (string.Empty, Generate ());
}
[Test]
[ExpectedException (typeof (NullReferenceException))]
public void NullCodeUnitTest ()
{
codeUnit = null;
Generate ();
}
[Test]
public void ReferencedTest ()
{
codeUnit.ReferencedAssemblies.Add ("System.dll");
Assert.AreEqual (string.Empty, Generate ());
}
[Test]
public void SimpleNamespaceTest ()
{
string code = null;
CodeNamespace ns = new CodeNamespace ("A");
codeUnit.Namespaces.Add (ns);
code = Generate ();
Assert.AreEqual ("namespace A {\n \n}\n", code, "#1");
CodeGeneratorOptions options = new CodeGeneratorOptions ();
options.BracingStyle = "C";
code = Generate (options);
Assert.AreEqual ("namespace A\n{\n \n}\n", code, "#2");
}
[Test]
public void ReferenceAndSimpleNamespaceTest()
{
CodeNamespace ns = new CodeNamespace ("A");
codeUnit.Namespaces.Add (ns);
codeUnit.ReferencedAssemblies.Add ("using System;");
Assert.AreEqual ("namespace A {\n \n}\n", Generate ());
}
[Test]
public void SimpleAttributeTest ()
{
CodeAttributeDeclaration attrDec = new CodeAttributeDeclaration ();
attrDec.Name = "A";
codeUnit.AssemblyCustomAttributes.Add (attrDec);
Assert.AreEqual (string.Format (CultureInfo.InvariantCulture,
"[assembly: A()]{0}{0}", NewLine), Generate ());
}
[Test]
public void AttributeWithValueTest ()
{
CodeAttributeDeclaration attrDec = new CodeAttributeDeclaration ();
attrDec.Name = "A";
attrDec.Arguments.Add (new CodeAttributeArgument ("A1",
new CodePrimitiveExpression (false)));
attrDec.Arguments.Add (new CodeAttributeArgument ("A2",
new CodePrimitiveExpression (true)));
// null name should not be output
attrDec.Arguments.Add (new CodeAttributeArgument (null,
new CodePrimitiveExpression (true)));
// zero length name should not be output
attrDec.Arguments.Add (new CodeAttributeArgument (string.Empty,
new CodePrimitiveExpression (false)));
codeUnit.AssemblyCustomAttributes.Add (attrDec);
Assert.AreEqual (string.Format (CultureInfo.InvariantCulture,
"[assembly: A(A1=false, A2=true, true, false)]{0}{0}", NewLine),
Generate ());
}
[Test]
public void MultipleAttributeTest ()
{
CodeAttributeDeclaration attrDec = new CodeAttributeDeclaration ();
attrDec.Name = "A";
codeUnit.AssemblyCustomAttributes.Add (attrDec);
attrDec = new CodeAttributeDeclaration ();
attrDec.Name = "B";
codeUnit.AssemblyCustomAttributes.Add (attrDec);
Assert.AreEqual (string.Format (CultureInfo.InvariantCulture,
"[assembly: A()]{0}[assembly: B()]{0}{0}", NewLine),
Generate ());
}
[Test]
public void AttributeAndSimpleNamespaceTest ()
{
CodeNamespace ns = new CodeNamespace ("A");
codeUnit.Namespaces.Add (ns);
CodeAttributeDeclaration attrDec = new CodeAttributeDeclaration ();
attrDec.Name = "A";
codeUnit.AssemblyCustomAttributes.Add (attrDec);
attrDec = new CodeAttributeDeclaration ();
attrDec.Name = "B";
codeUnit.AssemblyCustomAttributes.Add (attrDec);
Assert.AreEqual (string.Format (CultureInfo.InvariantCulture,
"[assembly: A()]{0}[assembly: B()]{0}{0}namespace A {{{0} {0}"
+ "}}{0}", NewLine), Generate ());
}
[Test]
public void CodeSnippetTest ()
{
StringWriter writer = new StringWriter ();
writer.NewLine = NewLine;
codeUnit = new CodeSnippetCompileUnit ("public class Test1 {}");
generator.GenerateCodeFromCompileUnit (codeUnit, writer, options);
writer.Close ();
Assert.AreEqual ("public class Test1 {}" + writer.NewLine, writer.ToString ());
}
[Test]
public void AttributeAndGlobalNamespaceWithImportTest ()
{
CodeNamespace ns = new CodeNamespace ();
ns.Imports.Add (new CodeNamespaceImport ("Z"));
ns.Imports.Add (new CodeNamespaceImport ("A"));
codeUnit.Namespaces.Add (ns);
CodeAttributeDeclaration attrDec = new CodeAttributeDeclaration ();
attrDec.Name = "A";
codeUnit.AssemblyCustomAttributes.Add (attrDec);
Assert.AreEqual (string.Format (CultureInfo.InvariantCulture,
"using A;{0}using Z;{0}{0}[assembly: A()]{0}{0}{0}", NewLine), Generate ());
}
[Test]
public void GlobalAttributeBeforeType ()
{
StringWriter writer = new StringWriter ();
writer.NewLine = NewLine;
codeUnit = new CodeCompileUnit () {
AssemblyCustomAttributes = {
new CodeAttributeDeclaration (
new CodeTypeReference (typeof (CLSCompliantAttribute)),
new CodeAttributeArgument (new CodePrimitiveExpression (false))),
},
Namespaces = {
new CodeNamespace () {
Types = {
new CodeTypeDeclaration ("Resources"),
},
}
},
};
generator.GenerateCodeFromCompileUnit (codeUnit, writer, options);
writer.Close ();
Assert.AreEqual (string.Format (CultureInfo.InvariantCulture,
"[assembly: System.CLSCompliantAttribute(false)]{0}{0}{0}{0}public class Resources {{{0}}}{0}", NewLine), Generate ());
}
}
}

File diff suppressed because it is too large Load Diff

File diff suppressed because it is too large Load Diff

File diff suppressed because it is too large Load Diff

View File

@ -0,0 +1 @@
3fcc1d6d3b7c329eaaf86b7566cb5d50a7b77b74

View File

@ -0,0 +1,97 @@
//
// CodeGeneratorIdentifierTest.cs
//
// Author:
// Atsushi Enomoto <atsushi@ximian.com>
//
// (C)2004 Novell inc.
//
using System;
using System.CodeDom.Compiler;
using NUnit.Framework;
using Microsoft.CSharp;
namespace MonoTests.Microsoft.CSharp
{
[TestFixture]
public class CodeGeneratorIdentifierTest
{
private ICodeGenerator gen;
public CodeGeneratorIdentifierTest ()
{
gen = new CSharpCodeProvider ().CreateGenerator ();
}
[Test]
[ExpectedException (typeof (NullReferenceException))]
public void TestCreateValidIdentifierNullArg ()
{
gen.CreateValidIdentifier (null);
}
[Test]
public void TestCreateValidIdentifier ()
{
Assert.AreEqual ("a", gen.CreateValidIdentifier ("a"));
Assert.AreEqual ("_int", gen.CreateValidIdentifier ("int"));
Assert.AreEqual ("_", gen.CreateValidIdentifier ("_"));
Assert.AreEqual ("1", gen.CreateValidIdentifier ("1"));
Assert.AreEqual ("1a", gen.CreateValidIdentifier ("1a"));
Assert.AreEqual ("1*2", gen.CreateValidIdentifier ("1*2"));
Assert.AreEqual ("-", gen.CreateValidIdentifier ("-"));
Assert.AreEqual ("+", gen.CreateValidIdentifier ("+"));
Assert.AreEqual ("", gen.CreateValidIdentifier (""));
Assert.AreEqual ("--", gen.CreateValidIdentifier ("--"));
Assert.AreEqual ("++", gen.CreateValidIdentifier ("++"));
Assert.AreEqual ("\u3042", gen.CreateValidIdentifier ("\u3042"));
}
[Test]
[ExpectedException (typeof (NullReferenceException))]
public void TestCreateEscapedIdentifierNullArg ()
{
gen.CreateEscapedIdentifier (null);
}
[Test]
public void TestCreateEscapedIdentifier ()
{
Assert.AreEqual ("a", gen.CreateEscapedIdentifier ("a"));
Assert.AreEqual ("@int", gen.CreateEscapedIdentifier ("int"));
Assert.AreEqual ("_", gen.CreateEscapedIdentifier ("_"));
Assert.AreEqual ("1", gen.CreateEscapedIdentifier ("1"));
Assert.AreEqual ("1a", gen.CreateEscapedIdentifier ("1a"));
Assert.AreEqual ("1*2", gen.CreateEscapedIdentifier ("1*2"));
Assert.AreEqual ("-", gen.CreateEscapedIdentifier ("-"));
Assert.AreEqual ("+", gen.CreateEscapedIdentifier ("+"));
Assert.AreEqual ("", gen.CreateEscapedIdentifier (""));
Assert.AreEqual ("--", gen.CreateEscapedIdentifier ("--"));
Assert.AreEqual ("++", gen.CreateEscapedIdentifier ("++"));
Assert.AreEqual ("\u3042", gen.CreateEscapedIdentifier ("\u3042"));
}
[Test]
public void TestIsValidIdentifier ()
{
Assert.AreEqual (true, gen.IsValidIdentifier ("_a"));
Assert.AreEqual (true, gen.IsValidIdentifier ("_"));
Assert.AreEqual (true, gen.IsValidIdentifier ("@return"));
Assert.AreEqual (true, gen.IsValidIdentifier ("d1"));
Assert.AreEqual (true, gen.IsValidIdentifier ("_1"));
Assert.AreEqual (true, gen.IsValidIdentifier ("_a_1"));
Assert.AreEqual (true, gen.IsValidIdentifier ("@a"));
Assert.AreEqual (false, gen.IsValidIdentifier ("1"));
Assert.AreEqual (false, gen.IsValidIdentifier (" "));
Assert.AreEqual (false, gen.IsValidIdentifier ("?"));
Assert.AreEqual (false, gen.IsValidIdentifier (":_:"));
Assert.AreEqual (false, gen.IsValidIdentifier ("_ "));
Assert.AreEqual (false, gen.IsValidIdentifier ("@ "));
Assert.AreEqual (false, gen.IsValidIdentifier ("1*2"));
Assert.AreEqual (false, gen.IsValidIdentifier ("1_2"));
Assert.AreEqual (gen.IsValidIdentifier ("a, b"), false);
}
}
}

View File

@ -0,0 +1,56 @@
//
// Microsoft.CSharp.* Test Cases
//
// Authors:
// Erik LeBel (eriklebel@yahoo.ca)
//
// (c) 2003 Erik LeBel
//
using System;
using System.IO;
using System.Text;
using System.CodeDom;
using System.CodeDom.Compiler;
using Microsoft.CSharp;
using NUnit.Framework;
namespace MonoTests.Microsoft.CSharp
{
///
/// <summary>
/// Base test for a variety of CodeGenerator GenerateCodeXXX methods.
///
/// This testing is a form of hybrid test, it tests the variety of CodeDom
/// classes as well as the C# code generator.
///
/// The implementations bellow provide a template as well as guidlines for
/// implementing further tests.
/// </summary>
///
public abstract class CodeGeneratorTestBase
{
private CodeDomProvider provider = null;
protected ICodeGenerator generator = null;
protected CodeGeneratorOptions options = null;
public void InitBase()
{
provider = new CSharpCodeProvider ();
generator = provider.CreateGenerator ();
options = new CodeGeneratorOptions ();
}
protected string Generate ()
{
return Generate (options);
}
protected virtual string NewLine
{
get { return "\n"; }
}
protected abstract string Generate (CodeGeneratorOptions options);
}
}

View File

@ -0,0 +1,122 @@
//
// CodeGeneratorTypeOutputTest.cs
//
// Author:
// Gert Driesen <drieseng@users.sourceforge.net>
//
// (C)2005 Novell inc.
//
using System;
using System.CodeDom;
using System.CodeDom.Compiler;
#if NET_2_0
using System.Collections.Generic;
#endif
using NUnit.Framework;
using Microsoft.CSharp;
namespace MonoTests.Microsoft.CSharp
{
[TestFixture]
public class CodeGeneratorTypeOutputTest
{
private ICodeGenerator gen;
[SetUp]
public void SetUp ()
{
gen = new CSharpCodeProvider ().CreateGenerator ();
}
#if NET_2_0
// This test fails on 2.0 profile, because our CodeTypeReference does not
// parse basetype from right to left.
[Test]
[Category ("NotWorking")]
public void GetTypeOutputFailure ()
{
Assert.AreEqual ("A[,,][,]", gen.GetTypeOutput (new CodeTypeReference ("A[,,][,]")), "#5");
Assert.AreEqual ("A<B, D>[,]", gen.GetTypeOutput (new CodeTypeReference ("A[B,,D][,]")), "#6");
}
#endif
[Test]
public void GetTypeOutput ()
{
Assert.AreEqual ("A", gen.GetTypeOutput (new CodeTypeReference ("A")), "#1");
Assert.AreEqual ("A[]", gen.GetTypeOutput (new CodeTypeReference ("A[]")), "#2");
Assert.AreEqual ("int[]", gen.GetTypeOutput (new CodeTypeReference (typeof (int).FullName, 1)), "#3");
Assert.AreEqual ("int[,]", gen.GetTypeOutput (new CodeTypeReference (typeof (int).FullName, 2)), "#4");
#if NET_2_0
Assert.AreEqual ("System.Nullable<int>", gen.GetTypeOutput (new CodeTypeReference (typeof (int?))), "#7");
Assert.AreEqual ("System.Collections.Generic.Dictionary<int, string>", gen.GetTypeOutput (new CodeTypeReference (typeof (Dictionary<int, string>))), "#8");
#else
Assert.AreEqual ("A[,,][,]", gen.GetTypeOutput (new CodeTypeReference ("A[,,][,]")), "#5");
Assert.AreEqual ("A[B,,D][,]", gen.GetTypeOutput (new CodeTypeReference ("A[B,,D][,]")), "#6");
Assert.AreEqual ("System.Nullable`1[[System.Int32, mscorlib, Version=2.0.0.0, Culture=neutral, PublicKeyToken=b77a5c561934e089]]",
gen.GetTypeOutput (new CodeTypeReference ("System.Nullable`1[[System.Int32, mscorlib, Version=2.0.0.0, Culture=neutral, PublicKeyToken=b77a5c561934e089]]")),
"#9");
Assert.AreEqual ("System.Collections.Generic.Dictionary`2[[System.Int32, mscorlib, Version=2.0.0.0, Culture=neutral, PublicKeyToken=b77a5c561934e089],[System.String, mscorlib, Version=2.0.0.0, Culture=neutral, PublicKeyToken=b77a5c561934e089]]",
gen.GetTypeOutput (new CodeTypeReference ("System.Collections.Generic.Dictionary`2[[System.Int32, mscorlib, Version=2.0.0.0, Culture=neutral, PublicKeyToken=b77a5c561934e089],[System.String, mscorlib, Version=2.0.0.0, Culture=neutral, PublicKeyToken=b77a5c561934e089]]")),
"#10");
#endif
}
[Test]
public void Shortcuts () {
Assert.AreEqual ("int", gen.GetTypeOutput (new CodeTypeReference (typeof(int))), "#1");
Assert.AreEqual ("int", gen.GetTypeOutput (new CodeTypeReference ("systeM.inT32")), "#2");
Assert.AreEqual ("long", gen.GetTypeOutput (new CodeTypeReference (typeof(long))), "#3");
Assert.AreEqual ("long", gen.GetTypeOutput (new CodeTypeReference ("systeM.inT64")), "#4");
Assert.AreEqual ("short", gen.GetTypeOutput (new CodeTypeReference (typeof(short))), "#5");
Assert.AreEqual ("short", gen.GetTypeOutput (new CodeTypeReference ("systeM.inT16")), "#6");
Assert.AreEqual ("bool", gen.GetTypeOutput (new CodeTypeReference (typeof(bool))), "#7");
Assert.AreEqual ("bool", gen.GetTypeOutput (new CodeTypeReference ("systeM.BooLean")), "#8");
Assert.AreEqual ("char", gen.GetTypeOutput (new CodeTypeReference (typeof(char))), "#9");
Assert.AreEqual ("char", gen.GetTypeOutput (new CodeTypeReference ("systeM.cHar")), "#10");
Assert.AreEqual ("string", gen.GetTypeOutput (new CodeTypeReference (typeof(string))), "#11");
Assert.AreEqual ("string", gen.GetTypeOutput (new CodeTypeReference ("systeM.sTring")), "#12");
Assert.AreEqual ("object", gen.GetTypeOutput (new CodeTypeReference (typeof(object))), "#13");
Assert.AreEqual ("object", gen.GetTypeOutput (new CodeTypeReference ("systeM.oBject")), "#14");
Assert.AreEqual ("void", gen.GetTypeOutput (new CodeTypeReference (typeof(void))), "#15");
Assert.AreEqual ("void", gen.GetTypeOutput (new CodeTypeReference ("systeM.vOid")), "#16");
#if NET_2_0
Assert.AreEqual ("byte", gen.GetTypeOutput (new CodeTypeReference (typeof(byte))), "#17");
Assert.AreEqual ("byte", gen.GetTypeOutput (new CodeTypeReference ("systeM.bYte")), "#18");
Assert.AreEqual ("sbyte", gen.GetTypeOutput (new CodeTypeReference (typeof(sbyte))), "#19");
Assert.AreEqual ("sbyte", gen.GetTypeOutput (new CodeTypeReference ("systeM.sBYte")), "#20");
Assert.AreEqual ("decimal", gen.GetTypeOutput (new CodeTypeReference (typeof(decimal))), "#21");
Assert.AreEqual ("decimal", gen.GetTypeOutput (new CodeTypeReference ("systeM.dEcimal")), "#22");
Assert.AreEqual ("double", gen.GetTypeOutput (new CodeTypeReference (typeof(double))), "#23");
Assert.AreEqual ("double", gen.GetTypeOutput (new CodeTypeReference ("systeM.dOuble")), "#24");
Assert.AreEqual ("float", gen.GetTypeOutput (new CodeTypeReference (typeof(float))), "#25");
Assert.AreEqual ("float", gen.GetTypeOutput (new CodeTypeReference ("systeM.SiNgle")), "#26");
Assert.AreEqual ("uint", gen.GetTypeOutput (new CodeTypeReference (typeof (uint))), "#27");
Assert.AreEqual ("uint", gen.GetTypeOutput (new CodeTypeReference ("systeM.UinT32")), "#28");
Assert.AreEqual ("ulong", gen.GetTypeOutput (new CodeTypeReference (typeof (ulong))), "#29");
Assert.AreEqual ("ulong", gen.GetTypeOutput (new CodeTypeReference ("systeM.uinT64")), "#30");
Assert.AreEqual ("ushort", gen.GetTypeOutput (new CodeTypeReference (typeof (ushort))), "#31");
Assert.AreEqual ("ushort", gen.GetTypeOutput (new CodeTypeReference ("systeM.uinT16")), "#32");
#else
Assert.AreEqual (typeof (byte).FullName, gen.GetTypeOutput (new CodeTypeReference (typeof (byte))), "#17");
Assert.AreEqual ("systeM.bYte", gen.GetTypeOutput (new CodeTypeReference ("systeM.bYte")), "#18");
Assert.AreEqual (typeof (sbyte).FullName, gen.GetTypeOutput (new CodeTypeReference (typeof (sbyte))), "#19");
Assert.AreEqual ("systeM.sBYte", gen.GetTypeOutput (new CodeTypeReference ("systeM.sBYte")), "#20");
Assert.AreEqual (typeof (decimal).FullName, gen.GetTypeOutput (new CodeTypeReference (typeof (decimal))), "#21");
Assert.AreEqual ("systeM.dEcimal", gen.GetTypeOutput (new CodeTypeReference ("systeM.dEcimal")), "#22");
Assert.AreEqual (typeof (double).FullName, gen.GetTypeOutput (new CodeTypeReference (typeof (double))), "#23");
Assert.AreEqual ("systeM.dOuble", gen.GetTypeOutput (new CodeTypeReference ("systeM.dOuble")), "#24");
Assert.AreEqual (typeof (float).FullName, gen.GetTypeOutput (new CodeTypeReference (typeof (float))), "#25");
Assert.AreEqual ("systeM.SiNgle", gen.GetTypeOutput (new CodeTypeReference ("systeM.SiNgle")), "#26");
Assert.AreEqual (typeof (uint).FullName, gen.GetTypeOutput (new CodeTypeReference (typeof (uint))), "#27");
Assert.AreEqual ("systeM.UinT32", gen.GetTypeOutput (new CodeTypeReference ("systeM.UinT32")), "#28");
Assert.AreEqual (typeof (ulong).FullName, gen.GetTypeOutput (new CodeTypeReference (typeof (ulong))), "#29");
Assert.AreEqual ("systeM.uinT64", gen.GetTypeOutput (new CodeTypeReference ("systeM.uinT64")), "#30");
Assert.AreEqual (typeof (ushort).FullName, gen.GetTypeOutput (new CodeTypeReference (typeof (ushort))), "#31");
Assert.AreEqual ("systeM.uinT16", gen.GetTypeOutput (new CodeTypeReference ("systeM.uinT16")), "#32");
#endif
}
}
}