4 using System.Collections.Generic;
11 namespace MonoTests.MonkeyDoc.Ecma
14 public class EcmaUrlTests
21 parser = new EcmaUrlParser ();
24 void AssertValidUrl (string url)
29 Assert.Fail (string.Format ("URL '{0}' deemed not valid", url));
33 void AssertInvalidUrl (string url)
40 Assert.Fail (string.Format ("URL '{0}' deemed valid", url));
43 void AssertUrlDesc (EcmaDesc expected, string url)
45 EcmaDesc actual = null;
47 actual = parser.Parse (url);
48 } catch (Exception e) {
49 Assert.Fail (string.Format ("URL '{0}' deemed not valid: {1}{2}", url, Environment.NewLine, e.ToString ()));
52 Assert.AreEqual (expected, actual, "Converted URL differs");
56 public void CommonMethodUrlIsValidTest ()
58 AssertValidUrl ("M:System.String.FooBar()");
59 AssertValidUrl ("M:System.String.FooBar(System.String, Int32)");
60 AssertValidUrl ("M:System.Foo.Int32<System.String+FooBar<System.Blop<T, U`2>>>.Foo()");
61 AssertValidUrl ("M:System.Foo.Int32<System.String+FooBar<System.Blop<T, U`2>>>.Foo(Bleh,Bar)");
62 AssertValidUrl ("M:System.Foo.Int32<System.String+FooBar<System.Blop<T, U`2>>>.Foo(Bleh<V>,Bar)");
63 AssertValidUrl ("M:Gendarme.Framework.Helpers.Log.WriteLine(string,string,object[])");
64 AssertValidUrl ("M:Mono.Security.X509.Extensions.SubjectKeyIdentifierExtension.Decode");
65 AssertValidUrl ("M:Mono.Security.PKCS7.IssuerAndSerialNumber");
69 public void CommonTypeUrlIsValidTest ()
71 AssertValidUrl ("T:Int32");
72 AssertValidUrl ("T:System.Foo.Int32");
73 AssertValidUrl ("T:System.Foo.Int32<System.String+FooBar`1>");
74 AssertValidUrl ("T:System.Foo.Int32<System.String+FooBar<System.Blop<T, U>>>");
75 AssertValidUrl ("T:System.Foo.Int32<T>");
76 AssertValidUrl ("T:System.Foo.Int32<T,U>");
77 AssertValidUrl ("T:System.Foo.Int32<System.String+FooBar<System.Blop<T, U>>>");
78 AssertValidUrl ("T:System.Foo.Int32<System.String+FooBar<System.Blop<T, U`2>>>");
82 public void CommonTypeUrlNotValidTest ()
84 AssertInvalidUrl ("TInt32");
85 AssertInvalidUrl ("K:Int32");
86 AssertInvalidUrl ("T:System..Foo.Int32");
87 AssertInvalidUrl ("T:System.Foo.Int32<System.String+FooBar`1");
88 AssertInvalidUrl ("T:System.Foo.Int32<System.String+FooBarSystem.Blop<T, U>>>");
89 AssertInvalidUrl ("T:System.Foo.Int32<T,>");
90 AssertInvalidUrl ("T:System.Foo.Int32<+FooBar<System.Blop<T, U>>>");
94 public void NamespaceValidTest ()
96 AssertValidUrl ("N:Foo.Bar");
97 AssertValidUrl ("N:Foo");
98 AssertValidUrl ("N:Foo.Bar.Baz");
99 AssertValidUrl ("N:A.B.C");
101 var ast = new EcmaDesc () { DescKind = EcmaDesc.Kind.Namespace,
102 Namespace = "Foo.Bar.Blop" };
103 AssertUrlDesc (ast, "N:Foo.Bar.Blop");
107 public void ConstructorValidTest ()
109 AssertValidUrl ("C:Gendarme.Rules.Concurrency.DecorateThreadsRule.DecorateThreadsRule");
110 AssertValidUrl ("C:Gendarme.Rules.Concurrency.DecorateThreadsRule.DecorateThreadsRule()");
111 AssertValidUrl ("C:Gendarme.Rules.Concurrency.DecorateThreadsRule.DecorateThreadsRule(System.String)");
112 AssertValidUrl ("C:Gendarme.Framework.Helpers.MethodSignature.MethodSignature(string,string,string[],System.Func<Mono.Cecil.MethodReference,System.Boolean>)");
113 AssertValidUrl ("C:System.Collections.Generic.Dictionary<TKey,TValue>+KeyCollection.KeyCollection(System.Collections.Generic.Dictionary<TKey,TValue>)");
117 public void SlashExpressionValidTest ()
119 AssertValidUrl ("T:Foo.Bar.Type/*");
120 AssertValidUrl ("T:Foo.Bar.Type/M");
121 AssertValidUrl ("T:Gendarme.Framework.Bitmask<T>/M/Equals");
122 AssertValidUrl ("T:Gendarme.Framework.Helpers.Log/M/WriteLine<T>");
123 AssertValidUrl ("T:System.Windows.Forms.AxHost/M/System.ComponentModel.ICustomTypeDescriptor.GetEvents");
127 public void MethodWithArgModValidTest ()
129 AssertValidUrl ("M:Foo.Bar.FooBar(int, System.Drawing.Imaging&)");
130 AssertValidUrl ("M:Foo.Bar.FooBar(int@, System.Drawing.Imaging)");
131 AssertValidUrl ("M:Foo.Bar.FooBar(int, System.Drawing.Imaging*)");
132 AssertValidUrl ("M:Foo.Bar.FooBar(int*, System.Drawing.Imaging&)");
133 AssertValidUrl ("M:Atk.NoOpObject.GetRunAttributes(int,int&,int&)");
137 public void MethodWithJaggedArrayArgsValidTest ()
139 AssertValidUrl ("M:System.Reflection.Emit.SignatureHelper.GetPropertySigHelper(System.Reflection.Module,System.Reflection.CallingConventions,Type,Type[],Type[],Type[],Type[][],Type[][])");
143 public void MethodWithInnerTypeValidTest ()
145 AssertValidUrl ("M:System.TimeZoneInfo+AdjustmentRule.CreateAdjustmentRule");
149 public void FieldValidTest ()
151 AssertValidUrl ("F:Mono.Terminal.Curses.KeyF10");
152 AssertValidUrl ("F:Novell.Directory.Ldap.Utilclass.ExceptionMessages.NOT_IMPLEMENTED");
153 AssertValidUrl ("F:Novell.Directory.Ldap.LdapException.NOT_ALLOWED_ON_NONLEAF");
157 public void PropertyValidTest ()
159 AssertValidUrl ("P:System.Foo.Bar");
160 AssertValidUrl ("P:System.ArraySegment<T>.Array");
164 public void IndexPropertyValidTest ()
166 AssertValidUrl ("P:System.ComponentModel.PropertyDescriptorCollection.Item(int)");
167 AssertValidUrl ("P:System.ComponentModel.AttributeCollection.Item(Type)");
168 AssertValidUrl ("P:System.Web.SessionState.HttpSessionStateContainer$System.Web.SessionState.IHttpSessionState.Item(System.Int32)");
169 AssertValidUrl ("P:System.Collections.Specialized.BitVector32.Item(System.Collections.Specialized.BitVector32+Section)");
173 public void ExplicitMethodImplValidTest ()
175 AssertValidUrl ("M:Microsoft.Win32.RegistryKey$System.IDisposable.Dispose");
179 public void MetaEtcNodeTest ()
181 var ast = new EcmaDesc () { DescKind = EcmaDesc.Kind.Type,
182 Namespace = "Foo.Bar",
185 AssertUrlDesc (ast, "T:Foo.Bar.Type/*");
189 public void MetaEtcWithInnerTypeTest ()
191 var ast = new EcmaDesc () { DescKind = EcmaDesc.Kind.Type,
192 Namespace = "Novell.Directory.Ldap",
193 TypeName = "Connection",
194 NestedType = new EcmaDesc { DescKind = EcmaDesc.Kind.Type, TypeName = "ReaderThread" },
196 AssertUrlDesc (ast, "T:Novell.Directory.Ldap.Connection+ReaderThread/*");
200 public void SimpleTypeUrlParseTest ()
202 var ast = new EcmaDesc () { DescKind = EcmaDesc.Kind.Type,
204 Namespace = "System" };
205 AssertUrlDesc (ast, "T:System.String");
209 public void TypeWithOneGenericUrlParseTest ()
211 var generics = new[] {
213 DescKind = EcmaDesc.Kind.Type,
214 Namespace = string.Empty,
218 var ast = new EcmaDesc () { DescKind = EcmaDesc.Kind.Type,
220 Namespace = "System",
221 GenericTypeArguments = generics,
224 AssertUrlDesc (ast, "T:System.String<T>");
228 public void TypeWithNestedGenericUrlParseTest ()
230 var generics = new[] {
232 DescKind = EcmaDesc.Kind.Type,
234 Namespace = string.Empty
237 DescKind = EcmaDesc.Kind.Type,
238 Namespace = "System.Collections.Generic",
240 GenericTypeArguments = new[] {
242 DescKind = EcmaDesc.Kind.Type,
244 Namespace = string.Empty
249 var ast = new EcmaDesc () { DescKind = EcmaDesc.Kind.Type,
251 Namespace = "System",
252 GenericTypeArguments = generics,
255 AssertUrlDesc (ast, "T:System.String<T, System.Collections.Generic.List<V>>");
259 public void SimpleMethodUrlParseTest ()
261 var ast = new EcmaDesc () { DescKind = EcmaDesc.Kind.Method,
263 Namespace = "System",
264 MemberName = "FooBar"
266 AssertUrlDesc (ast, "M:System.String.FooBar()");
270 public void MethodWithArgsUrlParseTest ()
274 DescKind = EcmaDesc.Kind.Type,
275 Namespace = "System",
279 DescKind = EcmaDesc.Kind.Type,
281 Namespace = string.Empty
284 var ast = new EcmaDesc () { DescKind = EcmaDesc.Kind.Method,
286 Namespace = "System",
287 MemberName = "FooBar",
288 MemberArguments = args
290 AssertUrlDesc (ast, "M:System.String.FooBar(System.String, Int32)");
294 public void MethodWithArgsAndGenericsUrlParseTest ()
298 DescKind = EcmaDesc.Kind.Type,
299 Namespace = "System",
303 DescKind = EcmaDesc.Kind.Type,
304 Namespace = "System.Collections.Generic",
305 TypeName = "Dictionary",
306 GenericTypeArguments = new[] {
308 DescKind = EcmaDesc.Kind.Type,
310 Namespace = string.Empty
313 DescKind = EcmaDesc.Kind.Type,
315 Namespace = string.Empty
321 var generics = new[] {
323 DescKind = EcmaDesc.Kind.Type,
325 Namespace = string.Empty,
326 GenericTypeArguments = new[] {
328 DescKind = EcmaDesc.Kind.Type,
329 Namespace = "System",
333 DescKind = EcmaDesc.Kind.Type,
335 Namespace = string.Empty
341 var ast = new EcmaDesc () { DescKind = EcmaDesc.Kind.Method,
343 Namespace = "System",
344 MemberName = "FooBar",
345 MemberArguments = args,
346 GenericMemberArguments = generics
348 AssertUrlDesc (ast, "M:System.String.FooBar<Action<System.Single, int>>(System.String, System.Collections.Generic.Dictionary<K, V>)");
352 public void ExplicitMethodImplementationParseTest ()
354 var inner = new EcmaDesc {
355 MemberName = "Dispose",
356 TypeName = "IDisposable",
359 var ast = new EcmaDesc {
360 DescKind = EcmaDesc.Kind.Method,
361 TypeName = "RegistryKey",
362 Namespace = "Microsoft.Win32",
363 ExplicitImplMember = inner
365 AssertUrlDesc (ast, "M:Microsoft.Win32.RegistryKey$System.IDisposable.Dispose");
369 public void SimpleMethodWithNumberInType ()
371 var ast = new EcmaDesc {
372 DescKind = EcmaDesc.Kind.Method,
374 Namespace = "Mono.Security",
377 AssertUrlDesc (ast, "M:Mono.Security.ASN1.Add");
381 public void JaggedArrayWithDimensions ()
383 var ast = new EcmaDesc {
384 DescKind = EcmaDesc.Kind.Type,
386 Namespace = "System",
387 ArrayDimensions = new int[] { 3, 1, 1 }
389 AssertUrlDesc (ast, "T:System.Int32[,,][][]");
393 public void ExplicitIndexerImplementation ()
395 var explicitImpl = new EcmaDesc {
396 Namespace = "System.Web.SessionState",
397 TypeName = "IHttpSessionState",
399 MemberArguments = new [] { new EcmaDesc { DescKind = EcmaDesc.Kind.Type, Namespace = "System", TypeName = "Int32" } },
401 var ast = new EcmaDesc {
402 DescKind = EcmaDesc.Kind.Property,
403 TypeName = "HttpSessionStateContainer",
404 Namespace = "System.Web.SessionState",
405 ExplicitImplMember = explicitImpl,
407 AssertUrlDesc (ast, "P:System.Web.SessionState.HttpSessionStateContainer$System.Web.SessionState.IHttpSessionState.Item(System.Int32)");
411 public void TreeParsabilityTest ()
413 var rootTree = RootTree.LoadTree ("/home/jeremie/monodoc/");
415 var generator = new CheckGenerator ();
417 foreach (var leaf in GetLeaves (rootTree.RootNode).Where (IsEcmaNode))
418 AssertUrl (leaf.PublicUrl);
421 IEnumerable<Node> GetLeaves (Node node)
429 foreach (var child in node.Nodes) {
430 if (!string.IsNullOrEmpty (child.Element) && !child.Element.StartsWith ("root:/"))
432 foreach (var childLeaf in GetLeaves (child))
433 yield return childLeaf;
438 bool IsEcmaNode (Node node)
440 var url = node.PublicUrl;
441 return url != null && url.Length > 2 && url[1] == ':';