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

VBFormatterTests.cs « mdoc.Test « mdoc - github.com/mono/api-doc-tools.git - Unnamed repository; edit this file 'description' to name the repository.
summaryrefslogtreecommitdiff
blob: 87d4565c7e83679f06d5e340ab629515f65921d3 (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
163
164
165
166
167
168
169
170
171
172
173
174
using mdoc.Test.SampleClasses;
using Mono.Documentation.Updater;
using NUnit.Framework;

namespace mdoc.Test
{
    [TestFixture()]
    public class VBFormatterTests : BasicFormatterTests<VBMemberFormatter>
    {
        private VBMemberFormatter vbMemberFormatter = new VBMemberFormatter();
        protected override VBMemberFormatter formatter => vbMemberFormatter;

        [Test]
        public void VB_op_Addition() =>
            TestBinaryOp("Addition", "+");

        [Test]
        public void VB_op_Subtraction() =>
            TestBinaryOp("Subtraction", "-");

        [Test]
        public void VB_op_Division() =>
            TestBinaryOp("Division", "/");
        
        [Test]
        public void VB_op_Multiplication() =>
            TestBinaryOp("Multiply", "*");

        [Test]
        public void VB_op_Modulus() =>
            TestBinaryOp("Modulus", "Mod");

        [Test]
        public void VB_op_BitwiseAnd() =>
            TestBinaryOp("BitwiseAnd", "And");

        [Test]
        public void VB_op_BitwiseOr() =>
            TestBinaryOp("BitwiseOr", "Or");

        [Test]
        public void VB_op_ExclusiveOr() =>
            TestBinaryOp("ExclusiveOr", "Xor");

        [Test]
        public void VB_op_LeftShift() =>
            TestBinaryOp("LeftShift", "<<", secondType: "Integer");

        [Test]
        public void VB_op_RightShift() =>
            TestBinaryOp("RightShift", ">>", secondType: "Integer");

        [Test]
        public void VB_op_UnaryPlus() =>
            TestUnaryOp("UnaryPlus", "+");

        [Test]
        public void VB_op_UnaryNegation() =>
            TestUnaryOp("UnaryNegation", "-");

        [Test]
        public void VB_op_LogicalNot() =>
            TestUnaryOp("LogicalNot", "Not");

        [Test]
        public void VB_op_OnesComplement() =>
            TestUnaryOp("OnesComplement", "Not");
        
        [Test]
        public void VB_op_True() =>
            TestUnaryOp("True", "IsTrue", returnType: "Boolean");

        [Test]
        public void VB_op_False() =>
            TestUnaryOp("False", "IsFalse", returnType: "Boolean");

        [Test]
        public void VB_op_Equality() =>
            TestComparisonOp("Equality", "==");

        [Test]
        public void VB_op_Inequality() =>
            TestComparisonOp("Inequality", "!=");

        [Test]
        public void VB_op_LessThan() =>
            TestComparisonOp("LessThan", "<");

        [Test]
        public void VB_op_GreaterThan() =>
            TestComparisonOp("GreaterThan", ">");

        [Test]
        public void VB_op_LessThanOrEqual() =>
            TestComparisonOp("LessThanOrEqual", "<=");

        [Test]
        public void VB_op_GreaterThanOrEqual() =>
            TestComparisonOp("GreaterThanOrEqual", ">=");

        [Test]
        public void VB_op_Implicit() =>
            TestConversionOp("Implicit", "Widening", "TestClass", "TestClassTwo");

        [Test]
        public void VB_op_Implicit_inverse() =>
            TestConversionOp("Implicit", "Widening", "TestClassTwo", "TestClass");

        [Test]
        public void VB_op_Explicit() =>
            TestConversionOp("Explicit", "Narrowing", "Integer", "TestClass");

        [Test]
        public void VB_op_Explicit_inverse() =>
            TestConversionOp("Explicit", "Narrowing", "TestClass", "Integer");
        
        
        [Test]
        public void Params()
        {
            var member = GetMethod(typeof(TestClass), m => m.Name == "DoSomethingWithParams");
            var formatter = new VBMemberFormatter();
            var sig = formatter.GetDeclaration(member);
            Assert.AreEqual("Public Sub DoSomethingWithParams (ParamArray values As Integer())", sig);
        }

        [Test]
        public void DefaultNullValueForParams()
        {
            var member = GetMethod(typeof(SomeGenericClass<>), m => m.Name == "SomeMethod4");
            var sig = formatter.GetDeclaration(member);
            Assert.AreEqual("Public Sub SomeMethod4 (ByRef a As String, t As T, Optional b As Object = Nothing)", sig);
        }

        #region Helper Methods
        string RealTypeName(string name)
        {
            switch (name)
            {
                case "Integer": return "Int32";
                default: return name;
            }
        }

        void TestConversionOp(string name, string type, string leftType, string rightType)
        {
            TestOp(name, $"Public Shared {type} Operator CType (c1 As {rightType}) As {leftType}", argCount: 1, returnType: leftType);
        }

        void TestComparisonOp(string name, string op)
        {
            TestOp(name, $"Public Shared Operator {op} (c1 As TestClass, c2 As TestClass) As Boolean", argCount: 2, returnType: "Boolean");
        }

        void TestUnaryOp(string name, string op, string returnType = "TestClass")
        {
            TestOp(name, $"Public Shared Operator {op} (c1 As TestClass) As {returnType}", argCount: 1, returnType: returnType);
        }

        void TestBinaryOp(string name, string op, string returnType = "TestClass", string secondType = "TestClass")
        {
            TestOp(name, $"Public Shared Operator {op} (c1 As TestClass, c2 As {secondType}) As {returnType}", 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 sig = formatter.GetDeclaration(member);
            Assert.AreEqual(expectedSig, sig);
        }

        #endregion
    }
}