diff options
author | Joel Martinez <joelmartinez@gmail.com> | 2019-11-22 01:08:44 +0300 |
---|---|---|
committer | Joel Martinez <joelmartinez@gmail.com> | 2019-11-22 01:08:44 +0300 |
commit | 4b4ea89adad89b0444dc22ffd33d57962b635838 (patch) | |
tree | d2ea5468e1e2e093fba5b4d67af090ac7d074632 /mdoc/mdoc.Test | |
parent | 135f70cce0f730e6ee8ee96f8e817142517d13df (diff) |
Adds support for TypeMap.xml ... TypeReplace nodes supported in formatters
Diffstat (limited to 'mdoc/mdoc.Test')
-rw-r--r-- | mdoc/mdoc.Test/Enumeration/CecilBaseTest.cs | 4 | ||||
-rw-r--r-- | mdoc/mdoc.Test/TypeMapTests.cs | 107 | ||||
-rw-r--r-- | mdoc/mdoc.Test/mdoc.Test.csproj | 1 |
3 files changed, 111 insertions, 1 deletions
diff --git a/mdoc/mdoc.Test/Enumeration/CecilBaseTest.cs b/mdoc/mdoc.Test/Enumeration/CecilBaseTest.cs index 8b0fd3ce..dc6145b1 100644 --- a/mdoc/mdoc.Test/Enumeration/CecilBaseTest.cs +++ b/mdoc/mdoc.Test/Enumeration/CecilBaseTest.cs @@ -14,7 +14,9 @@ namespace mdoc.Test 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"); + + var projPath = typeof(CecilBaseTest).Module.Assembly.Location; + var dependencyPath = System.IO.Path.Combine(System.IO.Path.GetDirectoryName(projPath), "..", "..", "..", "..", "external", "Windows"); assemblyResolver.AddSearchDirectory(dependencyPath); var cachedResolver = new CachedResolver(assemblyResolver); if (!System.IO.Directory.Exists(dependencyPath)) diff --git a/mdoc/mdoc.Test/TypeMapTests.cs b/mdoc/mdoc.Test/TypeMapTests.cs new file mode 100644 index 00000000..49ff5818 --- /dev/null +++ b/mdoc/mdoc.Test/TypeMapTests.cs @@ -0,0 +1,107 @@ +using Mono.Documentation.Updater; +using Mono.Cecil; +using NUnit.Framework; +using NUnit.Framework.Internal; +using System; +using System.Collections.Generic; +using System.Linq; +using System.Text; +using System.Threading.Tasks; +using System.Xml.Linq; +using Windows.Foundation; +using Mono.Documentation.Updater.Formatters.CppFormatters; + +namespace mdoc.Test +{ + [TestFixture] + public class TypeMapTests : CecilBaseTest + { + [Test] + public void LoadTypeMap() + { + var map = TypeMap.FromXDocument(XDocument.Parse(simpleSourceFile)); + + Assert.AreEqual(2, map.Items.Count); + + var item1 = map.Items.First(); + Assert.AreEqual("Windows.Foundation.IClosable", item1.From); + Assert.AreEqual("System.IDisposable", item1.To); + Assert.AreEqual("C#;VB.NET;F#", item1.Langs); + Assert.AreEqual(3, item1.LangList.Count()); + + var item2 = map.Items.Last(); + Assert.AreEqual("System.DateTime", item2.From); + Assert.AreEqual("System.DateTimeOffset", item2.To); + Assert.AreEqual("C#;F#", item2.Langs); + Assert.AreEqual(2, item2.LangList.Count()); + } + + [Test] + public void ReplaceType() + { + var map = TypeMap.FromXDocument(XDocument.Parse(simpleSourceFile)); + + var actualValue = map.GetTypeName("C#", "System.DateTime"); + Assert.AreEqual("System.DateTimeOffset", actualValue); + } + + [Test] + public void ReplaceInFormatter() + { + var typedef = GetTypeDef<UWPProjection>(); + + var map = TypeMap.FromXDocument(XDocument.Parse(simplerSourceFile)); + CSharpFullMemberFormatter formatter = new CSharpFullMemberFormatter(map); + + string actual = formatter.GetDeclaration(typedef); + string actualName = formatter.GetName(typedef); + + Assert.AreEqual("public class System.String", actual); + Assert.AreEqual("System.String", actualName); + } + + [Test] + public void ReplaceInFormatter_WrongLanguage() + { + var typedef = GetTypeDef<UWPProjection>(); + + var map = TypeMap.FromXDocument(XDocument.Parse(simplerSourceFile)); + CppCxFullMemberFormatter formatter = new CppCxFullMemberFormatter(map); + + string actual = formatter.GetDeclaration(typedef); + string actualName = formatter.GetName(typedef); + + Assert.AreEqual("mdoc::Test::TypeMapTests::UWPProjection", actualName); + } + + + string simpleSourceFile = @"<TypeMap> + <InterfaceReplace + From=""Windows.Foundation.IClosable"" + To=""System.IDisposable"" + Langs=""C#;VB.NET;F#""> + <Members> + <Member MemberName = ""Dispose"" > + <stuff /> + </Member> + </Members> + </InterfaceReplace> + <TypeReplace + From = ""System.DateTime"" + To= ""System.DateTimeOffset"" + Langs= ""C#;F#"" /> +</TypeMap> "; + + string simplerSourceFile = @"<TypeMap> + <TypeReplace + From = ""mdoc.Test.TypeMapTests.UWPProjection"" + To= ""System.String"" + Langs= ""C#;F#"" /> +</TypeMap> "; + + public class UWPProjection + { + public void Dispose(){} + } + } +}
\ No newline at end of file diff --git a/mdoc/mdoc.Test/mdoc.Test.csproj b/mdoc/mdoc.Test/mdoc.Test.csproj index f1ba924a..9347614f 100644 --- a/mdoc/mdoc.Test/mdoc.Test.csproj +++ b/mdoc/mdoc.Test/mdoc.Test.csproj @@ -92,6 +92,7 @@ <Compile Include="JsUsageFormatterTests.cs" />
<Compile Include="MDocFileSourceTests.cs" />
<Compile Include="MDocUpdaterTests.cs" />
+ <Compile Include="TypeMapTests.cs" />
<Compile Include="SampleClasses\ReadonlyRefClass.cs" />
<Compile Include="SampleClasses\ReadOnlySpan.cs" />
<Compile Include="SampleClasses\SomeDelegate.cs" />
|