Browse Source

Tested generation of C# comments at run-time.

Signed-off-by: Dimitar Dobrev <dpldobrev@protonmail.com>
pull/642/head
Dimitar Dobrev 10 years ago
parent
commit
0e344b4b8a
  1. 38
      src/Generator.Tests/AST/TestAST.cs
  2. 6
      src/Generator/Generators/CSharp/CSharpCommentPrinter.cs
  3. 9
      src/Generator/Generators/Template.cs
  4. 5
      tests/Common/Common.cpp
  5. 27
      tests/Common/Common.h
  6. 26
      tests/Native/AST.h

38
src/Generator.Tests/AST/TestAST.cs

@ -3,6 +3,7 @@ using CppSharp.Passes; @@ -3,6 +3,7 @@ using CppSharp.Passes;
using CppSharp.AST;
using CppSharp.AST.Extensions;
using NUnit.Framework;
using CppSharp.Generators.CSharp;
namespace CppSharp.Generator.Tests.AST
{
@ -36,10 +37,10 @@ namespace CppSharp.Generator.Tests.AST @@ -36,10 +37,10 @@ namespace CppSharp.Generator.Tests.AST
Modifier = PointerType.TypeModifier.LVReference,
QualifiedPointee = new QualifiedType(
new BuiltinType(PrimitiveType.Short),
new TypeQualifiers() { IsConst = true })
new TypeQualifiers { IsConst = true })
}),
new QualifiedType(
new PointerType()
new PointerType
{
Modifier = PointerType.TypeModifier.Pointer,
QualifiedPointee = new QualifiedType(new BuiltinType(PrimitiveType.Int))
@ -304,5 +305,38 @@ namespace CppSharp.Generator.Tests.AST @@ -304,5 +305,38 @@ namespace CppSharp.Generator.Tests.AST
c => !c.IsCopyConstructor && !c.IsMoveConstructor).InstantiatedFrom,
classTemplate.TemplatedClass.Constructors.First(c => !c.IsCopyConstructor && !c.IsMoveConstructor));
}
[Test]
public void TestComments()
{
var @class = AstContext.FindCompleteClass("TestComments");
var commentClass = @class.Comment.FullComment.CommentToString(Options.CommentPrefix);
Assert.AreEqual(@"/// <summary>
/// <para>Hash set/map base class.</para>
/// <para>Note that to prevent extra memory use due to vtable pointer, %HashBase intentionally does not declare a virtual destructor</para>
/// <para>and therefore %HashBase pointers should never be used.</para>
/// </summary>".Replace("\r", string.Empty), commentClass.Replace("\r", string.Empty));
var method = @class.Methods.First(m => m.Name == "GetIOHandlerControlSequence");
var commentMethod = method.Comment.FullComment.CommentToString(Options.CommentPrefix);
Assert.AreEqual(@"/// <summary>
/// <para>Get the string that needs to be written to the debugger stdin file</para>
/// <para>handle when a control character is typed.</para>
/// </summary>
/// <remarks>
/// <para>Some GUI programs will intercept &quot;control + char&quot; sequences and want</para>
/// <para>to have them do what normally would happen when using a real</para>
/// <para>terminal, so this function allows GUI programs to emulate this</para>
/// <para>functionality.</para>
/// </remarks>
/// <param name=""ch"">
/// <para>The character that was typed along with the control key</para>
/// </param>
/// <returns>
/// <para>The string that should be written into the file handle that is</para>
/// <para>feeding the input stream for the debugger, or NULL if there is</para>
/// <para>no string for this control key.</para>
/// </returns>".Replace("\r", string.Empty), commentMethod.Replace("\r", string.Empty));
}
}
}

6
src/Generator/Generators/CSharp/CSharpCommentPrinter.cs

@ -71,7 +71,7 @@ namespace CppSharp.Generators.CSharp @@ -71,7 +71,7 @@ namespace CppSharp.Generators.CSharp
break;
case CommentKind.TextComment:
var section = sections.Last();
sections.Last().Lines.Add(GetText(comment,
section.Lines.Add(GetText(comment,
section.Type == CommentElement.Returns || section.Type == CommentElement.Param));
if (sections.Count == 1)
sections.Add(new Section(CommentElement.Remarks));
@ -119,7 +119,7 @@ namespace CppSharp.Generators.CSharp @@ -119,7 +119,7 @@ namespace CppSharp.Generators.CSharp
foreach (var section in sections.Where(s => s.Lines.Count > 0))
{
var tag = section.Type.ToString().ToLowerInvariant();
commentBuilder.AppendFormat("<{0}{1}>",
commentBuilder.AppendFormat("{0} <{1}{2}>", commentPrefix,
tag + (section.Attributes.Count == 0 ? string.Empty : " "),
string.Join(" ", section.Attributes));
commentBuilder.AppendLine();
@ -128,7 +128,7 @@ namespace CppSharp.Generators.CSharp @@ -128,7 +128,7 @@ namespace CppSharp.Generators.CSharp
commentBuilder.AppendFormat("{0} <para>{1}</para>", commentPrefix, line);
commentBuilder.AppendLine();
}
commentBuilder.AppendFormat("</{0}>", tag);
commentBuilder.AppendFormat("{0} </{1}>", commentPrefix, tag);
commentBuilder.AppendLine();
}
if (commentBuilder.Length > 0)

9
src/Generator/Generators/Template.cs

@ -134,16 +134,9 @@ namespace CppSharp.Generators @@ -134,16 +134,9 @@ namespace CppSharp.Generators
if (!string.IsNullOrWhiteSpace(line))
builder.Append(new string(' ', (int)totalIndent));
if (childBlock.Kind == BlockKind.BlockComment &&
!line.StartsWith(options.CommentPrefix))
{
builder.Append(options.CommentPrefix);
builder.Append(' ');
}
builder.Append(line);
if (!line.EndsWith(Environment.NewLine))
if (!line.EndsWith(Environment.NewLine, StringComparison.Ordinal))
builder.AppendLine();
}

5
tests/Common/Common.cpp

@ -581,11 +581,6 @@ int OverridesNonDirectVirtual::retInt() @@ -581,11 +581,6 @@ int OverridesNonDirectVirtual::retInt()
return 3;
}
const char * TestComments::GetIOHandlerControlSequence(char ch)
{
return 0;
}
AbstractWithVirtualDtor::AbstractWithVirtualDtor()
{
}

27
tests/Common/Common.h

@ -983,33 +983,6 @@ AbstractTemplate<T>::AbstractTemplate() @@ -983,33 +983,6 @@ AbstractTemplate<T>::AbstractTemplate()
{
}
/// Hash set/map base class.
/** Note that to prevent extra memory use due to vtable pointer, %HashBase intentionally does not declare a virtual destructor
and therefore %HashBase pointers should never be used.
*/
class DLL_API TestComments
{
public:
//----------------------------------------------------------------------
/// Get the string that needs to be written to the debugger stdin file
/// handle when a control character is typed.
///
/// Some GUI programs will intercept "control + char" sequences and want
/// to have them do what normally would happen when using a real
/// terminal, so this function allows GUI programs to emulate this
/// functionality.
///
/// @param[in] ch
/// The character that was typed along with the control key
///
/// @return
/// The string that should be written into the file handle that is
/// feeding the input stream for the debugger, or NULL if there is
/// no string for this control key.
//----------------------------------------------------------------------
const char * GetIOHandlerControlSequence(char ch);
};
class DLL_API AbstractWithVirtualDtor
{
public:

26
tests/Native/AST.h

@ -122,3 +122,29 @@ void instantiatesTemplate(TestSpecializationArguments<int> t) @@ -122,3 +122,29 @@ void instantiatesTemplate(TestSpecializationArguments<int> t)
{
}
/// Hash set/map base class.
/** Note that to prevent extra memory use due to vtable pointer, %HashBase intentionally does not declare a virtual destructor
and therefore %HashBase pointers should never be used.
*/
class TestComments
{
public:
//----------------------------------------------------------------------
/// Get the string that needs to be written to the debugger stdin file
/// handle when a control character is typed.
///
/// Some GUI programs will intercept "control + char" sequences and want
/// to have them do what normally would happen when using a real
/// terminal, so this function allows GUI programs to emulate this
/// functionality.
///
/// @param[in] ch
/// The character that was typed along with the control key
///
/// @return
/// The string that should be written into the file handle that is
/// feeding the input stream for the debugger, or NULL if there is
/// no string for this control key.
//----------------------------------------------------------------------
const char * GetIOHandlerControlSequence(char ch);
};

Loading…
Cancel
Save