mirror of
https://github.com/BepInEx/mono.git
synced 2026-11-17 11:21:39 -10:00
and takes 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. * CodeGeneratorTestBase.cs: No longer keep instance of StringWriter to allow GenerateCodeFromType to be executed multiple times with relying on user to reset writer. Allow CodeGeneratorOptions to be passed in, in order to support bracing style tests. * CodeGeneratorFromTypeTestBase.cs: Modify Generate* methods to take CodeGeneratorOptions instance and pass it on to GenerateCodeFromType. * CodeGeneratorFromTypeTest.cs: Reworked tests to pass CodeGeneratorOptions to Generate* methods. * 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. * CSharpCodeGenerator.cs: Support C bracing style. Fixes bug #76286. svn path=/trunk/mcs/; revision=51753
60 lines
1.1 KiB
C#
60 lines
1.1 KiB
C#
//
|
|
// Base class for CodeGenerator unit tests
|
|
//
|
|
// Authors:
|
|
// Gert Driesen ([email protected])
|
|
//
|
|
// (c) Novell
|
|
//
|
|
|
|
using System;
|
|
using System.CodeDom;
|
|
using System.CodeDom.Compiler;
|
|
using System.IO;
|
|
|
|
using NUnit.Framework;
|
|
|
|
namespace MonoTests.System.CodeDom.Compiler
|
|
{
|
|
public abstract class CodeGeneratorTestBase
|
|
{
|
|
private CodeGeneratorOptions _options;
|
|
|
|
[SetUp]
|
|
public virtual void SetUp ()
|
|
{
|
|
_options = new CodeGeneratorOptions ();
|
|
}
|
|
|
|
protected abstract ICodeGenerator CodeGenerator
|
|
{
|
|
get;
|
|
}
|
|
|
|
protected virtual string NewLine
|
|
{
|
|
get { return "\n"; }
|
|
}
|
|
|
|
protected CodeGeneratorOptions Options
|
|
{
|
|
get { return _options; }
|
|
}
|
|
|
|
protected string GenerateCodeFromType (CodeTypeDeclaration type)
|
|
{
|
|
return GenerateCodeFromType (type, _options);
|
|
}
|
|
|
|
protected virtual string GenerateCodeFromType (CodeTypeDeclaration type, CodeGeneratorOptions options)
|
|
{
|
|
using (StringWriter writer = new StringWriter ()) {
|
|
writer.NewLine = NewLine;
|
|
CodeGenerator.GenerateCodeFromType (type, writer, options);
|
|
writer.Close ();
|
|
return writer.ToString ();
|
|
}
|
|
}
|
|
}
|
|
}
|