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

DocUtilsTests.cs « mdoc.Test « mdoc - github.com/mono/api-doc-tools.git - Unnamed repository; edit this file 'description' to name the repository.
summaryrefslogtreecommitdiff
blob: 52a50fd7048bee588df9a25fb56d398cc7675377 (plain)
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
103
104
105
106
107
108
109
110
111
112
113
114
115
116
117
118
119
120
121
122
123
124
125
126
127
128
129
130
131
132
133
134
135
136
137
138
139
140
141
142
143
144
145
146
147
148
149
150
151
152
153
154
155
156
157
158
159
160
161
162
using System.Linq;
using mdoc.Test.SampleClasses;
using Mono.Documentation;
using Mono.Documentation.Updater;
using NUnit.Framework;
using System.Xml;

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);
        }

        [Test]
        public void TestNodeCleaner()
        {
            string xml = @"<Docs>
    <summary>To be added.</summary>
    <param name=""one"">To be added.</param>
    <param name=""two"">written docs</param>
<param name=""three"">Written but not provided</param>
</Docs>"; string xml2 = @"<Docs>
    <param name=""two"">written docs</param>
</Docs>";
            XmlDocument doc = new XmlDocument();
            doc.LoadXml(xml);

            XmlDocument incomingDoc = new XmlDocument();
            incomingDoc.LoadXml(xml2);
            DocUtils.ClearNodesIfNotDefault(doc.FirstChild, incomingDoc.FirstChild);
            Assert.IsTrue(doc.FirstChild.ChildNodes.Count == 3);
        }

        [Test]
        public void TestNodeCleaner2()
        {
            string xml = @"<Docs>
    <summary>To be added.</summary>
    <param name=""one"" name2=""n2"">To be added.</param>
<!-- this is an xml comment -->
    <param name=""two"">written docs</param>
random text
<param name=""three"">Written but not provided</param>
<![CDATA[
  for some reason
]]>
</Docs>"; string xml2 = @"<Docs>
    <summary>new summary</summary>
<!-- this is another xml comment -->
    <param name=""one"" name2=""n2"">To be added.</param>
    random text
    <param name=""two"">written docs but changed</param>
<param name=""three"">Written but and</param>
<![CDATA[
  for some reason
]]>
</Docs>";
            XmlDocument doc = new XmlDocument();
            doc.LoadXml(xml);

            XmlDocument incomingDoc = new XmlDocument();
            incomingDoc.LoadXml(xml2);
            DocUtils.ClearNodesIfNotDefault(doc.FirstChild, incomingDoc.FirstChild);
            Assert.IsTrue(doc.FirstChild.ChildNodes.Count == 0);
        }

        [Test]
        public void DocidCheck()
        {
            XmlDocument doc = new System.Xml.XmlDocument();
            doc.LoadXml(XmlConsts.CheckDocidXml);

            //c# MemberSignature is the same,but docid not
            var listA = doc.SelectNodes("/Type/Members/Member[@MemberName='op_Implicit']");
            if (listA.Count == 2)
            {
                var Notequal = DocUtils.DocIdCheck(listA[0], (XmlElement)listA[1]);
                Assert.IsTrue(Notequal);
            }

            //note:c not have docid item in xml
            var b = doc.SelectSingleNode("/Type/Members/Member[@MemberName='op_Implicit']");
            var c = doc.SelectSingleNode("/Type/Members/Member[@MemberName='.ctor']");

            var flg1 = DocUtils.DocIdCheck(b, (XmlElement)c);
            Assert.IsFalse(flg1);

            //Parameter change position
            var flg2 = DocUtils.DocIdCheck(c, (XmlElement)b);
            Assert.IsFalse(flg2);

            // c# MemberSignature is not same,docid also
            var d = doc.SelectSingleNode("/Type/Members/Member[@MemberName='Value']");
            var flg3 = DocUtils.DocIdCheck(b, (XmlElement)d);
            Assert.IsTrue(flg3);
        }

        [Test]
        public void IsEiiignoredMethod()
        {
            var type = GetType(typeof(mdoc.Test2.InternalEIICalss));
            var member = type.Methods.FirstOrDefault(t => t.FullName == "System.String mdoc.Test2.InternalEIICalss::mdoc.Test.SampleClasses.InterfaceA.get_color()");
            Assert.IsTrue(member.IsSpecialName);
            member.IsSpecialName = false;
            var result = DocUtils.IsEiiIgnoredMethod(member, member.Overrides[0]);
            Assert.IsTrue(result);
        }

        [Test]
        public void HasCustomAttributeTest()
        {
            Assert.IsFalse(DocUtils.HasCustomAttribute(null, ""));

            var type = GetType(typeof(SampleClasses.RefStruct));
            Assert.IsFalse(DocUtils.HasCustomAttribute(type, Consts.IsReadOnlyAttribute));
            Assert.IsTrue(DocUtils.HasCustomAttribute(type, Consts.IsByRefLikeAttribute));

            type = GetType(typeof(SampleClasses.ReadOnlyRefStruct));
            Assert.IsTrue(DocUtils.HasCustomAttribute(type, Consts.IsReadOnlyAttribute));
            Assert.IsTrue(DocUtils.HasCustomAttribute(type, Consts.IsByRefLikeAttribute));
        }
    }
}