4 using System.Collections.Generic;
11 namespace MonoTests.Monodoc.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>)");
114 AssertValidUrl ("C:Microsoft.Build.Utilities.TaskItem(System.String,System.Collections.IDictionary)");
118 public void SlashExpressionValidTest ()
120 AssertValidUrl ("T:Foo.Bar.Type/*");
121 AssertValidUrl ("T:Foo.Bar.Type/M");
122 AssertValidUrl ("T:Gendarme.Framework.Bitmask<T>/M/Equals");
123 AssertValidUrl ("T:Gendarme.Framework.Helpers.Log/M/WriteLine<T>");
124 AssertValidUrl ("T:System.Windows.Forms.AxHost/M/System.ComponentModel.ICustomTypeDescriptor.GetEvents");
128 public void MethodWithArgModValidTest ()
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:Foo.Bar.FooBar(int*, System.Drawing.Imaging&)");
134 AssertValidUrl ("M:Atk.NoOpObject.GetRunAttributes(int,int&,int&)");
138 public void MethodWithJaggedArrayArgsValidTest ()
140 AssertValidUrl ("M:System.Reflection.Emit.SignatureHelper.GetPropertySigHelper(System.Reflection.Module,System.Reflection.CallingConventions,Type,Type[],Type[],Type[],Type[][],Type[][])");
144 public void MethodWithInnerTypeValidTest ()
146 AssertValidUrl ("M:System.TimeZoneInfo+AdjustmentRule.CreateAdjustmentRule");
150 public void FieldValidTest ()
152 AssertValidUrl ("F:Mono.Terminal.Curses.KeyF10");
153 AssertValidUrl ("F:Novell.Directory.Ldap.Utilclass.ExceptionMessages.NOT_IMPLEMENTED");
154 AssertValidUrl ("F:Novell.Directory.Ldap.LdapException.NOT_ALLOWED_ON_NONLEAF");
158 public void PropertyValidTest ()
160 AssertValidUrl ("P:System.Foo.Bar");
161 AssertValidUrl ("P:System.ArraySegment<T>.Array");
165 public void IndexPropertyValidTest ()
167 AssertValidUrl ("P:System.ComponentModel.PropertyDescriptorCollection.Item(int)");
168 AssertValidUrl ("P:System.ComponentModel.AttributeCollection.Item(Type)");
169 AssertValidUrl ("P:System.Web.SessionState.HttpSessionStateContainer$System.Web.SessionState.IHttpSessionState.Item(System.Int32)");
170 AssertValidUrl ("P:System.Collections.Specialized.BitVector32.Item(System.Collections.Specialized.BitVector32+Section)");
174 public void ExplicitMethodImplValidTest ()
176 AssertValidUrl ("M:Microsoft.Win32.RegistryKey$System.IDisposable.Dispose");
180 public void AspNetSafeUrlValidTest ()
182 AssertValidUrl ("M:MonoTouch.UIKit.UICollectionViewLayoutAttributes.CreateForCell{T}");
186 public void GenericTypeArgsIsNumericTest ()
188 var desc = parser.Parse ("T:System.Collections.Generic.Dictionary`2");
189 Assert.IsTrue (desc.GenericTypeArgumentsIsNumeric);
190 Assert.AreEqual (2, desc.GenericTypeArguments.Count);
191 desc = parser.Parse ("T:System.Collections.Generic.Dictionary<TKey,TValue>");
192 Assert.IsFalse (desc.GenericTypeArgumentsIsNumeric);
196 public void GenericTypeArgsNumericToStringTest ()
198 string stringCref = "T:System.Collections.Generic.Dictionary`2";
199 var desc = parser.Parse (stringCref);
200 Assert.IsTrue (desc.GenericTypeArgumentsIsNumeric);
201 Assert.AreEqual (2, desc.GenericTypeArguments.Count);
202 string generatedEcmaCref = desc.ToEcmaCref ();
203 Assert.AreEqual (stringCref, generatedEcmaCref);
207 public void MetaEtcNodeTest ()
209 var ast = new EcmaDesc () { DescKind = EcmaDesc.Kind.Type,
210 Namespace = "Foo.Bar",
213 AssertUrlDesc (ast, "T:Foo.Bar.Type/*");
217 public void MetaEtcWithInnerTypeTest ()
219 var ast = new EcmaDesc () { DescKind = EcmaDesc.Kind.Type,
220 Namespace = "Novell.Directory.Ldap",
221 TypeName = "Connection",
222 NestedType = new EcmaDesc { DescKind = EcmaDesc.Kind.Type, TypeName = "ReaderThread" },
224 AssertUrlDesc (ast, "T:Novell.Directory.Ldap.Connection+ReaderThread/*");
228 public void SimpleTypeUrlParseTest ()
230 var ast = new EcmaDesc () { DescKind = EcmaDesc.Kind.Type,
232 Namespace = "System" };
233 AssertUrlDesc (ast, "T:System.String");
237 public void TypeWithOneGenericUrlParseTest ()
239 var generics = new[] {
241 DescKind = EcmaDesc.Kind.Type,
242 Namespace = string.Empty,
246 var ast = new EcmaDesc () { DescKind = EcmaDesc.Kind.Type,
248 Namespace = "System",
249 GenericTypeArguments = generics,
252 AssertUrlDesc (ast, "T:System.String<T>");
256 public void TypeWithOneGenericUrlParseTestUsingAspNetStyleUrl ()
258 var generics = new[] {
260 DescKind = EcmaDesc.Kind.Type,
261 Namespace = string.Empty,
265 var ast = new EcmaDesc () { DescKind = EcmaDesc.Kind.Type,
267 Namespace = "System",
268 GenericTypeArguments = generics,
271 AssertUrlDesc (ast, "T:System.String{T}");
275 public void TypeWithNestedGenericUrlParseTest ()
277 var generics = new[] {
279 DescKind = EcmaDesc.Kind.Type,
281 Namespace = string.Empty
284 DescKind = EcmaDesc.Kind.Type,
285 Namespace = "System.Collections.Generic",
287 GenericTypeArguments = new[] {
289 DescKind = EcmaDesc.Kind.Type,
291 Namespace = string.Empty
296 var ast = new EcmaDesc () { DescKind = EcmaDesc.Kind.Type,
298 Namespace = "System",
299 GenericTypeArguments = generics,
302 AssertUrlDesc (ast, "T:System.String<T, System.Collections.Generic.List<V>>");
306 public void SimpleMethodUrlParseTest ()
308 var ast = new EcmaDesc () { DescKind = EcmaDesc.Kind.Method,
310 Namespace = "System",
311 MemberName = "FooBar"
313 AssertUrlDesc (ast, "M:System.String.FooBar()");
317 public void MethodWithArgsUrlParseTest ()
321 DescKind = EcmaDesc.Kind.Type,
322 Namespace = "System",
326 DescKind = EcmaDesc.Kind.Type,
328 Namespace = string.Empty
331 var ast = new EcmaDesc () { DescKind = EcmaDesc.Kind.Method,
333 Namespace = "System",
334 MemberName = "FooBar",
335 MemberArguments = args
337 AssertUrlDesc (ast, "M:System.String.FooBar(System.String, Int32)");
341 public void MethodWithArgsAndGenericsUrlParseTest ()
345 DescKind = EcmaDesc.Kind.Type,
346 Namespace = "System",
350 DescKind = EcmaDesc.Kind.Type,
351 Namespace = "System.Collections.Generic",
352 TypeName = "Dictionary",
353 GenericTypeArguments = new[] {
355 DescKind = EcmaDesc.Kind.Type,
357 Namespace = string.Empty
360 DescKind = EcmaDesc.Kind.Type,
362 Namespace = string.Empty
368 var generics = new[] {
370 DescKind = EcmaDesc.Kind.Type,
372 Namespace = string.Empty,
373 GenericTypeArguments = new[] {
375 DescKind = EcmaDesc.Kind.Type,
376 Namespace = "System",
380 DescKind = EcmaDesc.Kind.Type,
382 Namespace = string.Empty
388 var ast = new EcmaDesc () { DescKind = EcmaDesc.Kind.Method,
390 Namespace = "System",
391 MemberName = "FooBar",
392 MemberArguments = args,
393 GenericMemberArguments = generics
395 AssertUrlDesc (ast, "M:System.String.FooBar<Action<System.Single, int>>(System.String, System.Collections.Generic.Dictionary<K, V>)");
399 public void ExplicitMethodImplementationParseTest ()
401 var inner = new EcmaDesc {
402 MemberName = "Dispose",
403 TypeName = "IDisposable",
406 var ast = new EcmaDesc {
407 DescKind = EcmaDesc.Kind.Method,
408 TypeName = "RegistryKey",
409 Namespace = "Microsoft.Win32",
410 ExplicitImplMember = inner
412 AssertUrlDesc (ast, "M:Microsoft.Win32.RegistryKey$System.IDisposable.Dispose");
416 public void SimpleMethodWithNumberInType ()
418 var ast = new EcmaDesc {
419 DescKind = EcmaDesc.Kind.Method,
421 Namespace = "Mono.Security",
424 AssertUrlDesc (ast, "M:Mono.Security.ASN1.Add");
428 public void JaggedArrayWithDimensions ()
430 var ast = new EcmaDesc {
431 DescKind = EcmaDesc.Kind.Type,
433 Namespace = "System",
434 ArrayDimensions = new int[] { 3, 1, 1 }
436 AssertUrlDesc (ast, "T:System.Int32[,,][][]");
440 public void ExplicitIndexerImplementation ()
442 var explicitImpl = new EcmaDesc {
443 Namespace = "System.Web.SessionState",
444 TypeName = "IHttpSessionState",
446 MemberArguments = new [] { new EcmaDesc { DescKind = EcmaDesc.Kind.Type, Namespace = "System", TypeName = "Int32" } },
448 var ast = new EcmaDesc {
449 DescKind = EcmaDesc.Kind.Property,
450 TypeName = "HttpSessionStateContainer",
451 Namespace = "System.Web.SessionState",
452 ExplicitImplMember = explicitImpl,
454 AssertUrlDesc (ast, "P:System.Web.SessionState.HttpSessionStateContainer$System.Web.SessionState.IHttpSessionState.Item(System.Int32)");
458 public void TreeParsabilityTest ()
460 var rootTree = RootTree.LoadTree ("/home/jeremie/monodoc/");
462 var generator = new CheckGenerator ();
464 foreach (var leaf in GetLeaves (rootTree.RootNode).Where (IsEcmaNode))
465 AssertUrl (leaf.PublicUrl);
468 IEnumerable<Node> GetLeaves (Node node)
476 foreach (var child in node.Nodes) {
477 if (!string.IsNullOrEmpty (child.Element) && !child.Element.StartsWith ("root:/"))
479 foreach (var childLeaf in GetLeaves (child))
480 yield return childLeaf;
485 bool IsEcmaNode (Node node)
487 var url = node.PublicUrl;
488 return url != null && url.Length > 2 && url[1] == ':';