Skip to content

Commit 3aec8b1

Browse files
authored
Merge develop to main (#728)
* Add unit test for test coverage (#722) * update * update * update * update * update * update * update * update * update * update * update * update * Constraints on parameter types allow ref struct (#727) * update * add unit test * update * update * update * update * update * update * update * update ut case * update * update * update * upgrade version
2 parents 0b6d923 + 085df17 commit 3aec8b1

26 files changed

+1223
-84
lines changed

external/Test/AllowsRefStructDemo.dll

4 KB
Binary file not shown.

mdoc/Consts.cs

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -3,7 +3,7 @@ namespace Mono.Documentation
33
{
44
public static class Consts
55
{
6-
public static string MonoVersion = "5.9.3.7";
6+
public static string MonoVersion = "5.9.4";
77
public const string DocId = "DocId";
88
public const string CppCli = "C++ CLI";
99
public const string CppCx = "C++ CX";

mdoc/Mono.Documentation/MDocUpdater.Member.cs

Lines changed: 3 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -44,6 +44,9 @@ internal static void MakeTypeParameterConstraints(XmlElement root, XmlElement e,
4444
AppendElementText(ce, "ParameterAttribute", "NotNullableValueTypeConstraint");
4545
if ((attrs & GenericParameterAttributes.ReferenceTypeConstraint) != 0)
4646
AppendElementText(ce, "ParameterAttribute", "ReferenceTypeConstraint");
47+
// Check for 'allows ref struct' constraint
48+
if ((attrs & (GenericParameterAttributes)0x0020) != 0) // Assuming 0x0020 is the flag for 'allows ref struct'
49+
AppendElementText(ce, "ParameterAttribute", "AllowByRefLike");
4750

4851
#if NEW_CECIL
4952
foreach (GenericParameterConstraint c in constraints)

mdoc/Mono.Documentation/Updater/Formatters/CSharpFullMemberFormatter.cs

Lines changed: 10 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -314,9 +314,10 @@ private StringBuilder AppendConstraints (StringBuilder buf, IList<GenericParamet
314314
bool isref = (attrs & GenericParameterAttributes.ReferenceTypeConstraint) != 0;
315315
bool isvt = (attrs & GenericParameterAttributes.NotNullableValueTypeConstraint) != 0;
316316
bool isnew = (attrs & GenericParameterAttributes.DefaultConstructorConstraint) != 0;
317+
bool isAllowsRefStruct = (attrs & (GenericParameterAttributes)0x0020) != 0; // Assuming 0x0020 is the flag for 'allows ref struct'
317318
bool comma = false;
318319

319-
if (!isref && !isvt && !isnew && constraints.Count == 0)
320+
if (!isref && !isvt && !isAllowsRefStruct && !isnew && constraints.Count == 0)
320321
continue;
321322
buf.Append (" where ").Append (genArg.Name).Append (" : ");
322323
if (isref)
@@ -350,6 +351,14 @@ private StringBuilder AppendConstraints (StringBuilder buf, IList<GenericParamet
350351
buf.Append (", ");
351352
buf.Append ("new()");
352353
}
354+
355+
// Handle 'allows ref struct' constraint
356+
if (isAllowsRefStruct)
357+
{
358+
if (comma || constraints.Count > 0 || isnew)
359+
buf.Append(", ");
360+
buf.Append("allows ref struct");
361+
}
353362
}
354363
return buf;
355364
}
Lines changed: 201 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,201 @@
1+
using Mono.Documentation;
2+
using NUnit.Framework;
3+
using System.Text;
4+
using System.Xml;
5+
6+
namespace mdoc.Test
7+
{
8+
[TestFixture]
9+
public class DelegatingXmlWriterTests
10+
{
11+
private StringBuilder output;
12+
private XmlWriter baseWriter;
13+
private DelegatingXmlWriter delegatingWriter;
14+
15+
[SetUp]
16+
public void SetUp()
17+
{
18+
output = new StringBuilder();
19+
XmlWriterSettings settings = new XmlWriterSettings
20+
{
21+
OmitXmlDeclaration = true,
22+
ConformanceLevel = ConformanceLevel.Fragment
23+
};
24+
baseWriter = XmlWriter.Create(output, settings);
25+
delegatingWriter = new DelegatingXmlWriter(baseWriter);
26+
}
27+
28+
[TearDown]
29+
public void TearDown()
30+
{
31+
delegatingWriter.Close();
32+
}
33+
34+
[Test]
35+
public void TestWriteStartElement()
36+
{
37+
delegatingWriter.WriteStartElement("prefix", "localName", "namespace");
38+
delegatingWriter.WriteEndElement();
39+
delegatingWriter.Flush();
40+
41+
Assert.AreEqual("<prefix:localName xmlns:prefix=\"namespace\" />", output.ToString());
42+
}
43+
44+
[Test]
45+
public void TestWriteString()
46+
{
47+
delegatingWriter.WriteStartElement("root");
48+
delegatingWriter.WriteString("content");
49+
delegatingWriter.WriteEndElement();
50+
delegatingWriter.Flush();
51+
52+
Assert.AreEqual("<root>content</root>", output.ToString());
53+
}
54+
55+
[Test]
56+
public void TestWriteFullEndElement()
57+
{
58+
delegatingWriter.WriteStartElement("root");
59+
delegatingWriter.WriteFullEndElement();
60+
delegatingWriter.Flush();
61+
62+
Assert.AreEqual("<root></root>", output.ToString());
63+
}
64+
65+
[Test]
66+
public void TestWriteCData()
67+
{
68+
delegatingWriter.WriteStartElement("root");
69+
delegatingWriter.WriteCData("cdata content");
70+
delegatingWriter.WriteEndElement();
71+
delegatingWriter.Flush();
72+
73+
Assert.AreEqual("<root><![CDATA[cdata content]]></root>", output.ToString());
74+
}
75+
76+
[Test]
77+
public void TestWriteComment()
78+
{
79+
delegatingWriter.WriteComment("comment");
80+
delegatingWriter.Flush();
81+
82+
Assert.AreEqual("<!--comment-->", output.ToString());
83+
}
84+
85+
[Test]
86+
public void TestWriteProcessingInstruction()
87+
{
88+
delegatingWriter.WriteProcessingInstruction("xml-stylesheet", "type=\"text/xsl\" href=\"style.xsl\"");
89+
delegatingWriter.Flush();
90+
91+
Assert.AreEqual("<?xml-stylesheet type=\"text/xsl\" href=\"style.xsl\"?>", output.ToString());
92+
}
93+
94+
[Test]
95+
public void TestWriteWhitespace()
96+
{
97+
delegatingWriter.WriteWhitespace(" ");
98+
delegatingWriter.Flush();
99+
100+
Assert.AreEqual(" ", output.ToString());
101+
}
102+
103+
[Test]
104+
public void TestWriteRaw()
105+
{
106+
delegatingWriter.WriteRaw("<raw>data</raw>");
107+
delegatingWriter.Flush();
108+
109+
Assert.AreEqual("<raw>data</raw>", output.ToString());
110+
}
111+
112+
[Test]
113+
public void TestWriteEntityRef()
114+
{
115+
delegatingWriter.WriteEntityRef("entity");
116+
delegatingWriter.Flush();
117+
118+
Assert.AreEqual("&entity;", output.ToString());
119+
}
120+
121+
[Test]
122+
public void TestWriteCharEntity()
123+
{
124+
delegatingWriter.WriteCharEntity('c');
125+
delegatingWriter.Flush();
126+
127+
Assert.AreEqual("&#x63;", output.ToString());
128+
}
129+
[Test]
130+
public void TestWriteBase64()
131+
{
132+
byte[] buffer = Encoding.UTF8.GetBytes("base64 content");
133+
delegatingWriter.WriteStartElement("root");
134+
delegatingWriter.WriteBase64(buffer, 0, buffer.Length);
135+
delegatingWriter.WriteEndElement();
136+
delegatingWriter.Flush();
137+
138+
Assert.AreEqual("<root>YmFzZTY0IGNvbnRlbnQ=</root>", output.ToString());
139+
}
140+
141+
[Test]
142+
public void TestWriteBinHex()
143+
{
144+
byte[] buffer = Encoding.UTF8.GetBytes("binhex content");
145+
delegatingWriter.WriteStartElement("root");
146+
delegatingWriter.WriteBinHex(buffer, 0, buffer.Length);
147+
delegatingWriter.WriteEndElement();
148+
delegatingWriter.Flush();
149+
150+
Assert.AreEqual("<root>62696E68657820636F6E74656E74</root>", output.ToString());
151+
}
152+
153+
[Test]
154+
public void TestWriteChars()
155+
{
156+
char[] buffer = "char content".ToCharArray();
157+
delegatingWriter.WriteStartElement("root");
158+
delegatingWriter.WriteChars(buffer, 0, buffer.Length);
159+
delegatingWriter.WriteEndElement();
160+
delegatingWriter.Flush();
161+
162+
Assert.AreEqual("<root>char content</root>", output.ToString());
163+
}
164+
165+
[Test]
166+
public void TestWriteStartAttribute()
167+
{
168+
delegatingWriter.WriteStartElement("root");
169+
delegatingWriter.WriteStartAttribute("prefix", "attrName", "namespace");
170+
delegatingWriter.WriteString("attrValue");
171+
delegatingWriter.WriteEndAttribute();
172+
delegatingWriter.WriteEndElement();
173+
delegatingWriter.Flush();
174+
175+
Assert.AreEqual("<root prefix:attrName=\"attrValue\" xmlns:prefix=\"namespace\" />", output.ToString());
176+
}
177+
178+
[Test]
179+
public void TestWriteQualifiedName()
180+
{
181+
delegatingWriter.WriteStartElement("root");
182+
delegatingWriter.WriteAttributeString("xmlns", "namespace", null, "namespace");
183+
delegatingWriter.WriteQualifiedName("qualifiedName", "namespace");
184+
delegatingWriter.WriteEndElement();
185+
delegatingWriter.Flush();
186+
187+
Assert.AreEqual("<root xmlns:namespace=\"namespace\">namespace:qualifiedName</root>", output.ToString());
188+
}
189+
190+
[Test]
191+
public void TestWriteSurrogateCharEntity()
192+
{
193+
delegatingWriter.WriteStartElement("root");
194+
delegatingWriter.WriteSurrogateCharEntity('\uDC00', '\uD800');
195+
delegatingWriter.WriteEndElement();
196+
delegatingWriter.Flush();
197+
198+
Assert.AreEqual("<root>&#x10000;</root>", output.ToString());
199+
}
200+
}
201+
}

mdoc/mdoc.Test/Enumeration/ExceptionTests.cs

Lines changed: 56 additions & 40 deletions
Original file line numberDiff line numberDiff line change
@@ -5,62 +5,78 @@
55

66
namespace mdoc.Test.Enumeration
77
{
8-
[TestFixture ()]
9-
public class ExceptionTests : CecilBaseTest
10-
{
11-
[Test ()]
12-
public void TestExceptionEnumerations ()
13-
{
14-
var type = GetTypeDef<ExceptionTestClass> ();
15-
var member = type.Methods.Single (m => m.Name == "ThrowAnException");
8+
[TestFixture()]
9+
public class ExceptionTests : CecilBaseTest
10+
{
11+
[Test()]
12+
public void TestExceptionEnumerations()
13+
{
14+
var type = GetTypeDef<ExceptionTestClass>();
15+
var member = type.Methods.Single(m => m.Name == "ThrowAnException");
1616

17-
var sources = new ExceptionLookup (ExceptionLocations.DependentAssemblies)[member];
17+
var sources = new ExceptionLookup(ExceptionLocations.DependentAssemblies)[member];
1818

19-
Assert.IsNotNull (sources);
20-
Assert.AreEqual (1, sources.Count ());
21-
var source = sources.First ();
22-
Assert.AreEqual ("ThrowAnException", source.Sources.First ().Name);
19+
Assert.IsNotNull(sources);
20+
Assert.AreEqual(1, sources.Count());
21+
var source = sources.First();
22+
Assert.AreEqual("ThrowAnException", source.Sources.First().Name);
2323
}
2424

25-
[Test ()]
26-
public void TestExceptionEnumerations_FromPrivateMethod ()
25+
[Test()]
26+
public void TestExceptionEnumerations_FromPrivateMethod()
2727
{
28-
var type = GetTypeDef<ExceptionTestClass> ();
29-
var member = type.Methods.Single (m => m.Name == "ThrowFromPrivateMethod");
28+
var type = GetTypeDef<ExceptionTestClass>();
29+
var member = type.Methods.Single(m => m.Name == "ThrowFromPrivateMethod");
3030

31-
var sources = new ExceptionLookup (ExceptionLocations.DependentAssemblies)[member];
31+
var sources = new ExceptionLookup(ExceptionLocations.DependentAssemblies)[member];
3232

33-
Assert.IsNotNull (sources);
34-
Assert.AreEqual (0, sources.Count ());
33+
Assert.IsNotNull(sources);
34+
Assert.AreEqual(0, sources.Count());
3535
}
3636

37-
[Test ()]
38-
public void TestExceptionEnumerations_FromPublicMethod ()
37+
[Test()]
38+
public void TestExceptionEnumerations_FromPublicMethod()
3939
{
40-
var type = GetTypeDef<ExceptionTestClass> ();
41-
var member = type.Methods.Single (m => m.Name == "ThrowFromPublicMethod");
40+
var type = GetTypeDef<ExceptionTestClass>();
41+
var member = type.Methods.Single(m => m.Name == "ThrowFromPublicMethod");
4242

43-
var sources = new ExceptionLookup (ExceptionLocations.Assembly)[member];
43+
var sources = new ExceptionLookup(ExceptionLocations.Assembly)[member];
4444

45-
Assert.IsNotNull (sources);
46-
Assert.AreEqual (1, sources.Count ());
47-
var source = sources.First ();
48-
Assert.AreEqual ("ThrowItPublic", source.Sources.First ().Name);
45+
Assert.IsNotNull(sources);
46+
Assert.AreEqual(1, sources.Count());
47+
var source = sources.First();
48+
Assert.AreEqual("ThrowItPublic", source.Sources.First().Name);
49+
}
50+
51+
[Test()]
52+
public void TestExceptionEnumerations_FromInternalMethod()
53+
{
54+
var type = GetTypeDef<ExceptionTestClass>();
55+
var member = type.Methods.Single(m => m.Name == "ThrowFromInternalMethod");
56+
57+
var sources = new ExceptionLookup(ExceptionLocations.Assembly)[member];
58+
59+
Assert.IsNotNull(sources);
60+
Assert.AreEqual(1, sources.Count());
61+
var source = sources.First();
62+
Assert.AreEqual("ThrowItInternal", source.Sources.First().Name);
4963
}
5064

5165
public class ExceptionTestClass
5266
{
5367
public void ThrowAnException()
5468
{
55-
throw new NotImplementedException ();
56-
}
57-
58-
public void ThrowFromPrivateMethod () => ThrowItPrivate ();
59-
private void ThrowItPrivate () => throw new NotImplementedException ();
60-
61-
62-
public void ThrowFromPublicMethod () => ThrowItPublic ();
63-
public void ThrowItPublic () => throw new NotImplementedException ();
64-
}
65-
}
69+
throw new NotImplementedException();
70+
}
71+
72+
public void ThrowFromPrivateMethod() => ThrowItPrivate();
73+
private void ThrowItPrivate() => throw new NotImplementedException();
74+
75+
public void ThrowFromPublicMethod() => ThrowItPublic();
76+
public void ThrowItPublic() => throw new NotImplementedException();
77+
78+
internal void ThrowFromInternalMethod() => ThrowItInternal();
79+
internal void ThrowItInternal() => throw new NotImplementedException();
80+
}
81+
}
6682
}

mdoc/mdoc.Test/FormatterTests.cs

Lines changed: 18 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -601,6 +601,24 @@ public void CSharpStaticEventImplementation(string typeFullName, string eventNam
601601
TestEventSignature(staticVirtualMemberDllPath, typeFullName, eventName, expectedSignature);
602602
}
603603

604+
[TestCase("AllowsRefStructDemo.IRefStructProcessor`1",
605+
"public interface IRefStructProcessor<T> where T : allows ref struct")]
606+
public void CSharpAllowsRefStructForTypeTest(string typeFullName, string expectedSignature)
607+
{
608+
var allowsRefStructDllPath = "../../../../external/Test/AllowsRefStructDemo.dll";
609+
TestTypeSignature(allowsRefStructDllPath, typeFullName, expectedSignature);
610+
}
611+
612+
[TestCase("AllowsRefStructDemo.Immutable", "Update",
613+
"public bool Update<TArg> (TArg transformerArgument) where TArg : new(), allows ref struct;")]
614+
[TestCase("AllowsRefStructDemo.RefStructHandler", "Handle",
615+
"public void Handle<T> (ref T item) where T : new(), allows ref struct;")]
616+
public void CSharpAllowsRefStructForMemberTest(string typeFullName, string methodName, string expectedSignature)
617+
{
618+
var allowsRefStructDllPath = "../../../../external/Test/AllowsRefStructDemo.dll";
619+
TestMethodSignature(allowsRefStructDllPath, typeFullName, methodName, expectedSignature);
620+
}
621+
604622
#region Helper Methods
605623
string RealTypeName(string name){
606624
switch (name) {

0 commit comments

Comments
 (0)