You've already forked linux-packaging-mono
Imported Upstream version 6.6.0.89
Former-commit-id: b39a328747c2f3414dc52e009fb6f0aa80ca2492
This commit is contained in:
parent
cf815e07e0
commit
95fdb59ea6
86
external/api-doc-tools/mdoc/mdoc.Test/AssemblyGenerator.workbook
vendored
Normal file
86
external/api-doc-tools/mdoc/mdoc.Test/AssemblyGenerator.workbook
vendored
Normal file
@@ -0,0 +1,86 @@
|
||||
---
|
||||
id: c70709d1-d0a6-4dec-9ce5-de04540e5de6
|
||||
title: AssemblyGenerator
|
||||
uti: com.xamarin.workbook
|
||||
platforms:
|
||||
- Console
|
||||
---
|
||||
|
||||
From [this article](https://msdn.microsoft.com/en-us/library/system.runtime.compilerservices.isudtreturn\(v=vs.110\).aspx?cs-save-lang=1&cs-lang=csharp#code-snippet-1)
|
||||
|
||||
```csharp
|
||||
using System.Reflection;
|
||||
using System.Reflection.Emit;
|
||||
using System.Runtime.CompilerServices;
|
||||
using System.Threading;
|
||||
```
|
||||
|
||||
```csharp
|
||||
class CodeEmitter {
|
||||
AssemblyBuilder asmBuilder;
|
||||
string asmName;
|
||||
ModuleBuilder modBuilder;
|
||||
public CodeEmitter(string name) {
|
||||
asmName = name;
|
||||
AssemblyName aname = new AssemblyName { Name = name };
|
||||
AppDomain currentDomain = Thread.GetDomain();
|
||||
asmBuilder = currentDomain.DefineDynamicAssembly(aname, AssemblyBuilderAccess.RunAndSave);
|
||||
modBuilder = asmBuilder.DefineDynamicModule(asmName);
|
||||
}
|
||||
|
||||
public TypeBuilder CreateType(string name) {
|
||||
return modBuilder.DefineType(name, TypeAttributes.Public);
|
||||
}
|
||||
|
||||
public void WriteAssembly(MethodBuilder entryPoint) {
|
||||
asmBuilder.SetEntryPoint(entryPoint);
|
||||
asmBuilder.Save(asmName);
|
||||
}
|
||||
}
|
||||
```
|
||||
|
||||
```csharp
|
||||
void main() {
|
||||
CodeEmitter e = new CodeEmitter("test-mod.exe");
|
||||
TypeBuilder mainClass = e.CreateType("MainClass");
|
||||
|
||||
// main method
|
||||
MethodBuilder mBuilder = mainClass.DefineMethod("mainMethod", MethodAttributes.Static);
|
||||
ILGenerator ilGen = mBuilder.GetILGenerator();
|
||||
ilGen.Emit(OpCodes.Ldstr, "Hello World");
|
||||
Type[] type = new [] {typeof(string)};
|
||||
MethodInfo writeMI = typeof(Console).GetMethod("WriteLine", type);
|
||||
ilGen.EmitCall(OpCodes.Call, writeMI, null);
|
||||
ilGen.Emit(OpCodes.Ret);
|
||||
|
||||
Type[] fType = new [] { typeof(IsUdtReturn)};
|
||||
|
||||
// operator overload
|
||||
MethodBuilder sBuilder = mainClass.DefineMethod(
|
||||
"op_Decrement",
|
||||
MethodAttributes.Static | MethodAttributes.SpecialName | MethodAttributes.Public,
|
||||
CallingConventions.Any,
|
||||
Type.GetType("System.Void"),
|
||||
fType, // rtype required mods
|
||||
null, // rtype optional mods
|
||||
null, // parameters
|
||||
null, // parameter modreq
|
||||
null); // parameters modopt
|
||||
|
||||
var silGen = sBuilder.GetILGenerator();
|
||||
silGen.Emit(OpCodes.Ret);
|
||||
|
||||
// field
|
||||
//Type[] fType = new [] { typeof(IsUdtReturn)};
|
||||
mainClass.DefineField("modifiedInteger", Type.GetType("System.Type"), fType, null, FieldAttributes.Public);
|
||||
|
||||
// write
|
||||
mainClass.CreateType();
|
||||
e.WriteAssembly(mBuilder);
|
||||
Console.WriteLine("Assembly created");
|
||||
}
|
||||
```
|
||||
|
||||
```csharp
|
||||
main();
|
||||
```
|
||||
157
external/api-doc-tools/mdoc/mdoc.Test/BasicFormatterTests.cs
vendored
Normal file
157
external/api-doc-tools/mdoc/mdoc.Test/BasicFormatterTests.cs
vendored
Normal file
@@ -0,0 +1,157 @@
|
||||
using System;
|
||||
using System.Linq;
|
||||
using Mono.Cecil;
|
||||
using Mono.Documentation.Updater;
|
||||
using NUnit.Framework;
|
||||
|
||||
namespace mdoc.Test
|
||||
{
|
||||
public abstract class BasicFormatterTests<T> : BasicTests where T : MemberFormatter
|
||||
{
|
||||
protected abstract T formatter { get; }
|
||||
|
||||
protected MethodDefinition GetProperty(TypeDefinition testclass, Func<MethodDefinition, bool> query)
|
||||
{
|
||||
var methods = testclass.Methods;
|
||||
var member = methods.FirstOrDefault(query)?.Resolve();
|
||||
if (member == null)
|
||||
throw new Exception("Did not find the member in the test class");
|
||||
return member;
|
||||
}
|
||||
|
||||
protected MemberReference GetProperty(TypeDefinition type, string memberName)
|
||||
{
|
||||
var property = type.Properties.FirstOrDefault(i => i.Name == memberName);
|
||||
if (property == null)
|
||||
throw new Exception($"Can't find property {memberName}");
|
||||
return property;
|
||||
}
|
||||
|
||||
protected MemberReference GetField(TypeDefinition type, string eventName)
|
||||
{
|
||||
var property = type.Fields.SingleOrDefault(i => i.Name == eventName);
|
||||
if (property == null)
|
||||
throw new Exception($"Can't find field {eventName}");
|
||||
return property;
|
||||
}
|
||||
|
||||
protected MemberReference GetEvent(TypeDefinition type, string eventName)
|
||||
{
|
||||
var property = type.Events.SingleOrDefault(i => i.Name == eventName);
|
||||
if (property == null)
|
||||
throw new Exception($"Can't find field {eventName}");
|
||||
return property;
|
||||
}
|
||||
|
||||
protected void TestTypeSignature(Type type, string expected)
|
||||
{
|
||||
expected = FormatEndings(expected);
|
||||
var signature = GetTypeSignature(type);
|
||||
Assert.AreEqual(expected, signature);
|
||||
}
|
||||
|
||||
protected void TestTypeSignature(string libPath, string fullTypeName, string expected)
|
||||
{
|
||||
expected = FormatEndings(expected);
|
||||
var type = GetType(libPath, fullTypeName);
|
||||
var signature = formatter.GetDeclaration(type);
|
||||
Assert.AreEqual(expected, signature);
|
||||
}
|
||||
|
||||
private string GetTypeSignature(Type type)
|
||||
{
|
||||
var tref = GetType(type);
|
||||
var signature = formatter.GetDeclaration(tref);
|
||||
return signature;
|
||||
}
|
||||
|
||||
protected void TestMethodSignature(Type type, string expected, string memberName)
|
||||
{
|
||||
var signature = GetMethodSignature(type, memberName);
|
||||
Assert.AreEqual(FormatEndings(expected), signature);
|
||||
}
|
||||
|
||||
protected void TestMethodSignature(string libPath, string fullTypeName, string memberName, string expected)
|
||||
{
|
||||
var type = GetType(libPath, fullTypeName);
|
||||
var method = GetMethod(type, i => i.Name == memberName);
|
||||
var signature = formatter.GetDeclaration(method);
|
||||
Assert.AreEqual(FormatEndings(expected), signature);
|
||||
}
|
||||
|
||||
private string GetMethodSignature(Type type, string memberName)
|
||||
{
|
||||
var tref = GetType(type);
|
||||
var method = GetMethod(tref, i => i.Name == memberName);
|
||||
var signature = formatter.GetDeclaration(method);
|
||||
return signature;
|
||||
}
|
||||
|
||||
protected void TestPropertySignature(Type type, string expected, string memberName)
|
||||
{
|
||||
var signature = GetPropertySignature(type, memberName);
|
||||
Assert.AreEqual(FormatEndings(expected), signature);
|
||||
}
|
||||
|
||||
private string GetPropertySignature(Type type, string memberName)
|
||||
{
|
||||
var tref = GetType(type);
|
||||
return formatter.GetDeclaration(GetProperty(tref, memberName));
|
||||
}
|
||||
|
||||
protected void TestPropertySignature(string libPath, string fullTypeName, string memberName, string expected)
|
||||
{
|
||||
var type = GetType(libPath, fullTypeName);
|
||||
var property = GetProperty(type, memberName);
|
||||
var signature = formatter.GetDeclaration(property);
|
||||
Assert.AreEqual(FormatEndings(expected), signature);
|
||||
}
|
||||
|
||||
protected void TestEventSignature(Type type, string expected, string memberName)
|
||||
{
|
||||
var signature = GetEventSignature(type, memberName);
|
||||
Assert.AreEqual(expected, signature);
|
||||
}
|
||||
|
||||
private string GetEventSignature(Type type, string memberName)
|
||||
{
|
||||
var tref = GetType(type);
|
||||
return formatter.GetDeclaration(GetEvent(tref, memberName));
|
||||
}
|
||||
|
||||
protected void TestEventSignature(string libPath, string fullTypeName, string memberName, string expected)
|
||||
{
|
||||
var type = GetType(libPath, fullTypeName);
|
||||
var @event = GetEvent(type, memberName);
|
||||
var signature = formatter.GetDeclaration(@event);
|
||||
Assert.AreEqual(FormatEndings(expected), signature);
|
||||
}
|
||||
|
||||
protected void TestFieldSignature(Type type, string expected, string memberName)
|
||||
{
|
||||
var usage = GetFieldUsage(type, memberName);
|
||||
Assert.AreEqual(FormatEndings(expected), usage);
|
||||
}
|
||||
|
||||
private string GetFieldUsage(Type type, string memberName)
|
||||
{
|
||||
var tref = GetType(type);
|
||||
var field = GetField(tref, memberName);
|
||||
var signature = formatter.GetDeclaration(field);
|
||||
return signature;
|
||||
}
|
||||
|
||||
protected void TestFieldSignature(string libPath, string fullTypeName, string memberName, string expected)
|
||||
{
|
||||
var type = GetType(libPath, fullTypeName);
|
||||
var field = GetField(type, memberName);
|
||||
var signature = formatter.GetDeclaration(field);
|
||||
Assert.AreEqual(FormatEndings(expected), signature);
|
||||
}
|
||||
|
||||
protected static string FormatEndings(string s)
|
||||
{
|
||||
return s?.Replace("\r\n", MemberFormatter.GetLineEnding());
|
||||
}
|
||||
}
|
||||
}
|
||||
91
external/api-doc-tools/mdoc/mdoc.Test/BasicTests.cs
vendored
Normal file
91
external/api-doc-tools/mdoc/mdoc.Test/BasicTests.cs
vendored
Normal file
@@ -0,0 +1,91 @@
|
||||
using System;
|
||||
using System.Collections.Generic;
|
||||
using System.IO;
|
||||
using System.Linq;
|
||||
using System.Xml.Linq;
|
||||
using Mono.Cecil;
|
||||
using Mono.Documentation.Framework;
|
||||
|
||||
namespace mdoc.Test
|
||||
{
|
||||
public class BasicTests
|
||||
{
|
||||
protected Dictionary<string, ModuleDefinition> moduleCash = new Dictionary<string, ModuleDefinition>();
|
||||
protected Dictionary<string, TypeDefinition> typesCash = new Dictionary<string, TypeDefinition>();
|
||||
|
||||
protected TypeDefinition GetType(string filepath, string classname)
|
||||
{
|
||||
if (typesCash.ContainsKey(classname))
|
||||
return typesCash[classname];
|
||||
|
||||
|
||||
if (!moduleCash.ContainsKey(filepath))
|
||||
{
|
||||
var fullpath = Path.Combine (Path.GetDirectoryName (this.GetType ().Module.Assembly.Location), filepath);
|
||||
var resolver = new DefaultAssemblyResolver ();
|
||||
var testAssemblyPath = Path.GetDirectoryName (this.GetType ().Module.Assembly.Location);
|
||||
resolver.AddSearchDirectory (testAssemblyPath);
|
||||
|
||||
ReaderParameters p = new ReaderParameters ()
|
||||
{
|
||||
AssemblyResolver = resolver
|
||||
};
|
||||
|
||||
|
||||
var readModule = ModuleDefinition.ReadModule(fullpath, p);
|
||||
moduleCash.Add(filepath, readModule);
|
||||
}
|
||||
|
||||
var module = moduleCash[filepath];
|
||||
var types = module.GetTypes();
|
||||
var testclass = types
|
||||
.SingleOrDefault(t => t.FullName == classname);
|
||||
if (testclass == null)
|
||||
{
|
||||
throw new Exception($"Test was unable to find type {classname}");
|
||||
}
|
||||
|
||||
var typeDef = testclass.Resolve();
|
||||
typesCash.Add(classname, typeDef);
|
||||
return typeDef;
|
||||
}
|
||||
|
||||
protected virtual TypeDefinition GetType(Type type)
|
||||
{
|
||||
var moduleName = type.Module.FullyQualifiedName;
|
||||
return GetType(moduleName, type.FullName);
|
||||
}
|
||||
|
||||
protected static XDocument ReadXDocument(string xml)
|
||||
{
|
||||
using (TextReader stringReader = new StringReader(xml))
|
||||
{
|
||||
return XDocument.Load(stringReader);
|
||||
}
|
||||
}
|
||||
|
||||
protected static string NormalizeXml(string xml)
|
||||
{
|
||||
return ReadXDocument(xml).ToString();
|
||||
}
|
||||
|
||||
protected MethodDefinition GetMethod(TypeDefinition testclass, Func<MethodDefinition, bool> query)
|
||||
{
|
||||
var methods = testclass.Methods;
|
||||
var member = methods.FirstOrDefault(query)?.Resolve();
|
||||
if (member == null)
|
||||
throw new Exception("Did not find the member in the test class");
|
||||
return member;
|
||||
}
|
||||
|
||||
protected MethodDefinition GetMethod(Type type, Func<MethodDefinition, bool> query)
|
||||
{
|
||||
return GetMethod(GetType(type), query);
|
||||
}
|
||||
|
||||
protected MethodDefinition GetMethod(Type type, string name)
|
||||
{
|
||||
return GetMethod(GetType(type), i => i.Name == name);
|
||||
}
|
||||
}
|
||||
}
|
||||
157
external/api-doc-tools/mdoc/mdoc.Test/CppCxFormatterMembersTests.cs
vendored
Normal file
157
external/api-doc-tools/mdoc/mdoc.Test/CppCxFormatterMembersTests.cs
vendored
Normal file
@@ -0,0 +1,157 @@
|
||||
using Mono.Documentation.Updater.Formatters.CppFormatters;
|
||||
using Mono_DocTest;
|
||||
using NUnit.Framework;
|
||||
using Cpp = Mono_DocTest_Generic;
|
||||
|
||||
namespace mdoc.Test
|
||||
{
|
||||
[TestFixture]
|
||||
[Category("CppCx")]
|
||||
public class CppCxFormatterMembersTests : BasicFormatterTests<CppCxFullMemberFormatter>
|
||||
{
|
||||
protected override CppCxFullMemberFormatter formatter { get; } = new CppCxFullMemberFormatter();
|
||||
|
||||
private const string CppCxTestLibName = "../../../../external/Test/UwpTestWinRtComponentCpp.winmd";
|
||||
private const string CSharpTestLib = "../../../../external/Test/CSharpExample.dll";
|
||||
|
||||
[Test]
|
||||
[Category("Method")]
|
||||
public void Method_ComputeResult()
|
||||
{
|
||||
TestMethodSignature(CppCxTestLibName, "UwpTestWinRtComponentCpp.Class1", "ComputeResult",
|
||||
@"public:
|
||||
Windows::Foundation::Collections::IVector<double> ^ ComputeResult(double input);");
|
||||
}
|
||||
|
||||
[Test]
|
||||
[Category("Method")]
|
||||
public void Method_GetPrimesOrdered()
|
||||
{
|
||||
TestMethodSignature(CppCxTestLibName, "UwpTestWinRtComponentCpp.Class1", "GetPrimesOrdered",
|
||||
@"public:
|
||||
Windows::Foundation::IAsyncOperationWithProgress<Windows::Foundation::Collections::IVector<int> ^, double> ^ GetPrimesOrdered(int first, int last);");
|
||||
|
||||
}
|
||||
|
||||
[Test]
|
||||
[Category("Method")]
|
||||
public void Method_GetPrimesUnordered()
|
||||
{
|
||||
TestMethodSignature(CppCxTestLibName, "UwpTestWinRtComponentCpp.Class1", "GetPrimesUnordered",
|
||||
@"public:
|
||||
Windows::Foundation::IAsyncActionWithProgress<double> ^ GetPrimesUnordered(int first, int last);");
|
||||
}
|
||||
|
||||
[Test]
|
||||
[Category("Method")]
|
||||
public void Method_WinRtTypeInterfaceImplementation()
|
||||
{
|
||||
TestMethodSignature(CppCxTestLibName, "Namespace222.App", "SetWindow",
|
||||
@"public:
|
||||
virtual void SetWindow(Windows::UI::Core::CoreWindow ^ window) = Windows::ApplicationModel::Core::IFrameworkView::SetWindow;");
|
||||
}
|
||||
|
||||
[Test]
|
||||
[Category("Field")]
|
||||
public void Field_CustomAttributeFundamentalType()
|
||||
{
|
||||
TestFieldSignature(CppCxTestLibName, "UwpTestWinRtComponentCpp.CustomAttribute1", "Field1", "public: bool Field1;");
|
||||
}
|
||||
|
||||
|
||||
[Test]
|
||||
[Category("Field")]
|
||||
public void Field_CustomAttributуSpecificType()
|
||||
{
|
||||
TestFieldSignature(CppCxTestLibName, "UwpTestWinRtComponentCpp.CustomAttribute1", "Field2", "public: Windows::Foundation::HResult Field2;");
|
||||
}
|
||||
|
||||
[Test]
|
||||
[Category("Field")]
|
||||
public void Field_EnumField()
|
||||
{
|
||||
TestFieldSignature(CppCxTestLibName, "UwpTestWinRtComponentCpp.Color1", "Red", "Red");
|
||||
}
|
||||
|
||||
[Test]
|
||||
[Category("Field")]
|
||||
public void Field_ValueType_String()
|
||||
{
|
||||
TestFieldSignature(CppCxTestLibName, "Namespace2.Class4", "StringField", "public: Platform::String ^ StringField;");
|
||||
}
|
||||
|
||||
[Test]
|
||||
[Category("Event")]
|
||||
public void Event_Class1_primeFoundEvent()
|
||||
{
|
||||
TestEventSignature(CppCxTestLibName, "UwpTestWinRtComponentCpp.Class1", "primeFoundEvent", @"public:
|
||||
event UwpTestWinRtComponentCpp::PrimeFoundHandler ^ primeFoundEvent;");
|
||||
}
|
||||
|
||||
[Test]
|
||||
[Category("Properties")]
|
||||
public void Property_FundamentalType()
|
||||
{
|
||||
TestPropertySignature(CppCxTestLibName, "Namespace2.Class3", "LongProperty", @"public:
|
||||
property long long LongProperty { long long get(); void set(long long value); };");
|
||||
}
|
||||
|
||||
[Test]
|
||||
[Category("Properties")]
|
||||
public void Property_EII_implementation_correctDelimeter()
|
||||
{
|
||||
TestPropertySignature(CSharpTestLib, "Mono.DocTest.Generic.MyList`2", "System.Collections.Generic.ICollection<A>.IsReadOnly", @"property bool System::Collections::Generic::ICollection<A>::IsReadOnly { bool get(); };");
|
||||
}
|
||||
|
||||
[Test]
|
||||
[Category("Properties")]
|
||||
public void Property_ArrayOfTypeProperty()
|
||||
{
|
||||
TestPropertySignature(CppCxTestLibName, "Namespace2.Class3", "ArrayOfTypeProperty", @"public:
|
||||
property Platform::Array <Platform::Type ^> ^ ArrayOfTypeProperty { Platform::Array <Platform::Type ^> ^ get(); void set(Platform::Array <Platform::Type ^> ^ value); };");
|
||||
}
|
||||
|
||||
[Test]
|
||||
[Category("Properties")]
|
||||
public void Property_ArrayOfTypePropertyProtected()
|
||||
{
|
||||
TestPropertySignature(CppCxTestLibName, "Namespace2.Class3", "ArrayOfTypePropertyProtected", @"protected:
|
||||
property Platform::Array <Platform::Type ^> ^ ArrayOfTypePropertyProtected { Platform::Array <Platform::Type ^> ^ get(); void set(Platform::Array <Platform::Type ^> ^ value); };");
|
||||
}
|
||||
|
||||
[Test]
|
||||
[Category("NoSupport")]
|
||||
public void NoSupport_ParamsKeyword_M6()
|
||||
{
|
||||
TestMethodSignature(typeof(Widget), null, "M6");
|
||||
}
|
||||
|
||||
[Test]
|
||||
[Category("NoSupport")]
|
||||
public void NoSupport_DefaultParameters()
|
||||
{
|
||||
TestMethodSignature(CSharpTestLib, "Mono.DocTest.Widget", "Default", null);
|
||||
}
|
||||
|
||||
[TearDown]
|
||||
public void TearDown()
|
||||
{
|
||||
moduleCash.Clear();
|
||||
}
|
||||
[Test]
|
||||
[Category("NoSupport")]
|
||||
public void NoSupport_Exception_NestedClassWithSameName()
|
||||
{
|
||||
TestTypeSignature(CSharpTestLib, "Mono.DocTest.Widget/NestedClass", null);
|
||||
}
|
||||
|
||||
[Test]
|
||||
[Category("NoSupport")]
|
||||
public void NoSupport_GenericMethodInUwp()
|
||||
{
|
||||
TestMethodSignature(typeof(Cpp.GenericBase<>), null, "BaseMethod2");
|
||||
}
|
||||
}
|
||||
|
||||
}
|
||||
|
||||
197
external/api-doc-tools/mdoc/mdoc.Test/CppCxFormatterTypesTests.cs
vendored
Normal file
197
external/api-doc-tools/mdoc/mdoc.Test/CppCxFormatterTypesTests.cs
vendored
Normal file
@@ -0,0 +1,197 @@
|
||||
using System;
|
||||
using Mono.Cecil;
|
||||
using Mono.Documentation.Updater.Formatters.CppFormatters;
|
||||
using Mono_DocTest;
|
||||
using Mono_DocTest_Generic;
|
||||
using NUnit.Framework;
|
||||
|
||||
namespace mdoc.Test
|
||||
{
|
||||
[TestFixture]
|
||||
[Category("CppCx")]
|
||||
public class CppCxFormatterTypesTests : BasicFormatterTests<CppCxMemberFormatter>
|
||||
{
|
||||
protected override CppCxMemberFormatter formatter => new CppCxMemberFormatter();
|
||||
|
||||
private string _cppCxTestLibName = "../../../../external/Test/UwpTestWinRtComponentCpp.winmd";
|
||||
|
||||
protected override TypeDefinition GetType(Type type)
|
||||
{
|
||||
var moduleName = type.Module.FullyQualifiedName;
|
||||
|
||||
var tref = GetType(moduleName, type.FullName?.Replace("+", "/"));
|
||||
return tref;
|
||||
}
|
||||
|
||||
[Test]
|
||||
[Category("Type")]
|
||||
public void TypeSignature_CustomAttribute()
|
||||
{
|
||||
TestTypeSignature(_cppCxTestLibName, "UwpTestWinRtComponentCpp.CustomAttribute1",
|
||||
"public ref class CustomAttribute1 sealed : Platform::Metadata::Attribute");
|
||||
}
|
||||
|
||||
[Test]
|
||||
[Category("Type")]
|
||||
public void TypeSignature_Class1()
|
||||
{
|
||||
TestTypeSignature(_cppCxTestLibName, "UwpTestWinRtComponentCpp.Class1",
|
||||
"public ref class Class1 sealed");
|
||||
}
|
||||
|
||||
[Test]
|
||||
[Category("Type")]
|
||||
public void TypeSignature_delegate()
|
||||
{
|
||||
TestTypeSignature(_cppCxTestLibName, "UwpTestWinRtComponentCpp.PrimeFoundHandler",
|
||||
"public delegate void PrimeFoundHandler(int result);");
|
||||
}
|
||||
|
||||
[Test]
|
||||
[Category("Type")]
|
||||
public void TypeSignature_delegateWithSpecificType()
|
||||
{
|
||||
TestTypeSignature(_cppCxTestLibName, "UwpTestWinRtComponentCpp.PrimeFoundHandlerWithSpecificType",
|
||||
"public delegate void PrimeFoundHandlerWithSpecificType(IMap<double, float> ^ result);");
|
||||
}
|
||||
|
||||
[Test]
|
||||
[Category("Type")]
|
||||
public void TypeSignature_delegateWithCustomType()
|
||||
{
|
||||
TestTypeSignature(_cppCxTestLibName, "UwpTestWinRtComponentCpp.SomethingHappenedEventHandler",
|
||||
"public delegate void SomethingHappenedEventHandler(Class1 ^ sender, Platform::String ^ s);");
|
||||
}
|
||||
|
||||
[Test]
|
||||
[Category("Type")]
|
||||
public void TypeSignature_enum()
|
||||
{
|
||||
TestTypeSignature(_cppCxTestLibName, "UwpTestWinRtComponentCpp.Color1", "public enum class Color1");
|
||||
}
|
||||
|
||||
[Test]
|
||||
[Category("Type")]
|
||||
public void TypeSignature_publicUnsealedClass()
|
||||
{
|
||||
TestTypeSignature(_cppCxTestLibName, "Namespace2.Class2", @"public ref class Class2 : Windows::UI::Xaml::Application");
|
||||
|
||||
}
|
||||
|
||||
[Test]
|
||||
[Category("Type")]
|
||||
public void TypeSignature_ValueClass()
|
||||
{
|
||||
TestTypeSignature(_cppCxTestLibName, "Namespace2.Class4", "public value class Class4");
|
||||
}
|
||||
|
||||
#region NoSupport
|
||||
|
||||
[Test]
|
||||
[Category("NoSupport")]
|
||||
public void NoSupport_GenericDelegate()
|
||||
{
|
||||
TestTypeSignature(typeof(Action22<>), null);
|
||||
}
|
||||
|
||||
[Test]
|
||||
[Category("NoSupport")]
|
||||
public void NoSupport_DelegateWithSystemType()
|
||||
{
|
||||
TestTypeSignature(typeof(DelegateWithNetSystemType), null);
|
||||
}
|
||||
|
||||
[Test]
|
||||
[Category("NoSupport")]
|
||||
public void NoSupport_NoNamespace()
|
||||
{
|
||||
TestTypeSignature(typeof(NoNamespace), null);
|
||||
}
|
||||
|
||||
[Test]
|
||||
[Category("NoSupport")]
|
||||
public void NoSupport_StandardType()
|
||||
{
|
||||
TestMethodSignature(typeof(UseLists), null, nameof(UseLists.Process));
|
||||
}
|
||||
|
||||
[Test]
|
||||
[Category("NoSupport")]
|
||||
public void NoSupport_PublicNestedType()
|
||||
{
|
||||
TestTypeSignature(typeof(Widget.NestedClass), null);
|
||||
}
|
||||
|
||||
[Test]
|
||||
[Category("NoSupport")]
|
||||
public void NoSupport_PublicNestedEnum()
|
||||
{
|
||||
TestTypeSignature(typeof(Widget.NestedEnum), null);
|
||||
}
|
||||
|
||||
[Test]
|
||||
[Category("NoSupport")]
|
||||
public void NoSupport_JaggedArrays()
|
||||
{
|
||||
TestMethodSignature(typeof(Widget), null, "M2");
|
||||
}
|
||||
|
||||
[Test]
|
||||
[Category("NoSupport")]
|
||||
public void NoSupport_PublicConstructorUnsealedClass()
|
||||
{
|
||||
TestTypeSignature(typeof(DocAttribute), null);
|
||||
}
|
||||
|
||||
[Test]
|
||||
[Category("NoSupport")]
|
||||
public void NoSupport_PublicRefClassWithGeneric()
|
||||
{
|
||||
TestTypeSignature(typeof(GenericBase<>), null);
|
||||
}
|
||||
|
||||
[Test]
|
||||
[Category("NoSupport")]
|
||||
public void NoSupport_GenericInterfaceWithConstraints()
|
||||
{
|
||||
TestTypeSignature(typeof(IFooNew<>), null);
|
||||
}
|
||||
|
||||
[Test]
|
||||
[Category("NoSupport")]
|
||||
public void NoSupport_ValueTypeWithNotAllowedType()
|
||||
{
|
||||
TestTypeSignature(typeof(ValueClassSpecificField), null);
|
||||
}
|
||||
|
||||
[Test]
|
||||
[Category("NoSupport")]
|
||||
public void NoSupport_PublicIndexedProperty()
|
||||
{
|
||||
TestPropertySignature(typeof(Widget), null, "indexedProperty");
|
||||
}
|
||||
|
||||
[Test]
|
||||
[Category("NoSupport")]
|
||||
public void NoSupport_CustomException()
|
||||
{
|
||||
TestTypeSignature(typeof(CustomException), null);
|
||||
}
|
||||
|
||||
[Test]
|
||||
[Category("NoSupport")]
|
||||
public void NoSupport_Exception_ArgumentNullExceptionField()
|
||||
{
|
||||
TestFieldSignature(typeof(CustomException), null, "ArgumentNullExceptionField");
|
||||
}
|
||||
|
||||
#endregion
|
||||
|
||||
[TearDown]
|
||||
public void TearDown()
|
||||
{
|
||||
moduleCash.Clear();
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
194
external/api-doc-tools/mdoc/mdoc.Test/CppFormatterTests.cs
vendored
Normal file
194
external/api-doc-tools/mdoc/mdoc.Test/CppFormatterTests.cs
vendored
Normal file
@@ -0,0 +1,194 @@
|
||||
using System;
|
||||
using Mono.Cecil;
|
||||
using NUnit.Framework;
|
||||
using Mono.Documentation.Updater.Formatters.CppFormatters;
|
||||
using Mono_DocTest_Generic;
|
||||
using Mono_DocTest;
|
||||
|
||||
namespace mdoc.Test
|
||||
{
|
||||
public class CppFormatterTests : BasicFormatterTests<CppMemberFormatter>
|
||||
{
|
||||
#region Types
|
||||
private static readonly CppMemberFormatter cppMemberFormatter = new CppMemberFormatter();
|
||||
protected override CppMemberFormatter formatter => cppMemberFormatter;
|
||||
|
||||
[Test]
|
||||
[Category("Types")]
|
||||
public void TypeSignature_Extensions() =>
|
||||
TestTypeSignature(typeof(Extensions), @"public ref class Extensions abstract sealed");
|
||||
|
||||
[Test]
|
||||
[Category("Types")]
|
||||
public void TypeSignature_GenericBase() =>
|
||||
TestTypeSignature(typeof(GenericBase<>), @"generic <typename U>
|
||||
public ref class GenericBase");
|
||||
|
||||
[Test]
|
||||
[Category("Types")]
|
||||
public void TypeSignature_MyList() =>
|
||||
TestTypeSignature(typeof(MyList<>), @"generic <typename T>
|
||||
public ref class MyList : Mono_DocTest_Generic::GenericBase<T>, System::Collections::Generic::IEnumerable<cli::array <int> ^>");
|
||||
|
||||
[Test]
|
||||
[Category("Types")]
|
||||
public void TypeSignature_IFoo() =>
|
||||
TestTypeSignature(typeof(IFoo<>), @"generic <typename T>
|
||||
public interface class IFoo");
|
||||
|
||||
[Test]
|
||||
[Category("Types")]
|
||||
public void TypeSignature_MyList1() =>
|
||||
TestTypeSignature(typeof(MyList1<,>), @"generic <typename A, typename B>
|
||||
public ref class MyList1 : Mono_DocTest_Generic::GenericBase<System::Collections::Generic::Dictionary<A, B> ^>, Mono_DocTest_Generic::IFoo<A>, System::Collections::Generic::ICollection<A>, System::Collections::Generic::IEnumerable<A>, System::Collections::Generic::IEnumerator<A>");
|
||||
|
||||
[Test]
|
||||
[Category("Types")]
|
||||
public void TypeSignature_Color() =>
|
||||
TestTypeSignature(typeof(Color), @"public enum class Color");
|
||||
|
||||
[Test]
|
||||
[Category("Types")]
|
||||
public void TypeSignature_Nonamespace() =>
|
||||
TestTypeSignature(typeof(NoNamespace), @"public ref class NoNamespace");
|
||||
|
||||
[Test]
|
||||
[Category("Types")]
|
||||
public void TypeSignature_DocAttribute() =>
|
||||
TestTypeSignature(typeof(DocAttribute), @"public ref class DocAttribute : Attribute");
|
||||
[Test]
|
||||
[Category("Types")]
|
||||
public void TypeSignature_Environment1() =>
|
||||
TestTypeSignature(typeof(Environment1), @"public ref class Environment1 abstract sealed");
|
||||
|
||||
[Test]
|
||||
[Category("Types")]
|
||||
public void TypeSignature_IProcess() =>
|
||||
TestTypeSignature(typeof(IProcess), @"public interface class IProcess");
|
||||
|
||||
[Test]
|
||||
[Category("Types")]
|
||||
public void TypeSignature_DocValueType() =>
|
||||
TestTypeSignature(typeof(DocValueType), @"public value class DocValueType : Mono_DocTest::IProcess");
|
||||
|
||||
[Test]
|
||||
[Category("Types")]
|
||||
public void TypeSignature_D() =>
|
||||
TestTypeSignature(typeof(D), @"public delegate System::Object ^ D(Func<System::String ^, System::Object ^, System::Object ^> ^ value);");
|
||||
|
||||
|
||||
[Test]
|
||||
[Category("Fields")]
|
||||
public void FieldSignature_NonFlagEnum() =>
|
||||
TestFieldSignature(typeof(DocAttribute),
|
||||
"public: Color NonFlagsEnum;",
|
||||
nameof(DocAttribute.NonFlagsEnum));
|
||||
|
||||
[Test]
|
||||
[Category("Types")]
|
||||
public void TypeSignature_Widget() =>
|
||||
TestTypeSignature(typeof(Widget), @"public ref class Widget : Mono_DocTest::IProcess");
|
||||
|
||||
[Test]
|
||||
[Category("Types")]
|
||||
public void TypeSignature_FooEventArgs() =>
|
||||
TestTypeSignature(typeof(GenericBase<>.FooEventArgs), @"public: ref class GenericBase<U>::FooEventArgs : EventArgs");
|
||||
|
||||
[Test]
|
||||
[Category("Fields")]
|
||||
public void FieldSignature_StaticField1() =>
|
||||
TestFieldSignature(typeof(GenericBase<>),
|
||||
"public: static initonly GenericBase<U> ^ StaticField1;",
|
||||
nameof(GenericBase<int>.StaticField1));
|
||||
|
||||
[Test]
|
||||
[Category("Fields")]
|
||||
public void FieldSignature_NonFlagsEnum() =>
|
||||
TestFieldSignature(typeof(DocAttribute),
|
||||
"public: Color NonFlagsEnum;",
|
||||
nameof(DocAttribute.NonFlagsEnum));
|
||||
|
||||
[Test]
|
||||
[Category("Fields")]
|
||||
public void FieldSignature_Pointers_ppValues() =>
|
||||
TestFieldSignature(typeof(Widget),
|
||||
"public: float** ppValues;",
|
||||
nameof(Widget.ppValues));
|
||||
|
||||
[Test]
|
||||
[Category("Fields")]
|
||||
public void FieldSignature_Pointers_pCount() =>
|
||||
TestFieldSignature(typeof(Widget),
|
||||
"public: int* pCount;",
|
||||
nameof(Widget.pCount));
|
||||
|
||||
[Test]
|
||||
[Category("Fields")]
|
||||
public void FieldSignature_value() =>
|
||||
TestFieldSignature(typeof(Widget.NestedClass),
|
||||
"public: int value;",
|
||||
nameof(Widget.NestedClass.value));
|
||||
|
||||
[Test]
|
||||
[Category("Fields")]
|
||||
public void FieldSignature_protectedPublic_monthlyAverage()
|
||||
{
|
||||
TestFieldSignature(typeof(Widget), @"protected public: initonly double monthlyAverage;", "monthlyAverage");
|
||||
}
|
||||
|
||||
[Test]
|
||||
[Category("Properties")]
|
||||
public void PropertySignature_IndexedPropertyNamed()
|
||||
{
|
||||
TestPropertySignature(typeof(Widget), @"public:
|
||||
property long indexedProperty[long] { long get(long index); void set(long index, long value); };",
|
||||
"indexedProperty");
|
||||
}
|
||||
|
||||
[Test]
|
||||
[Category("Properties")]
|
||||
public void PropertySignature_IndexedPropertyDefault()
|
||||
{
|
||||
TestPropertySignature(typeof(Widget), @"public:
|
||||
property int default[System::String ^, int] { int get(System::String ^ s, int i); void set(System::String ^ s, int i, int value); };",
|
||||
"Item");
|
||||
}
|
||||
|
||||
|
||||
[Test]
|
||||
[Category("Properties")]
|
||||
public void PropertySignature_Current3() =>
|
||||
TestPropertySignature(typeof(MyList1<,>), @"public:
|
||||
virtual property System::Object ^ Current3 { System::Object ^ get(); };",
|
||||
nameof(MyList1<int,int>.Current3));
|
||||
|
||||
[Test]
|
||||
[Category("Properties")]
|
||||
public void PropertySignature_B() =>
|
||||
TestPropertySignature(typeof(Widget.IMenuItem), @"public:
|
||||
property int B { int get(); void set(int value); };",
|
||||
nameof(Widget.IMenuItem.B));
|
||||
[Test]
|
||||
[Category("Properties")]
|
||||
public void PropertySignature_Count() =>
|
||||
TestPropertySignature(typeof(MyList1<,>), @"public:
|
||||
virtual property int Count { int get(); };",
|
||||
nameof(MyList1<int, int>.Count));
|
||||
|
||||
[Test]
|
||||
[Category("Types")]
|
||||
public void TypeSignature_AsyncCallback() =>
|
||||
TestTypeSignature(typeof(AsyncCallback), @"public delegate void AsyncCallback(IAsyncResult ^ ar);");
|
||||
|
||||
#endregion
|
||||
|
||||
protected override TypeDefinition GetType(Type type)
|
||||
{
|
||||
var moduleName = type.Module.FullyQualifiedName;
|
||||
|
||||
var tref = GetType(moduleName, type.FullName.Replace("+", "/"));
|
||||
return tref;
|
||||
}
|
||||
|
||||
}
|
||||
}
|
||||
308
external/api-doc-tools/mdoc/mdoc.Test/CppFullFormatterTests.cs
vendored
Normal file
308
external/api-doc-tools/mdoc/mdoc.Test/CppFullFormatterTests.cs
vendored
Normal file
@@ -0,0 +1,308 @@
|
||||
using System;
|
||||
using Mono.Cecil;
|
||||
using NUnit.Framework;
|
||||
using Mono.Documentation.Updater.Formatters.CppFormatters;
|
||||
using Mono_DocTest_Generic;
|
||||
using Cpp=Mono_DocTest_Generic;
|
||||
using Mono_DocTest;
|
||||
|
||||
namespace mdoc.Test
|
||||
{
|
||||
public class CppFullFormatterTests: BasicFormatterTests<CppFullMemberFormatter>
|
||||
{
|
||||
private static readonly CppFullMemberFormatter cppFullMemberFormatter = new CppFullMemberFormatter();
|
||||
protected override CppFullMemberFormatter formatter => cppFullMemberFormatter;
|
||||
private const string CSharpTestLib = "../../../../external/Test/CSharpExample.dll";
|
||||
[Test]
|
||||
[Category("Methods")]
|
||||
public void MethodSignature_Bar() =>
|
||||
TestMethodSignature(typeof(Cpp.Extensions), @"public:
|
||||
generic <typename T>
|
||||
[System::Runtime::CompilerServices::Extension]
|
||||
static void Bar(IFoo<T> ^ self, System::String ^ s);",
|
||||
nameof(Cpp.Extensions.Bar));
|
||||
|
||||
[Test]
|
||||
[Category("Methods")]
|
||||
public void MethodSignature_ForEach() =>
|
||||
TestMethodSignature(typeof(Cpp.Extensions), @"public:
|
||||
generic <typename T>
|
||||
[System::Runtime::CompilerServices::Extension]
|
||||
static void ForEach(System::Collections::Generic::IEnumerable<T> ^ self, Action<T> ^ a);",
|
||||
nameof(Cpp.Extensions.ForEach));
|
||||
|
||||
[Test]
|
||||
[Category("Methods")]
|
||||
public void MethodSignature_ToEnumerable() =>
|
||||
TestMethodSignature(typeof(Cpp.Extensions), @"public:
|
||||
generic <typename T>
|
||||
[System::Runtime::CompilerServices::Extension]
|
||||
static System::Collections::Generic::IEnumerable<T> ^ ToEnumerable(T self);",
|
||||
nameof(Cpp.Extensions.ToEnumerable));
|
||||
|
||||
[Test]
|
||||
[Category("Methods")]
|
||||
public void MethodSignature_ToDouble() =>
|
||||
TestMethodSignature(typeof(Cpp.Extensions), @"public:
|
||||
generic <typename T>
|
||||
where T : IFoo<T>[System::Runtime::CompilerServices::Extension]
|
||||
static double ToDouble(T val);",
|
||||
nameof(Cpp.Extensions.ToDouble));
|
||||
|
||||
[Test]
|
||||
[Category("Methods")]
|
||||
public void MethodSignature_BaseMethod() =>
|
||||
TestMethodSignature(typeof(GenericBase<>), @"public:
|
||||
generic <typename S>
|
||||
U BaseMethod(S genericParameter);",
|
||||
nameof(GenericBase<int>.BaseMethod));
|
||||
|
||||
[Test]
|
||||
[Category("Methods")]
|
||||
public void MethodSignature_Method() =>
|
||||
TestMethodSignature(typeof(IFoo<>), @"public:
|
||||
generic <typename U>
|
||||
T Method(T t, U u);",
|
||||
nameof(IFoo<int>.Method));
|
||||
|
||||
[Test]
|
||||
[Category("Fields")]
|
||||
public void FieldSignature_ConstInt() =>
|
||||
TestFieldSignature(typeof(GenericBase<>),
|
||||
"public: const int ConstInt;",
|
||||
nameof(GenericBase<int>.ConstInt));
|
||||
|
||||
[Test]
|
||||
[Category("Fields")]
|
||||
public void FieldSignature_ConstLong() =>
|
||||
TestFieldSignature(typeof(GenericBase<>),
|
||||
"public: const long ConstLong;",
|
||||
nameof(GenericBase<int>.ConstLong));
|
||||
|
||||
[Test]
|
||||
[Category("Fields")]
|
||||
public void FieldSignature_ConstDecimal() =>
|
||||
TestFieldSignature(typeof(GenericBase<>),
|
||||
"public: const System::Decimal ConstDecimal;",
|
||||
nameof(GenericBase<int>.ConstDecimal));
|
||||
|
||||
[Test]
|
||||
[Category("Fields")]
|
||||
public void FieldSignature_ConstShort() =>
|
||||
TestFieldSignature(typeof(GenericBase<>),
|
||||
"public: const short ConstShort;",
|
||||
nameof(GenericBase<int>.ConstShort));
|
||||
[Test]
|
||||
[Category("Fields")]
|
||||
public void FieldSignature_ConstUint16() =>
|
||||
TestFieldSignature(typeof(GenericBase<>),
|
||||
"public: const System::UInt16 ConstUint16;",
|
||||
nameof(GenericBase<int>.ConstUint16));
|
||||
[Test]
|
||||
[Category("Fields")]
|
||||
public void FieldSignature_ConstUint32() =>
|
||||
TestFieldSignature(typeof(GenericBase<>),
|
||||
"public: const System::UInt32 ConstUint32;",
|
||||
nameof(GenericBase<int>.ConstUint32));
|
||||
[Test]
|
||||
[Category("Fields")]
|
||||
public void FieldSignature_ConstUint64() =>
|
||||
TestFieldSignature(typeof(GenericBase<>),
|
||||
"public: const System::UInt64 ConstUint64;",
|
||||
nameof(GenericBase<int>.ConstUint64));
|
||||
[Test]
|
||||
[Category("Fields")]
|
||||
public void FieldSignature_ConstFloat() =>
|
||||
TestFieldSignature(typeof(GenericBase<>),
|
||||
"public: const float ConstFloat;",
|
||||
nameof(GenericBase<int>.ConstFloat));
|
||||
[Test]
|
||||
[Category("Fields")]
|
||||
public void FieldSignature_ConstBool() =>
|
||||
TestFieldSignature(typeof(GenericBase<>),
|
||||
"public: const bool ConstBool;",
|
||||
nameof(GenericBase<int>.ConstBool));
|
||||
|
||||
[Test]
|
||||
[Category("Fields")]
|
||||
public void FieldSignature_ConstChar() =>
|
||||
TestFieldSignature(typeof(GenericBase<>),
|
||||
"public: const char ConstChar;",
|
||||
nameof(GenericBase<int>.ConstChar));
|
||||
|
||||
[Test]
|
||||
[Category("Fields")]
|
||||
public void FieldSignature_ConstObject() =>
|
||||
TestFieldSignature(typeof(GenericBase<>),
|
||||
"public: const System::Object ^ ConstObject;",
|
||||
nameof(GenericBase<int>.ConstObject));
|
||||
|
||||
|
||||
[Test]
|
||||
[Category("Fields")]
|
||||
public void FieldSignature_ConstString() =>
|
||||
TestFieldSignature(typeof(GenericBase<>),
|
||||
"public: const System::String ^ ConstString;",
|
||||
nameof(GenericBase<int>.ConstString));
|
||||
|
||||
[Test]
|
||||
[Category("Methods")]
|
||||
public void MethodSignature_AsReadOnly() =>
|
||||
TestMethodSignature(typeof(Array1), @"public:
|
||||
generic <typename T>
|
||||
static System::Collections::ObjectModel::ReadOnlyCollection<T> ^ AsReadOnly(cli::array <T> ^ array);",
|
||||
nameof(Array1.AsReadOnly));
|
||||
|
||||
[Test]
|
||||
[Category("Methods")]
|
||||
public void MethodSignature_UseT() =>
|
||||
TestMethodSignature(typeof(MyList<>.Helper<,>), @"public:
|
||||
void UseT(T a, U b, V c);",
|
||||
nameof(MyList<int>.Helper<int,int>.UseT));
|
||||
|
||||
[Test]
|
||||
[Category("Methods")]
|
||||
public void MethodSignature_s() =>
|
||||
TestMethodSignature(typeof(Widget), @"public:
|
||||
Func<System::String ^, System::Object ^> ^ Dynamic2(Func<System::String ^, System::Object ^> ^ value);",
|
||||
nameof(Widget.Dynamic2));
|
||||
|
||||
[Test]
|
||||
[Category("Methods")]
|
||||
public void MethodSignature_M2() =>
|
||||
TestMethodSignature(typeof(Widget), @"public:
|
||||
void M2(cli::array <short> ^ x1, cli::array <int, 2> ^ x2, cli::array <cli::array <long> ^> ^ x3);",
|
||||
nameof(Widget.M2));
|
||||
|
||||
[Test]
|
||||
[Category("Methods")]
|
||||
public void MethodSignature_PointersOnHat_JaggedArray_M5() =>
|
||||
TestMethodSignature(typeof(Widget), @"protected:
|
||||
void M5(void* pv, cli::array <cli::array <double, 2> ^> ^* pd);",
|
||||
"M5");
|
||||
|
||||
[Test]
|
||||
[Category("Methods")]
|
||||
public void MethodSignature_PointersOnHat_ReferenceType_M55() =>
|
||||
TestMethodSignature(typeof(Widget), @"protected:
|
||||
void M55(void* pv, System::String ^* pd);",
|
||||
"M55");
|
||||
|
||||
[Test]
|
||||
[Category("Methods")]
|
||||
public void MethodSignature_GenericRefParams_RefMethod() =>
|
||||
TestMethodSignature(typeof(MyList<>), @"public:
|
||||
generic <typename U>
|
||||
void RefMethod(T % t, U % u);",
|
||||
nameof(MyList<int>.RefMethod));
|
||||
|
||||
[Test]
|
||||
[Category("Methods")]
|
||||
public void MethodSignature_RefParams_M1() =>
|
||||
TestMethodSignature(typeof(Widget), @"public:
|
||||
void M1(long c, [Runtime::InteropServices::Out] float % f, Mono_DocTest::DocValueType % v);",
|
||||
nameof(Widget.M1));
|
||||
|
||||
[Test]
|
||||
[Category("Methods")]
|
||||
public void MethodSignature_RefParamsWithHat_RefMethod() =>
|
||||
TestMethodSignature(typeof(Array1), @"public:
|
||||
generic <typename T>
|
||||
static void Resize(cli::array <T> ^ % array, int newSize);",
|
||||
nameof(Array1.Resize));
|
||||
|
||||
[Test]
|
||||
[Category("Methods")]
|
||||
public void MethodSignature_Reset() =>
|
||||
TestMethodSignature(typeof(MyList1<,>), @"public:
|
||||
virtual void Reset();",
|
||||
nameof(MyList1<int,int>.Reset));
|
||||
|
||||
[Test]
|
||||
[Category("Methods")]
|
||||
public void MethodSignature_GetEnumerator1() =>
|
||||
TestMethodSignature(typeof(MyList<>), @"public:
|
||||
virtual System::Collections::IEnumerator ^ GetEnumerator1() = System::Collections::IEnumerable::GetEnumerator;",
|
||||
nameof(MyList<int>.GetEnumerator1));
|
||||
|
||||
[Test]
|
||||
[Category("Methods")]
|
||||
public void MethodSignature_GetEnumeratorIEnumerable() =>
|
||||
TestMethodSignature(typeof(MyList1<,>), @"public:
|
||||
virtual System::Collections::IEnumerator ^ GetEnumerator1() = System::Collections::IEnumerable::GetEnumerator;",
|
||||
nameof(MyList1<int,int>.GetEnumerator1));
|
||||
|
||||
[Test]
|
||||
[Category("Methods")]
|
||||
public void MethodSignature_GetEnumeratorGenericIEnumerable()
|
||||
{
|
||||
TestMethodSignature(
|
||||
typeof(MyList1<,>), @"public:
|
||||
virtual System::Collections::Generic::IEnumerator<A> ^ GetEnumerator() = System::Collections::Generic::IEnumerable<A>::GetEnumerator;",
|
||||
nameof(MyList1<int, int>.GetEnumerator));
|
||||
|
||||
}
|
||||
|
||||
[Test]
|
||||
[Category("Methods")]
|
||||
public void MethodSignature_opAddition() =>
|
||||
TestMethodSignature(typeof(Widget), @"public:
|
||||
static Mono_DocTest::Widget ^ operator +(Mono_DocTest::Widget ^ x1, Mono_DocTest::Widget ^ x2);",
|
||||
"op_Addition");
|
||||
|
||||
|
||||
[Test]
|
||||
[Category("Methods")]
|
||||
[Category("NoSupport")]
|
||||
public void MethodSignature_NoSupport_DefaultValue() =>
|
||||
TestMethodSignature(CSharpTestLib, "Mono.DocTest.Widget", "Default",
|
||||
null);
|
||||
|
||||
[Test]
|
||||
[Category("NoSupport")]
|
||||
public void NoSupport_Exception_NestedClassWithSameName()
|
||||
{
|
||||
TestTypeSignature(CSharpTestLib, "Mono.DocTest.Widget/NestedClass", null);
|
||||
}
|
||||
|
||||
[Test]
|
||||
[Category("Methods")]
|
||||
public void MethodSignature_opExplicit() =>
|
||||
TestMethodSignature(typeof(Widget), @"public:
|
||||
static explicit operator int(Mono_DocTest::Widget ^ x);",
|
||||
"op_Explicit");
|
||||
|
||||
[Test]
|
||||
[Category("Methods")]
|
||||
public void MethodSignature_opImplicit() =>
|
||||
TestMethodSignature(typeof(Widget), @"public:
|
||||
static operator long(Mono_DocTest::Widget ^ x);",
|
||||
"op_Implicit");
|
||||
|
||||
[Test]
|
||||
[Category("Methods")]
|
||||
public void MethodSignature_constructor()
|
||||
{
|
||||
TestMethodSignature(typeof(Widget), @"public:
|
||||
Widget(Converter<System::String ^, System::String ^> ^ c);",
|
||||
".ctor");
|
||||
}
|
||||
|
||||
[Test]
|
||||
[Category("Methods")]
|
||||
public void MethodSignature_ParamsKeyword_M6()
|
||||
{
|
||||
TestMethodSignature(typeof(Widget), @"protected:
|
||||
void M6(int i, ... cli::array <System::Object ^> ^ args);",
|
||||
"M6");
|
||||
}
|
||||
|
||||
protected override TypeDefinition GetType(Type type)
|
||||
{
|
||||
var moduleName = type.Module.FullyQualifiedName;
|
||||
|
||||
var tref = GetType(moduleName, type.FullName.Replace("+", "/"));
|
||||
return tref;
|
||||
}
|
||||
}
|
||||
}
|
||||
146
external/api-doc-tools/mdoc/mdoc.Test/CppWinRtFormatterTests.cs
vendored
Normal file
146
external/api-doc-tools/mdoc/mdoc.Test/CppWinRtFormatterTests.cs
vendored
Normal file
@@ -0,0 +1,146 @@
|
||||
using System;
|
||||
using Mono.Cecil;
|
||||
using Mono.Documentation.Updater.CppFormatters;
|
||||
using Mono.Documentation.Updater.Formatters.CppFormatters;
|
||||
using Mono_DocTest;
|
||||
using Mono_DocTest_Generic;
|
||||
using NUnit.Framework;
|
||||
|
||||
namespace mdoc.Test
|
||||
{
|
||||
[TestFixture]
|
||||
public class CppWinRtFormatterTests : BasicFormatterTests<CppWinRtMemberFormatter>
|
||||
{
|
||||
private static readonly CppWinRtMemberFormatter CppWinRtMemberFormatter = new CppWinRtMemberFormatter();
|
||||
protected override CppWinRtMemberFormatter formatter => CppWinRtMemberFormatter;
|
||||
|
||||
private string _cppCxTestLibName = "../../../../external/Test/UwpTestWinRtComponentCpp.winmd";
|
||||
private const string CSharpTestLib = "../../../../external/Test/CSharpExample.dll";
|
||||
|
||||
protected override TypeDefinition GetType(Type type)
|
||||
{
|
||||
var moduleName = type.Module.FullyQualifiedName;
|
||||
|
||||
var tref = GetType(moduleName, type.FullName?.Replace("+", "/"));
|
||||
return tref;
|
||||
}
|
||||
|
||||
[Test]
|
||||
[Category("Type")]
|
||||
public void TypeSignature_enum()
|
||||
{
|
||||
TestTypeSignature(_cppCxTestLibName, "UwpTestWinRtComponentCpp.Color1", "enum Color1");
|
||||
}
|
||||
|
||||
[Test]
|
||||
[Category("Type")]
|
||||
public void TypeSignature_publicSealedClass_Class1()
|
||||
{
|
||||
TestTypeSignature(_cppCxTestLibName, "UwpTestWinRtComponentCpp.Class1",
|
||||
"class Class1 sealed");
|
||||
}
|
||||
|
||||
[Test]
|
||||
[Category("Type")]
|
||||
public void TypeSignature_publicUnsealedClass_Class2()
|
||||
{
|
||||
TestTypeSignature(_cppCxTestLibName, "Namespace2.Class2", @"class Class2 : winrt::Windows::UI::Xaml::Application");
|
||||
}
|
||||
|
||||
[Test]
|
||||
[Category("Type")]
|
||||
public void TypeSignature_Struct_Class4()
|
||||
{
|
||||
TestTypeSignature(_cppCxTestLibName, "Namespace2.Class4", "struct Class4");
|
||||
}
|
||||
|
||||
[Test]
|
||||
[Category("Type")]
|
||||
public void TypeSignature_GenericInterface()
|
||||
{
|
||||
TestTypeSignature(typeof(IFoo<>), @"template <typename T>
|
||||
__interface IFoo");
|
||||
}
|
||||
|
||||
[Test]
|
||||
[Category("Type")]
|
||||
public void TypeSignature_GenericClass()
|
||||
{
|
||||
TestTypeSignature(typeof(MyList<>.Helper<,>), @"template <typename U, typename V>
|
||||
[Windows::Foundation::Metadata::WebHostHidden]
|
||||
class MyList<T>::Helper");
|
||||
}
|
||||
|
||||
[Test]
|
||||
[Category("Type")]
|
||||
public void TypeSignature_NestedClass()
|
||||
{
|
||||
TestTypeSignature(typeof(Widget.NestedClass.Double), @"[Windows::Foundation::Metadata::WebHostHidden]
|
||||
class Widget::NestedClass::Double");
|
||||
}
|
||||
|
||||
[Test]
|
||||
[Category("Type")]
|
||||
public void TypeSignature_WebHostHiddenAttribute()
|
||||
{
|
||||
TestTypeSignature(typeof(Widget), @"[Windows::Foundation::Metadata::WebHostHidden]
|
||||
class Widget : Mono_DocTest::IProcess");
|
||||
}
|
||||
|
||||
[Test]
|
||||
[Category("NoSupport")]
|
||||
public void NoSupport_Delegate()
|
||||
{
|
||||
TestTypeSignature(_cppCxTestLibName, "UwpTestWinRtComponentCpp.PrimeFoundHandlerWithSpecificType", null);
|
||||
}
|
||||
|
||||
[Test]
|
||||
[Category("NoSupport")]
|
||||
public void NoSupport_DelegateWithCustomType()
|
||||
{
|
||||
TestTypeSignature(_cppCxTestLibName, "UwpTestWinRtComponentCpp.SomethingHappenedEventHandler",
|
||||
null);
|
||||
}
|
||||
|
||||
[Test]
|
||||
[Category("NoSupport")]
|
||||
public void NoSupport_CustomAttribute()
|
||||
{
|
||||
TestTypeSignature(_cppCxTestLibName, "UwpTestWinRtComponentCpp.CustomAttribute1", null);
|
||||
}
|
||||
|
||||
[Test]
|
||||
[Category("NoSupport")]
|
||||
public void NoSupport_CustomException()
|
||||
{
|
||||
TestTypeSignature(typeof(CustomException), null);
|
||||
}
|
||||
|
||||
[Test]
|
||||
[Category("NoSupport")]
|
||||
public void NoSupport_Exception_ArgumentNullExceptionField()
|
||||
{
|
||||
TestFieldSignature(typeof(CustomException), null, "ArgumentNullExceptionField");
|
||||
}
|
||||
|
||||
[Test]
|
||||
[Category("NoSupport")]
|
||||
public void NoSupport_Exception_InterfaceWithGenericConstraints()
|
||||
{
|
||||
TestTypeSignature(typeof(IFooNew<>), null);
|
||||
}
|
||||
|
||||
[Test]
|
||||
[Category("NoSupport")]
|
||||
public void NoSupport_Exception_ClassWithGenericConstraints()
|
||||
{
|
||||
TestTypeSignature(typeof(GenericConstraintClass<>), null);
|
||||
}
|
||||
[Test]
|
||||
[Category("NoSupport")]
|
||||
public void NoSupport_Exception_NestedClassWithSameName()
|
||||
{
|
||||
TestTypeSignature(CSharpTestLib, "Mono.DocTest.Widget/NestedClass", null);
|
||||
}
|
||||
}
|
||||
}
|
||||
134
external/api-doc-tools/mdoc/mdoc.Test/CppWinRtMembersTests.cs
vendored
Normal file
134
external/api-doc-tools/mdoc/mdoc.Test/CppWinRtMembersTests.cs
vendored
Normal file
@@ -0,0 +1,134 @@
|
||||
using Mono.Documentation.Updater.CppFormatters;
|
||||
using Mono_DocTest;
|
||||
using NUnit.Framework;
|
||||
using Cpp = Mono_DocTest_Generic;
|
||||
|
||||
namespace mdoc.Test
|
||||
{
|
||||
[TestFixture]
|
||||
public class CppWinRtMembersTests: BasicFormatterTests<CppWinRtFullMemberFormatter>
|
||||
{
|
||||
private static readonly CppWinRtFullMemberFormatter CppWinRtFullMemberFormatter = new CppWinRtFullMemberFormatter();
|
||||
protected override CppWinRtFullMemberFormatter formatter => CppWinRtFullMemberFormatter;
|
||||
|
||||
private string CppCxTestLibName = "../../../../external/Test/UwpTestWinRtComponentCpp.winmd";
|
||||
private const string CSharpTestLib = "../../../../external/Test/CSharpExample.dll";
|
||||
|
||||
[Test]
|
||||
[Category("Method")]
|
||||
public void Method_ComputeResult()
|
||||
{
|
||||
TestMethodSignature(CppCxTestLibName, "UwpTestWinRtComponentCpp.Class1", "ComputeResult",
|
||||
@"winrt::Windows::Foundation::Collections::IVector<double> ComputeResult(double input);");
|
||||
}
|
||||
|
||||
[Test]
|
||||
[Category("Method")]
|
||||
public void Method_GetPrimesOrdered()
|
||||
{
|
||||
TestMethodSignature(CppCxTestLibName, "UwpTestWinRtComponentCpp.Class1", "GetPrimesOrdered",
|
||||
@"winrt::Windows::Foundation::IAsyncOperationWithProgress<Windows::Foundation::Collections::IVector<int>, double> GetPrimesOrdered(int first, int last);");
|
||||
|
||||
}
|
||||
|
||||
[Test]
|
||||
[Category("Method")]
|
||||
public void Method_GetPrimesUnordered()
|
||||
{
|
||||
TestMethodSignature(CppCxTestLibName, "UwpTestWinRtComponentCpp.Class1", "GetPrimesUnordered",
|
||||
@"winrt::Windows::Foundation::IAsyncActionWithProgress<double> GetPrimesUnordered(int first, int last);");
|
||||
}
|
||||
|
||||
[Test]
|
||||
[Category("Method")]
|
||||
public void Method_DefaultParameters()
|
||||
{
|
||||
TestMethodSignature(CSharpTestLib, "Mono.DocTest.Widget", "Default",
|
||||
@"void Default(int a = 1, int b = 2);");
|
||||
}
|
||||
|
||||
[Test]
|
||||
[Category("Method")]
|
||||
public void Method_RefType()
|
||||
{
|
||||
TestMethodSignature(CppCxTestLibName, "Namespace222.App", "SetWindow1",
|
||||
@"void SetWindow1(winrt::Windows::UI::Core::CoreWindow const & window);");
|
||||
}
|
||||
|
||||
[Test]
|
||||
[Category("Method")]
|
||||
public void Method_WinRtTypeInterfaceImplementation()
|
||||
{
|
||||
TestMethodSignature(CppCxTestLibName, "Namespace222.App", "SetWindow",
|
||||
@"void SetWindow(winrt::Windows::UI::Core::CoreWindow const & window);");
|
||||
}
|
||||
|
||||
[Test]
|
||||
[Category("Fields")]
|
||||
public void FieldSignature_ConstLong() =>
|
||||
TestFieldSignature(typeof(Cpp.GenericBase<>),
|
||||
"const long ConstLong;",
|
||||
nameof(Cpp.GenericBase<int>.ConstLong));
|
||||
|
||||
[Test]
|
||||
[Category("Fields")]
|
||||
public void FieldSignature_ConstChar() =>
|
||||
TestFieldSignature(typeof(Cpp.GenericBase<>),
|
||||
"const char ConstChar;",
|
||||
nameof(Cpp.GenericBase<int>.ConstChar));
|
||||
|
||||
|
||||
|
||||
#region NoSupport
|
||||
[Test]
|
||||
[Category("NoSupport")]
|
||||
public void NoSupport_Property()
|
||||
{
|
||||
TestPropertySignature(CppCxTestLibName, "Namespace2.Class3", "LongProperty", null);
|
||||
}
|
||||
|
||||
[Test]
|
||||
[Category("NoSupport")]
|
||||
public void NoSupport_Event()
|
||||
{
|
||||
TestEventSignature(CppCxTestLibName, "UwpTestWinRtComponentCpp.Class1", "primeFoundEvent", null);
|
||||
}
|
||||
|
||||
[Test]
|
||||
[Category("NoSupport")]
|
||||
public void NoSupport_ExtensionMethod()
|
||||
{
|
||||
TestMethodSignature(typeof(Cpp.Extensions), null, nameof(Cpp.Extensions.Bar));
|
||||
}
|
||||
|
||||
[Test]
|
||||
[Category("NoSupport")]
|
||||
public void NoSupport_SystemTypes()
|
||||
{
|
||||
TestMethodSignature(typeof(Cpp.Extensions), null, nameof(Cpp.Extensions.Bar));
|
||||
}
|
||||
|
||||
|
||||
[Test]
|
||||
[Category("NoSupport")]
|
||||
public void MethodSignature_ParamsKeyword_M6()
|
||||
{
|
||||
TestMethodSignature(typeof(Widget), null, "M6");
|
||||
}
|
||||
|
||||
[Test]
|
||||
[Category("NoSupport")]
|
||||
public void NoSupport_StandardType()
|
||||
{
|
||||
TestMethodSignature(typeof(UseLists), null, nameof(UseLists.Process));
|
||||
}
|
||||
|
||||
[Test]
|
||||
[Category("Fields")]
|
||||
public void NoSupport_Decimal() =>
|
||||
TestFieldSignature(typeof(Cpp.GenericBase<>),
|
||||
null,
|
||||
nameof(Cpp.GenericBase<int>.ConstDecimal));
|
||||
#endregion
|
||||
}
|
||||
}
|
||||
44
external/api-doc-tools/mdoc/mdoc.Test/DocUtilsFSharpTests.cs
vendored
Normal file
44
external/api-doc-tools/mdoc/mdoc.Test/DocUtilsFSharpTests.cs
vendored
Normal file
@@ -0,0 +1,44 @@
|
||||
using Mono.Documentation.Updater;
|
||||
using NUnit.Framework;
|
||||
|
||||
namespace mdoc.Test
|
||||
{
|
||||
[TestFixture]
|
||||
public class DocUtilsFSharpTests : BasicFSharpFormatterTests<FSharpFormatter>
|
||||
{
|
||||
protected override FSharpFormatter formatter { get; }
|
||||
|
||||
[Test]
|
||||
public void IsIgnored_GetMethodIsGeneratedByProperty_IsIgnoredTrue()
|
||||
{
|
||||
var method = GetMethod(typeof(DiscriminatedUnions.Shape.Circle),
|
||||
"get_" + nameof(DiscriminatedUnions.Shape.Circle.radius));
|
||||
|
||||
var isIgnoredPropertyGeneratedMethod = DocUtils.IsIgnored(method);
|
||||
|
||||
Assert.IsTrue(isIgnoredPropertyGeneratedMethod);
|
||||
}
|
||||
|
||||
[Test]
|
||||
public void IsIgnored_GetMethodIsGeneratedByProperty2_IsIgnoredTrue()
|
||||
{
|
||||
var method = GetMethod(typeof(DiscriminatedUnions.SizeUnion),
|
||||
"get_" + nameof(DiscriminatedUnions.SizeUnion.Large));
|
||||
|
||||
var isIgnoredPropertyGeneratedMethod = DocUtils.IsIgnored(method);
|
||||
|
||||
Assert.IsTrue(isIgnoredPropertyGeneratedMethod);
|
||||
}
|
||||
|
||||
[Test]
|
||||
public void IsIgnored_GetMethodIsNotGeneratedByProperty_IsIgnoredFalse()
|
||||
{
|
||||
var method = GetMethod(typeof(Functions),
|
||||
nameof(Functions.get_function));
|
||||
|
||||
var isIgnoredPropertyGeneratedMethod = DocUtils.IsIgnored(method);
|
||||
|
||||
Assert.IsFalse(isIgnoredPropertyGeneratedMethod);
|
||||
}
|
||||
}
|
||||
}
|
||||
50
external/api-doc-tools/mdoc/mdoc.Test/DocUtilsTests.cs
vendored
Normal file
50
external/api-doc-tools/mdoc/mdoc.Test/DocUtilsTests.cs
vendored
Normal file
@@ -0,0 +1,50 @@
|
||||
using mdoc.Test.SampleClasses;
|
||||
using Mono.Documentation.Updater;
|
||||
using NUnit.Framework;
|
||||
|
||||
namespace mdoc.Test
|
||||
{
|
||||
[TestFixture]
|
||||
public class DocUtilsTests : BasicTests
|
||||
{
|
||||
[Test]
|
||||
public void IsIgnored_MethodGeneratedByProperty_IsIgnoredTrue()
|
||||
{
|
||||
var method = GetMethod(typeof(SomeClass), "get_" + nameof(SomeClass.Property));
|
||||
|
||||
var isIgnoredPropertyGeneratedMethod = DocUtils.IsIgnored(method);
|
||||
|
||||
Assert.True(isIgnoredPropertyGeneratedMethod);
|
||||
}
|
||||
|
||||
[Test]
|
||||
public void IsIgnored_GetMethodIsNotGeneratedByProperty_IsIgnoredFalse()
|
||||
{
|
||||
var method = GetMethod(typeof(SomeClass), nameof(SomeClass.get_Method));
|
||||
|
||||
var isIgnoredPropertyGeneratedMethod = DocUtils.IsIgnored(method);
|
||||
|
||||
Assert.False(isIgnoredPropertyGeneratedMethod);
|
||||
}
|
||||
|
||||
[Test]
|
||||
public void IsIgnored_GetMethodInIterfaceIsGeneratedByProperty_IsIgnoredTrue()
|
||||
{
|
||||
var method = GetMethod(typeof(SomeInterface), "get_B");
|
||||
|
||||
var isIgnoredPropertyGeneratedMethod = DocUtils.IsIgnored(method);
|
||||
|
||||
Assert.IsTrue(isIgnoredPropertyGeneratedMethod);
|
||||
}
|
||||
|
||||
[Test]
|
||||
public void IsIgnored_SetMethodIsGeneratedByProperty_IsIgnoredTrue()
|
||||
{
|
||||
var method = GetMethod(typeof(SomeClass), "set_" +nameof(SomeClass.Property4));
|
||||
|
||||
var isIgnoredPropertyGeneratedMethod = DocUtils.IsIgnored(method);
|
||||
|
||||
Assert.IsTrue(isIgnoredPropertyGeneratedMethod);
|
||||
}
|
||||
}
|
||||
}
|
||||
95
external/api-doc-tools/mdoc/mdoc.Test/Enumeration/AttachedEntityTests.cs
vendored
Normal file
95
external/api-doc-tools/mdoc/mdoc.Test/Enumeration/AttachedEntityTests.cs
vendored
Normal file
@@ -0,0 +1,95 @@
|
||||
using NUnit.Framework;
|
||||
using System;
|
||||
using System.Collections.Generic;
|
||||
using System.Linq;
|
||||
using System.Text;
|
||||
using System.Threading.Tasks;
|
||||
using Mono.Documentation.Util;
|
||||
using Windows.UI.Xaml;
|
||||
using Mono.Documentation.Updater;
|
||||
|
||||
namespace mdoc.Test.Enumeration
|
||||
{
|
||||
[TestFixture]
|
||||
public class AttachedEntityTests : CecilBaseTest
|
||||
{
|
||||
[TestCase]
|
||||
public void Test_NoEntities()
|
||||
{
|
||||
var type = GetTypeDef<AttachedTestClassNoAttachedEntities>();
|
||||
var list = AttachedEntitiesHelper.GetAttachedEntities(type);
|
||||
|
||||
Assert.IsFalse(list.Any());
|
||||
}
|
||||
|
||||
[TestCase]
|
||||
public void Test_AttachedProperty()
|
||||
{
|
||||
var type = GetTypeDef<AttachedTestClass>();
|
||||
var list = AttachedEntitiesHelper.GetAttachedEntities(type);
|
||||
|
||||
Assert.AreEqual(3, list.Count());
|
||||
}
|
||||
|
||||
[TestCase]
|
||||
public void Test_AttachedProperty_Formatter()
|
||||
{
|
||||
string expected = "see GetSome, and SetSome";
|
||||
|
||||
var type = GetTypeDef<AttachedTestClass>();
|
||||
var list = AttachedEntitiesHelper.GetAttachedEntities(type);
|
||||
|
||||
MemberFormatter formatter = new CSharpMemberFormatter();
|
||||
string def = formatter.GetDeclaration(list.First());
|
||||
Assert.AreEqual(expected, def);
|
||||
}
|
||||
|
||||
[TestCase]
|
||||
public void Test_AttachedProperty_Formatter_GetOnly()
|
||||
{
|
||||
string expected = "see GetSomeGet";
|
||||
|
||||
var type = GetTypeDef<AttachedTestClass>();
|
||||
var list = AttachedEntitiesHelper.GetAttachedEntities(type);
|
||||
|
||||
MemberFormatter formatter = new CSharpMemberFormatter();
|
||||
string def = formatter.GetDeclaration(list.Skip(1).First());
|
||||
Assert.AreEqual(expected, def);
|
||||
}
|
||||
|
||||
[TestCase]
|
||||
public void Test_AttachedProperty_Formatter_SetOnly()
|
||||
{
|
||||
string expected = "see SetSomeSet";
|
||||
|
||||
var type = GetTypeDef<AttachedTestClass>();
|
||||
var list = AttachedEntitiesHelper.GetAttachedEntities(type);
|
||||
|
||||
MemberFormatter formatter = new CSharpMemberFormatter();
|
||||
string def = formatter.GetDeclaration(list.Skip(2).First());
|
||||
Assert.AreEqual(expected, def);
|
||||
}
|
||||
|
||||
public class AttachedTestClassNoAttachedEntities { }
|
||||
|
||||
public class AttachedTestClass
|
||||
{
|
||||
public static readonly DependencyProperty SomeProperty;
|
||||
public static bool GetSome(DependencyObject obj) { return false; }
|
||||
public static void SetSome(DependencyObject obj, bool val) { }
|
||||
|
||||
|
||||
public static readonly DependencyProperty SomeGetProperty;
|
||||
public static bool GetSomeGet(DependencyObject obj) { return false; }
|
||||
|
||||
|
||||
public static readonly DependencyProperty SomeSetProperty;
|
||||
public static void SetSomeSet(DependencyObject obj, bool val) { }
|
||||
|
||||
|
||||
public static DependencyProperty SomeNotReadonlyProperty;
|
||||
public static bool GetSomeNotReadOnly(DependencyObject obj) { return false; }
|
||||
public static void SetSomeNotReadOnly(DependencyObject obj, bool val) { }
|
||||
}
|
||||
}
|
||||
}
|
||||
30
external/api-doc-tools/mdoc/mdoc.Test/Enumeration/CecilBaseTest.cs
vendored
Normal file
30
external/api-doc-tools/mdoc/mdoc.Test/Enumeration/CecilBaseTest.cs
vendored
Normal file
@@ -0,0 +1,30 @@
|
||||
using System.Linq;
|
||||
using Mono.Cecil;
|
||||
using Mono.Cecil.Rocks;
|
||||
using Mono.Documentation;
|
||||
using Mono.Documentation.Updater.Frameworks;
|
||||
|
||||
namespace mdoc.Test
|
||||
{
|
||||
public abstract class CecilBaseTest
|
||||
{
|
||||
|
||||
protected TypeDefinition GetTypeDef<T> ()
|
||||
{
|
||||
var type = typeof(T);
|
||||
var path = type.Module.Assembly.Location;
|
||||
var assemblyResolver = new MDocResolver();
|
||||
var dependencyPath = System.IO.Path.Combine(System.IO.Path.GetDirectoryName(path), "..", "..", "..", "..", "external", "Windows");
|
||||
assemblyResolver.AddSearchDirectory(dependencyPath);
|
||||
var cachedResolver = new CachedResolver(assemblyResolver);
|
||||
if (!System.IO.Directory.Exists(dependencyPath))
|
||||
throw new System.Exception($"The path '{dependencyPath}' doesn't seem to exist ... did project files get moved around?");
|
||||
|
||||
var resolver = new MDocMetadataResolver(cachedResolver);
|
||||
var assembly = AssemblyDefinition.ReadAssembly(path, new ReaderParameters { AssemblyResolver = cachedResolver, MetadataResolver = resolver });
|
||||
|
||||
var typeref = assembly.MainModule.GetAllTypes ().FirstOrDefault (t => t.Name == type.Name);
|
||||
return typeref;
|
||||
}
|
||||
}
|
||||
}
|
||||
167
external/api-doc-tools/mdoc/mdoc.Test/Enumeration/EnumeratorTests.cs
vendored
Normal file
167
external/api-doc-tools/mdoc/mdoc.Test/Enumeration/EnumeratorTests.cs
vendored
Normal file
@@ -0,0 +1,167 @@
|
||||
using NUnit.Framework;
|
||||
using System;
|
||||
using System.Linq;
|
||||
using System.Xml;
|
||||
using Mono.Cecil;
|
||||
using Mono.Cecil.Rocks;
|
||||
using Mono.Documentation.Updater;
|
||||
using Mono.Documentation.Updater.Frameworks;
|
||||
|
||||
namespace mdoc.Test
|
||||
{
|
||||
/// <summary>
|
||||
/// This is for testing the DocumentationEnumerator
|
||||
/// </summary>
|
||||
[TestFixture ()]
|
||||
public class EnumeratorTests : CecilBaseTest
|
||||
{
|
||||
|
||||
|
||||
[Test]
|
||||
public void FindProperty_NonEII () => TestProperty ("AProperty");
|
||||
|
||||
[Test]
|
||||
public void FindProperty_EII1 () => TestProperty ("mdoc.Test.EnumeratorTests.IFace1.AProperty");
|
||||
|
||||
[Test]
|
||||
public void FindProperty_EII2 () => TestProperty ("mdoc.Test.EnumeratorTests.IFace2.AProperty");
|
||||
|
||||
[Test]
|
||||
public void FindProperty_NonExistent ()
|
||||
{
|
||||
string propertyName = "mdoc.Test.EnumeratorTests.IDontExist.AProperty";
|
||||
|
||||
TypeDefinition theclass = GetTypeDef<ConcreteClass> ();
|
||||
|
||||
var members = DocumentationEnumerator.GetReflectionMembers (theclass, propertyName, "Property").ToArray ();
|
||||
|
||||
|
||||
Assert.IsFalse (members.Any (), "Invalid Member Matched");
|
||||
}
|
||||
|
||||
[Test]
|
||||
public void GetMember () => TestPropertyMember ("AProperty", XML_PROPERTY);
|
||||
|
||||
[Test]
|
||||
public void GetMember_EII1 () => TestPropertyMember ("mdoc.Test.EnumeratorTests.IFace1.AProperty", XML_PROPERTY_IFACE1);
|
||||
|
||||
[Test]
|
||||
public void GetMember_EII2 () => TestPropertyMember ("mdoc.Test.EnumeratorTests.IFace2.AProperty", XML_PROPERTY_IFACE2);
|
||||
|
||||
[Test]
|
||||
public void GetMethod() => TestMethodMember("BeginRead", XML_METHOD_TESTMETHOD);
|
||||
|
||||
#region Test infrastructure
|
||||
|
||||
private void TestProperty (string propertyName)
|
||||
{
|
||||
TypeDefinition theclass = GetTypeDef<ConcreteClass> ();
|
||||
|
||||
var members = DocumentationEnumerator.GetReflectionMembers (theclass, propertyName, "Property").ToArray ();
|
||||
|
||||
Assert.IsTrue (members.Any (), "no members found");
|
||||
Assert.AreEqual (1, members.Count (), "Different # of members found");
|
||||
Assert.AreEqual (propertyName, members.Single ().Name);
|
||||
}
|
||||
|
||||
private void TestPropertyMember (string propertyName, string theXml)
|
||||
{
|
||||
TypeDefinition theclass = GetTypeDef<ConcreteClass> ();
|
||||
|
||||
XmlDocument document = new XmlDocument ();
|
||||
document.LoadXml (theXml);
|
||||
|
||||
var member = DocumentationEnumerator.GetMember (theclass, new DocumentationMember (document.FirstChild, FrameworkTypeEntry.Empty));
|
||||
|
||||
Assert.NotNull (member, "didn't find the node");
|
||||
Assert.AreEqual (propertyName, member.Name);
|
||||
}
|
||||
|
||||
private void TestMethodMember(string methodName, string theXml)
|
||||
{
|
||||
TypeDefinition theclass = GetTypeDef<ConcreteClass>();
|
||||
|
||||
XmlDocument document = new XmlDocument();
|
||||
document.LoadXml(theXml);
|
||||
|
||||
var member = DocumentationEnumerator.GetMember(theclass, new DocumentationMember(document.FirstChild, FrameworkTypeEntry.Empty));
|
||||
|
||||
Assert.NotNull(member, "didn't find the node");
|
||||
Assert.AreEqual(methodName, member.Name);
|
||||
}
|
||||
|
||||
#endregion
|
||||
|
||||
#region Test Types
|
||||
|
||||
public interface IFace1
|
||||
{
|
||||
string AProperty { get; set; }
|
||||
}
|
||||
|
||||
public interface IFace2
|
||||
{
|
||||
string AProperty { get; set; }
|
||||
}
|
||||
|
||||
public class ConcreteClass : IFace1, IFace2
|
||||
{
|
||||
public string AProperty { get; set; }
|
||||
string IFace1.AProperty { get; set; }
|
||||
string IFace2.AProperty { get; set; }
|
||||
public IAsyncResult BeginRead(byte[] buffer, int offset, int count, AsyncCallback asyncCallback, object asyncState) => null;
|
||||
}
|
||||
|
||||
#endregion
|
||||
|
||||
#region Test Data
|
||||
|
||||
private string XML_PROPERTY = @"<Member MemberName=""AProperty"">
|
||||
<MemberType>Property</MemberType>
|
||||
<Implements>
|
||||
<InterfaceMember>P:mdoc.Test.EnumeratorTests.IFace1.AProperty</InterfaceMember>
|
||||
<InterfaceMember>P:mdoc.Test.EnumeratorTests.IFace2.AProperty</InterfaceMember>
|
||||
</Implements>
|
||||
<ReturnValue>
|
||||
<ReturnType>System.String</ReturnType>
|
||||
</ReturnValue>
|
||||
</Member>";
|
||||
|
||||
private string XML_PROPERTY_IFACE1 = @"<Member MemberName=""mdoc.Test.EnumeratorTests.IFace1.AProperty"">
|
||||
<MemberType>Property</MemberType>
|
||||
<Implements>
|
||||
<InterfaceMember>P:mdoc.Test.EnumeratorTests.IFace1.AProperty</InterfaceMember>
|
||||
</Implements>
|
||||
<ReturnValue>
|
||||
<ReturnType>System.String</ReturnType>
|
||||
</ReturnValue>
|
||||
</Member>";
|
||||
|
||||
private string XML_PROPERTY_IFACE2 = @"<Member MemberName=""mdoc.Test.EnumeratorTests.IFace2.AProperty"">
|
||||
<MemberType>Property</MemberType>
|
||||
<Implements>
|
||||
<InterfaceMember>P:mdoc.Test.EnumeratorTests.IFace2.AProperty</InterfaceMember>
|
||||
</Implements>
|
||||
<ReturnValue>
|
||||
<ReturnType>System.String</ReturnType>
|
||||
</ReturnValue>
|
||||
</Member>";
|
||||
|
||||
private string XML_METHOD_TESTMETHOD = @"<Member MemberName=""BeginRead"">
|
||||
<MemberType>Method</MemberType>
|
||||
<ReturnValue>
|
||||
<ReturnType>System.IAsyncResult</ReturnType>
|
||||
</ReturnValue>
|
||||
<Parameters>
|
||||
<Parameter Name = ""buffer"" Type=""System.Byte[]"" Index=""0"" FrameworkAlternate=""netcore-1.0;netcore-1.1;netcore-2.0"" />
|
||||
<Parameter Name = ""array"" Type=""System.Byte[]"" Index=""0"" FrameworkAlternate=""netframework-4.5;netframework-4.5.1;netframework-4.5.2;netframework-4.6;netframework-4.6.1;netframework-4.6.2;netframework-4.7;netstandard-2.0"" />
|
||||
<Parameter Name = ""offset"" Type=""System.Int32"" Index=""1"" FrameworkAlternate=""netcore-2.0;netframework-4.5;netframework-4.5.1;netframework-4.5.2;netframework-4.6;netframework-4.6.1;netframework-4.6.2;netframework-4.7;netstandard-2.0"" />
|
||||
<Parameter Name = ""count"" Type=""System.Int32"" Index=""2"" FrameworkAlternate=""netcore-2.0;netframework-4.5;netframework-4.5.1;netframework-4.5.2;netframework-4.6;netframework-4.6.1;netframework-4.6.2;netframework-4.7;netstandard-2.0"" />
|
||||
<Parameter Name = ""asyncCallback"" Type=""System.AsyncCallback"" Index=""3"" FrameworkAlternate=""netcore-2.0;netframework-4.5;netframework-4.5.1;netframework-4.5.2;netframework-4.6;netframework-4.6.1;netframework-4.6.2;netframework-4.7;netstandard-2.0"" />
|
||||
<Parameter Name = ""asyncState"" Type=""System.Object"" Index=""4"" FrameworkAlternate=""netcore-2.0;netframework-4.5;netframework-4.5.1;netframework-4.5.2;netframework-4.6;netframework-4.6.1;netframework-4.6.2;netframework-4.7;netstandard-2.0"" />
|
||||
</Parameters>
|
||||
</Member>";
|
||||
|
||||
#endregion
|
||||
}
|
||||
}
|
||||
66
external/api-doc-tools/mdoc/mdoc.Test/Enumeration/ExceptionTests.cs
vendored
Normal file
66
external/api-doc-tools/mdoc/mdoc.Test/Enumeration/ExceptionTests.cs
vendored
Normal file
@@ -0,0 +1,66 @@
|
||||
using Mono.Documentation;
|
||||
using NUnit.Framework;
|
||||
using System;
|
||||
using System.Linq;
|
||||
|
||||
namespace mdoc.Test.Enumeration
|
||||
{
|
||||
[TestFixture ()]
|
||||
public class ExceptionTests : CecilBaseTest
|
||||
{
|
||||
[Test ()]
|
||||
public void TestExceptionEnumerations ()
|
||||
{
|
||||
var type = GetTypeDef<ExceptionTestClass> ();
|
||||
var member = type.Methods.Single (m => m.Name == "ThrowAnException");
|
||||
|
||||
var sources = new ExceptionLookup (ExceptionLocations.DependentAssemblies)[member];
|
||||
|
||||
Assert.IsNotNull (sources);
|
||||
Assert.AreEqual (1, sources.Count ());
|
||||
var source = sources.First ();
|
||||
Assert.AreEqual ("ThrowAnException", source.Sources.First ().Name);
|
||||
}
|
||||
|
||||
[Test ()]
|
||||
public void TestExceptionEnumerations_FromPrivateMethod ()
|
||||
{
|
||||
var type = GetTypeDef<ExceptionTestClass> ();
|
||||
var member = type.Methods.Single (m => m.Name == "ThrowFromPrivateMethod");
|
||||
|
||||
var sources = new ExceptionLookup (ExceptionLocations.DependentAssemblies)[member];
|
||||
|
||||
Assert.IsNotNull (sources);
|
||||
Assert.AreEqual (0, sources.Count ());
|
||||
}
|
||||
|
||||
[Test ()]
|
||||
public void TestExceptionEnumerations_FromPublicMethod ()
|
||||
{
|
||||
var type = GetTypeDef<ExceptionTestClass> ();
|
||||
var member = type.Methods.Single (m => m.Name == "ThrowFromPublicMethod");
|
||||
|
||||
var sources = new ExceptionLookup (ExceptionLocations.Assembly)[member];
|
||||
|
||||
Assert.IsNotNull (sources);
|
||||
Assert.AreEqual (1, sources.Count ());
|
||||
var source = sources.First ();
|
||||
Assert.AreEqual ("ThrowItPublic", source.Sources.First ().Name);
|
||||
}
|
||||
|
||||
public class ExceptionTestClass
|
||||
{
|
||||
public void ThrowAnException()
|
||||
{
|
||||
throw new NotImplementedException ();
|
||||
}
|
||||
|
||||
public void ThrowFromPrivateMethod () => ThrowItPrivate ();
|
||||
private void ThrowItPrivate () => throw new NotImplementedException ();
|
||||
|
||||
|
||||
public void ThrowFromPublicMethod () => ThrowItPublic ();
|
||||
public void ThrowItPublic () => throw new NotImplementedException ();
|
||||
}
|
||||
}
|
||||
}
|
||||
55
external/api-doc-tools/mdoc/mdoc.Test/Enumeration/InterfaceTests.cs
vendored
Normal file
55
external/api-doc-tools/mdoc/mdoc.Test/Enumeration/InterfaceTests.cs
vendored
Normal file
@@ -0,0 +1,55 @@
|
||||
using Mono.Documentation.Updater;
|
||||
using NUnit.Framework;
|
||||
using System;
|
||||
using System.Linq;
|
||||
|
||||
namespace mdoc.Test.Enumeration
|
||||
{
|
||||
[TestFixture ()]
|
||||
public class InterfaceTests : CecilBaseTest
|
||||
{
|
||||
|
||||
[Test ()]
|
||||
public void TestCase ()
|
||||
{
|
||||
var type = GetTypeDef<TestClassWithInterfaces> ();
|
||||
var ifaces = DocUtils.GetAllPublicInterfaces (type).ToArray ();
|
||||
|
||||
Assert.AreEqual (3, ifaces.Count ());
|
||||
Assert.AreEqual ("I2", ifaces[0].Name);
|
||||
Assert.AreEqual ("ICombined", ifaces[1].Name);
|
||||
Assert.AreEqual ("I1", ifaces[2].Name);
|
||||
}
|
||||
|
||||
[Test ()]
|
||||
public void TestCase_WithComplexCombinations ()
|
||||
{
|
||||
var type = GetTypeDef<TestClassWithAllInterfaces> ();
|
||||
var ifaces = DocUtils.GetAllPublicInterfaces (type).ToArray ();
|
||||
|
||||
Assert.AreEqual (4, ifaces.Count ());
|
||||
Assert.AreEqual ("ICombined2", ifaces[0].Name);
|
||||
Assert.AreEqual ("I1", ifaces[1].Name);
|
||||
Assert.AreEqual ("ICombined", ifaces[2].Name);
|
||||
Assert.AreEqual ("I2", ifaces[3].Name);
|
||||
}
|
||||
|
||||
[Test ()]
|
||||
public void TestCase_OnlyDirectlyImplemented ()
|
||||
{
|
||||
var type = GetTypeDef<TestClassWithInterfaces> ();
|
||||
var ifaces = DocUtils.GetUserImplementedInterfaces (type).ToArray ();
|
||||
|
||||
Assert.AreEqual (2, ifaces.Count ());
|
||||
Assert.AreEqual ("I2", ifaces[0].Name);
|
||||
Assert.AreEqual ("ICombined", ifaces[1].Name);
|
||||
}
|
||||
}
|
||||
|
||||
public interface I1 {}
|
||||
public interface I2 {}
|
||||
public interface ICombined : I1 {}
|
||||
public interface ICombined2 : I1, ICombined, I2 {}
|
||||
public interface TestClassWithInterfaces : I2, ICombined {}
|
||||
public interface TestClassWithAllInterfaces : ICombined2 {}
|
||||
}
|
||||
18
external/api-doc-tools/mdoc/mdoc.Test/FSharp/BasicFSharpFormatterTests.cs
vendored
Normal file
18
external/api-doc-tools/mdoc/mdoc.Test/FSharp/BasicFSharpFormatterTests.cs
vendored
Normal file
@@ -0,0 +1,18 @@
|
||||
using Mono.Cecil;
|
||||
using Mono.Documentation.Updater;
|
||||
using System;
|
||||
|
||||
namespace mdoc.Test
|
||||
{
|
||||
public abstract class BasicFSharpFormatterTests<T> : BasicFormatterTests<T> where T : MemberFormatter
|
||||
{
|
||||
protected override TypeDefinition GetType(Type type)
|
||||
{
|
||||
var moduleName = type.Module.FullyQualifiedName;
|
||||
|
||||
// Can't use base.GetType, F# assemblies use '/' instead of '+'
|
||||
var tref = GetType(moduleName, type.FullName.Replace("+", "/"));
|
||||
return tref;
|
||||
}
|
||||
}
|
||||
}
|
||||
940
external/api-doc-tools/mdoc/mdoc.Test/FSharp/FSharpFormatterTests.cs
vendored
Normal file
940
external/api-doc-tools/mdoc/mdoc.Test/FSharp/FSharpFormatterTests.cs
vendored
Normal file
File diff suppressed because it is too large
Load Diff
148
external/api-doc-tools/mdoc/mdoc.Test/FSharp/FSharpUsageFormatterTests.cs
vendored
Normal file
148
external/api-doc-tools/mdoc/mdoc.Test/FSharp/FSharpUsageFormatterTests.cs
vendored
Normal file
@@ -0,0 +1,148 @@
|
||||
using Microsoft.FSharp.Core;
|
||||
using Mono.Documentation.Updater;
|
||||
using NUnit.Framework;
|
||||
|
||||
namespace mdoc.Test
|
||||
{
|
||||
[TestFixture]
|
||||
[Category("FSharp")]
|
||||
public class FSharpUsageFormatterTests : BasicFSharpFormatterTests<FSharpUsageFormatter>
|
||||
{
|
||||
private static readonly FSharpUsageFormatter fSharpUsageFormatter = new FSharpUsageFormatter();
|
||||
protected override FSharpUsageFormatter formatter => fSharpUsageFormatter;
|
||||
|
||||
#region Usage
|
||||
[Test]
|
||||
[Category("Usage")]
|
||||
[Category("Properties")]
|
||||
public void PropertyUsage_0() =>
|
||||
TestPropertySignature(typeof(Properties.MyPropertyClass2),
|
||||
@"Properties.MyPropertyClass2.Property1",
|
||||
nameof(Properties.MyPropertyClass2.Property1));
|
||||
|
||||
[Test]
|
||||
[Category("Usage")]
|
||||
[Category("Properties")]
|
||||
[Category("DiscriminatedUnions")]
|
||||
public void PropertyUsage_1() =>
|
||||
TestPropertySignature(
|
||||
typeof(DiscriminatedUnions.SizeUnion),
|
||||
"DiscriminatedUnions.SizeUnion.Small",
|
||||
nameof(DiscriminatedUnions.SizeUnion.Small));
|
||||
|
||||
[Test]
|
||||
[Category("Usage")]
|
||||
[Category("Methods")]
|
||||
public void MethodUsage_0() =>
|
||||
TestMethodSignature(typeof(Methods.SomeType),
|
||||
@"someType.SomeMethod (a, b, c)",
|
||||
nameof(Methods.SomeType.SomeMethod));
|
||||
|
||||
[Test]
|
||||
[Category("Usage")]
|
||||
[Category("Methods")]
|
||||
public void MethodUsage_1() =>
|
||||
TestMethodSignature(typeof(Methods.SomeType),
|
||||
@"Methods.SomeType.SomeStaticMethod (a, b, c)",
|
||||
nameof(Methods.SomeType.SomeStaticMethod));
|
||||
|
||||
|
||||
[Test]
|
||||
[Category("Usage")]
|
||||
[Category("Methods")]
|
||||
public void MethodUsage_2() =>
|
||||
TestMethodSignature(typeof(Methods.SomeType),
|
||||
@"Methods.SomeType.SomeOtherStaticMethod2 a b c",
|
||||
nameof(Methods.SomeType.SomeOtherStaticMethod2));
|
||||
|
||||
[Test]
|
||||
[Category("Usage")]
|
||||
[Category("Methods")]
|
||||
public void MethodUsage_3() =>
|
||||
TestMethodSignature(typeof(Methods.SomeType),
|
||||
@"Methods.SomeType.SomeOtherStaticMethod3 (a, b) c d",
|
||||
nameof(Methods.SomeType.SomeOtherStaticMethod3));
|
||||
|
||||
[Test]
|
||||
[Category("Usage")]
|
||||
[Category("Operators")]
|
||||
public void MethodUsage_4() =>
|
||||
TestMethodSignature(typeof(OperatorsOverloading.Vector),
|
||||
"v * a",
|
||||
"op_Multiply");
|
||||
|
||||
[Test]
|
||||
[Category("Usage")]
|
||||
[Category("Operators")]
|
||||
public void MethodUsage_5() =>
|
||||
TestMethodSignature(typeof(OperatorsOverloading.Vector),
|
||||
"- v",
|
||||
"op_UnaryNegation");
|
||||
|
||||
[Test]
|
||||
[Category("Usage")]
|
||||
[Category("Operators")]
|
||||
public void MethodUsage_6() =>
|
||||
TestMethodSignature(typeof(OperatorsOverloading.Vector),
|
||||
"~~~ v",
|
||||
"op_LogicalNot");
|
||||
|
||||
[Test]
|
||||
[Category("Usage")]
|
||||
[Category("Operators")]
|
||||
public void MethodUsage_7() =>
|
||||
TestMethodSignature(typeof(OperatorsOverloading.Vector),
|
||||
"start .. finish",
|
||||
"op_Range");
|
||||
|
||||
[Test]
|
||||
[Category("Usage")]
|
||||
[Category("Operators")]
|
||||
public void MethodUsage_8() =>
|
||||
TestMethodSignature(typeof(OperatorsOverloading.Vector),
|
||||
"start .. step .. finish",
|
||||
"op_RangeStep");
|
||||
|
||||
[Test]
|
||||
[Category("Usage")]
|
||||
[Category("Operators")]
|
||||
public void MethodUsage_9() =>
|
||||
TestMethodSignature(typeof(OperatorsOverloading.Vector),
|
||||
"a |+-+ v",
|
||||
"op_BarPlusMinusPlus");
|
||||
|
||||
[Test]
|
||||
[Category("Usage")]
|
||||
[Category("Operators")]
|
||||
public void MethodUsage_10() =>
|
||||
TestMethodSignature(typeof(Operators),
|
||||
"(arg1, arg2, arg3) |||> func",
|
||||
"op_PipeRight3");
|
||||
|
||||
[Test]
|
||||
[Category("Usage")]
|
||||
[Category("Operators")]
|
||||
public void MethodUsage_11() =>
|
||||
TestMethodSignature(typeof(Operators),
|
||||
"func <||| (arg1, arg2, arg3)",
|
||||
"op_PipeLeft3");
|
||||
|
||||
[Test]
|
||||
[Category("Usage")]
|
||||
[Category("Methods")]
|
||||
public void MethodUsage_12() =>
|
||||
TestMethodSignature(typeof(PatternMatching.PatternMatchingExamples),
|
||||
"PatternMatching.PatternMatchingExamples.countValues list value",
|
||||
"countValues");
|
||||
|
||||
[Test]
|
||||
[Category("Usage")]
|
||||
[Category("Operators")]
|
||||
public void ConstructorUsage_0() =>
|
||||
TestMethodSignature(typeof(AbstractClasses.Circle),
|
||||
"new AbstractClasses.Circle (x, y, radius)",
|
||||
".ctor");
|
||||
#endregion
|
||||
|
||||
}
|
||||
}
|
||||
276
external/api-doc-tools/mdoc/mdoc.Test/FormatterTests.cs
vendored
Normal file
276
external/api-doc-tools/mdoc/mdoc.Test/FormatterTests.cs
vendored
Normal file
@@ -0,0 +1,276 @@
|
||||
using NUnit.Framework;
|
||||
using System.Linq;
|
||||
using mdoc.Test.SampleClasses;
|
||||
using Mono.Documentation.Updater;
|
||||
|
||||
namespace mdoc.Test
|
||||
{
|
||||
[TestFixture ()]
|
||||
public class FormatterTests : BasicFormatterTests<CSharpMemberFormatter>
|
||||
{
|
||||
private CSharpMemberFormatter csharpMemberFormatter = new CSharpMemberFormatter();
|
||||
protected override CSharpMemberFormatter formatter => csharpMemberFormatter;
|
||||
|
||||
[Test ()]
|
||||
public void Formatters_VerifyPrivateConstructorNull ()
|
||||
{
|
||||
// this is a private constructor
|
||||
var method = GetMethod (typeof(TestClass), m => m.IsConstructor && !m.IsPublic && m.Parameters.Count () == 1);
|
||||
|
||||
MemberFormatter[] formatters = new MemberFormatter[]
|
||||
{
|
||||
new CSharpFullMemberFormatter (),
|
||||
new CSharpMemberFormatter(),
|
||||
new ILMemberFormatter(),
|
||||
new ILFullMemberFormatter(),
|
||||
new VBFullMemberFormatter (),
|
||||
new VBMemberFormatter(),
|
||||
new FSharpMemberFormatter(),
|
||||
new FSharpFullMemberFormatter(),
|
||||
};
|
||||
var sigs = formatters.Select (f => f.GetDeclaration (method));
|
||||
|
||||
foreach (var sig in sigs)
|
||||
Assert.IsNull (sig);
|
||||
}
|
||||
|
||||
[Test]
|
||||
public void CSharp_op_Addition () =>
|
||||
TestBinaryOp ("Addition", "+");
|
||||
|
||||
[Test]
|
||||
public void CSharp_op_Subtraction () =>
|
||||
TestBinaryOp ("Subtraction", "-");
|
||||
|
||||
[Test]
|
||||
public void CSharp_op_Division () =>
|
||||
TestBinaryOp ("Division", "/");
|
||||
|
||||
[Test]
|
||||
public void CSharp_op_Multiplication () =>
|
||||
TestBinaryOp ("Multiply", "*");
|
||||
|
||||
[Test]
|
||||
public void CSharp_op_Modulus () =>
|
||||
TestBinaryOp ("Modulus", "%");
|
||||
|
||||
[Test]
|
||||
public void CSharp_op_BitwiseAnd () =>
|
||||
TestBinaryOp ("BitwiseAnd", "&");
|
||||
|
||||
[Test]
|
||||
public void CSharp_op_BitwiseOr () =>
|
||||
TestBinaryOp ("BitwiseOr", "|");
|
||||
|
||||
[Test]
|
||||
public void CSharp_op_ExclusiveOr () =>
|
||||
TestBinaryOp ("ExclusiveOr", "^");
|
||||
|
||||
[Test]
|
||||
public void CSharp_op_LeftShift () =>
|
||||
TestBinaryOp ("LeftShift", "<<", secondType: "int");
|
||||
|
||||
[Test]
|
||||
public void CSharp_op_RightShift () =>
|
||||
TestBinaryOp ("RightShift", ">>", secondType: "int");
|
||||
|
||||
[Test]
|
||||
public void CSharp_op_UnaryPlus () =>
|
||||
TestUnaryOp ("UnaryPlus", "+");
|
||||
|
||||
[Test]
|
||||
public void CSharp_op_UnaryNegation () =>
|
||||
TestUnaryOp ("UnaryNegation", "-");
|
||||
|
||||
[Test]
|
||||
public void CSharp_op_LogicalNot () =>
|
||||
TestUnaryOp ("LogicalNot", "!");
|
||||
|
||||
[Test]
|
||||
public void CSharp_op_OnesComplement () =>
|
||||
TestUnaryOp ("OnesComplement", "~");
|
||||
|
||||
[Test]
|
||||
public void CSharp_op_Decrement () =>
|
||||
TestUnaryOp ("Decrement", "--");
|
||||
|
||||
[Test]
|
||||
public void CSharp_op_Increment () =>
|
||||
TestUnaryOp ("Increment", "++");
|
||||
|
||||
[Test]
|
||||
public void CSharp_op_True () =>
|
||||
TestUnaryOp ("True", "true", returnType: "bool");
|
||||
|
||||
[Test]
|
||||
public void CSharp_op_False () =>
|
||||
TestUnaryOp ("False", "false", returnType: "bool");
|
||||
|
||||
[Test]
|
||||
public void CSharp_op_Equality () =>
|
||||
TestComparisonOp ("Equality", "==");
|
||||
|
||||
[Test]
|
||||
public void CSharp_op_Inequality () =>
|
||||
TestComparisonOp ("Inequality", "!=");
|
||||
|
||||
[Test]
|
||||
public void CSharp_op_LessThan () =>
|
||||
TestComparisonOp ("LessThan", "<");
|
||||
|
||||
[Test]
|
||||
public void CSharp_op_GreaterThan () =>
|
||||
TestComparisonOp ("GreaterThan", ">");
|
||||
|
||||
[Test]
|
||||
public void CSharp_op_LessThanOrEqual () =>
|
||||
TestComparisonOp ("LessThanOrEqual", "<=");
|
||||
|
||||
[Test]
|
||||
public void CSharp_op_GreaterThanOrEqual () =>
|
||||
TestComparisonOp ("GreaterThanOrEqual", ">=");
|
||||
|
||||
[Test]
|
||||
public void CSharp_op_Implicit () =>
|
||||
TestConversionOp ("Implicit", "implicit", "TestClass", "TestClassTwo");
|
||||
|
||||
[Test]
|
||||
public void CSharp_op_Implicit_inverse () =>
|
||||
TestConversionOp ("Implicit", "implicit", "TestClassTwo", "TestClass");
|
||||
|
||||
[Test]
|
||||
public void CSharp_op_Explicit () =>
|
||||
TestConversionOp ("Explicit", "explicit", "int", "TestClass");
|
||||
|
||||
[Test]
|
||||
public void CSharp_op_Explicit_inverse () =>
|
||||
TestConversionOp ("Explicit", "explicit", "TestClass", "int");
|
||||
|
||||
[Test]
|
||||
public void CSharp_modopt () =>
|
||||
TestMod ("SomeFunc2", "public SomeClass* SomeFunc2 (SomeClass param);", returnType: "SomeClass*");
|
||||
|
||||
[Test]
|
||||
public void CSharp_modreq () =>
|
||||
TestMod ("SomeFunc", "public int SomeFunc (SomeClass* param);", returnType: "int");
|
||||
|
||||
[Test]
|
||||
public void CSharp_doublepointer () =>
|
||||
TestMod ("SomeFunc3", "public SomeClass** SomeFunc3 (int param);", returnType: "cppcli.SomeClass**");
|
||||
|
||||
[Test]
|
||||
public void CSharp_pointerref_modreqparam () =>
|
||||
TestMod ("SomeFunc4", "public int SomeFunc4 (SomeClass** param, int param2);", returnType: "int");
|
||||
|
||||
[Test]
|
||||
public void DoubleMod ()
|
||||
{
|
||||
string doubledUp = "System.ValueType modopt(System.DateTime) modopt(System.Runtime.CompilerServices.IsBoxed)";
|
||||
string result = MemberFormatter.RemoveMod (doubledUp);
|
||||
Assert.AreEqual ("System.ValueType", result);
|
||||
}
|
||||
|
||||
[Test]
|
||||
public void DoubleMod_Mixed ()
|
||||
{
|
||||
string doubledUp = "System.ValueType modreq(System.DateTime) modopt(System.Runtime.CompilerServices.IsBoxed)";
|
||||
string result = MemberFormatter.RemoveMod (doubledUp);
|
||||
Assert.AreEqual ("System.ValueType", result);
|
||||
}
|
||||
|
||||
[Test]
|
||||
public void DoubleMod_Pointer ()
|
||||
{
|
||||
string doubledUp = "System.ValueType modreq(System.DateTime) modopt(System.Runtime.CompilerServices.IsBoxed)*";
|
||||
string result = MemberFormatter.RemoveMod (doubledUp);
|
||||
Assert.AreEqual ("System.ValueType*", result);
|
||||
}
|
||||
|
||||
[Test]
|
||||
public void Params()
|
||||
{
|
||||
var member = GetMethod (typeof(TestClass), m => m.Name == "DoSomethingWithParams");
|
||||
var sig = formatter.GetDeclaration (member);
|
||||
Assert.AreEqual ("public void DoSomethingWithParams (params int[] values);", sig);
|
||||
}
|
||||
[Test]
|
||||
public void IL_RefAndOut ()
|
||||
{
|
||||
var member = GetMethod (typeof(TestClass), m => m.Name == "RefAndOut");
|
||||
var formatter = new ILFullMemberFormatter ();
|
||||
var sig = formatter.GetDeclaration (member);
|
||||
Assert.AreEqual (".method public hidebysig instance void RefAndOut(int32& a, [out] int32& b) cil managed", sig);
|
||||
}
|
||||
[Test]
|
||||
public void MethodSignature_Finalize() =>
|
||||
TestMethodSignature(typeof(SomeGenericClass<>),
|
||||
"~SomeGenericClass ();",
|
||||
"Finalize");
|
||||
|
||||
[Test]
|
||||
public void CSharpReadonlyRefReturn()
|
||||
{
|
||||
var member = GetMethod(typeof(ReadonlyRefClass), m => m.Name == "ReadonlyRef");
|
||||
var formatter = new CSharpFullMemberFormatter();
|
||||
var sig = formatter.GetDeclaration(member);
|
||||
Assert.AreEqual("public ref readonly int ReadonlyRef ();", sig);
|
||||
}
|
||||
|
||||
[Test]
|
||||
public void CSharpRefReturn()
|
||||
{
|
||||
var member = GetMethod(typeof(ReadonlyRefClass), m => m.Name == "Ref");
|
||||
var formatter = new CSharpFullMemberFormatter();
|
||||
var sig = formatter.GetDeclaration(member);
|
||||
Assert.AreEqual("public ref int Ref ();", sig);
|
||||
}
|
||||
|
||||
#region Helper Methods
|
||||
string RealTypeName(string name){
|
||||
switch (name) {
|
||||
case "bool": return "Boolean";
|
||||
case "int": return "Int32";
|
||||
default: return name;
|
||||
}
|
||||
}
|
||||
|
||||
void TestConversionOp (string name, string type, string leftType, string rightType) {
|
||||
TestOp (name, $"public static {type} operator {leftType} ({rightType} c1);", argCount: 1, returnType: leftType);
|
||||
}
|
||||
|
||||
void TestComparisonOp (string name, string op)
|
||||
{
|
||||
TestOp (name, $"public static bool operator {op} (TestClass c1, TestClass c2);", argCount: 2, returnType: "Boolean");
|
||||
}
|
||||
|
||||
void TestUnaryOp (string name, string op, string returnType = "TestClass")
|
||||
{
|
||||
TestOp (name, $"public static {returnType} operator {op} (TestClass c1);", argCount: 1, returnType: returnType);
|
||||
}
|
||||
|
||||
void TestBinaryOp (string name, string op, string returnType = "TestClass", string secondType = "TestClass")
|
||||
{
|
||||
TestOp (name, $"public static {returnType} operator {op} (TestClass c1, {secondType} c2);", argCount: 2, returnType: returnType);
|
||||
}
|
||||
|
||||
void TestOp (string name, string expectedSig, int argCount, string returnType = "TestClass")
|
||||
{
|
||||
var member = GetMethod (typeof(TestClass), m => m.Name == $"op_{name}" && m.Parameters.Count == argCount && m.ReturnType.Name == RealTypeName (returnType));
|
||||
var formatter = new CSharpMemberFormatter ();
|
||||
var sig = formatter.GetDeclaration (member);
|
||||
Assert.AreEqual (expectedSig, sig);
|
||||
}
|
||||
|
||||
void TestMod (string name, string expectedSig, int argCount = 1, string returnType = "SomeClass")
|
||||
{
|
||||
var member = GetMethod (
|
||||
GetType ("SampleClasses/cppcli.dll", "cppcli.SomeInterface"),
|
||||
m => m.Name == name
|
||||
);
|
||||
var formatter = new CSharpMemberFormatter ();
|
||||
var sig = formatter.GetDeclaration (member);
|
||||
Assert.AreEqual (expectedSig, sig);
|
||||
}
|
||||
#endregion
|
||||
}
|
||||
}
|
||||
Some files were not shown because too many files have changed in this diff Show More
Reference in New Issue
Block a user