Welcome to mirror list, hosted at ThFree Co, Russian Federation.

github.com/mono/api-doc-tools.git - Unnamed repository; edit this file 'description' to name the repository.
summaryrefslogtreecommitdiff
diff options
context:
space:
mode:
authorkatsiaryna_bialiatka <katsiaryna_bialiatka@epam.com>2017-12-22 19:15:31 +0300
committerJoel Martinez <joelmartinez@gmail.com>2018-01-12 01:11:42 +0300
commit6533035ec31f38543532568bc499aba2a98e1788 (patch)
treec9e7e3bdefd3299bfbf28dd5bd6b5bcc43fd988f /mdoc/mdoc.Test/BasicFormatterTests.cs
parent8ff2931c4e40e1c3687e8efa6fb4e8078b3a3c4b (diff)
[mdoc] Support for C++ signatures
Closes #132
Diffstat (limited to 'mdoc/mdoc.Test/BasicFormatterTests.cs')
-rw-r--r--mdoc/mdoc.Test/BasicFormatterTests.cs70
1 files changed, 64 insertions, 6 deletions
diff --git a/mdoc/mdoc.Test/BasicFormatterTests.cs b/mdoc/mdoc.Test/BasicFormatterTests.cs
index 3cb521e6..d6a2b442 100644
--- a/mdoc/mdoc.Test/BasicFormatterTests.cs
+++ b/mdoc/mdoc.Test/BasicFormatterTests.cs
@@ -1,4 +1,5 @@
using System;
+using System.Collections.Generic;
using System.Linq;
using Mono.Cecil;
using Mono.Documentation.Updater;
@@ -8,6 +9,9 @@ namespace mdoc.Test
{
public abstract class BasicFormatterTests<T> where T : MemberFormatter
{
+ protected Dictionary<string, ModuleDefinition> moduleCash = new Dictionary<string, ModuleDefinition>();
+ protected Dictionary<string, TypeDefinition> typesCash = new Dictionary<string, TypeDefinition>();
+
protected abstract T formatter { get; }
protected MethodDefinition GetMethod(Type type, Func<MethodDefinition, bool> query)
@@ -18,7 +22,7 @@ namespace mdoc.Test
protected MethodDefinition GetMethod(TypeDefinition testclass, Func<MethodDefinition, bool> query)
{
var methods = testclass.Methods;
- var member = methods.FirstOrDefault(query).Resolve();
+ var member = methods.FirstOrDefault(query)?.Resolve();
if (member == null)
throw new Exception("Did not find the member in the test class");
return member;
@@ -27,7 +31,7 @@ namespace mdoc.Test
protected MethodDefinition GetProperty(TypeDefinition testclass, Func<MethodDefinition, bool> query)
{
var methods = testclass.Methods;
- var member = methods.FirstOrDefault(query).Resolve();
+ var member = methods.FirstOrDefault(query)?.Resolve();
if (member == null)
throw new Exception("Did not find the member in the test class");
return member;
@@ -35,7 +39,17 @@ namespace mdoc.Test
protected TypeDefinition GetType(string filepath, string classname)
{
- var module = ModuleDefinition.ReadModule(filepath);
+ if (typesCash.ContainsKey(classname))
+ return typesCash[classname];
+
+
+ if (!moduleCash.ContainsKey(filepath))
+ {
+ var readModule = ModuleDefinition.ReadModule(filepath);
+ moduleCash.Add(filepath, readModule);
+ }
+
+ var module = moduleCash[filepath];
var types = module.GetTypes();
var testclass = types
.SingleOrDefault(t => t.FullName == classname);
@@ -43,7 +57,10 @@ namespace mdoc.Test
{
throw new Exception($"Test was unable to find type {classname}");
}
- return testclass.Resolve();
+
+ var typeDef = testclass.Resolve();
+ typesCash.Add(classname, typeDef);
+ return typeDef;
}
protected virtual TypeDefinition GetType(Type type)
@@ -54,7 +71,7 @@ namespace mdoc.Test
protected MemberReference GetProperty(TypeDefinition type, string memberName)
{
- var property = type.Properties.SingleOrDefault(i => i.Name == memberName);
+ var property = type.Properties.FirstOrDefault(i => i.Name == memberName);
if (property == null)
throw new Exception($"Can't find property {memberName}");
return property;
@@ -83,6 +100,14 @@ namespace mdoc.Test
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);
@@ -96,6 +121,14 @@ namespace mdoc.Test
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);
@@ -116,6 +149,14 @@ namespace mdoc.Test
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);
@@ -128,6 +169,14 @@ namespace mdoc.Test
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);
@@ -142,9 +191,18 @@ namespace mdoc.Test
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());
}
}
-} \ No newline at end of file
+
+}