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 MetaEtcNodeTest ()
198 var ast = new EcmaDesc () { DescKind = EcmaDesc.Kind.Type,
199 Namespace = "Foo.Bar",
202 AssertUrlDesc (ast, "T:Foo.Bar.Type/*");
206 public void MetaEtcWithInnerTypeTest ()
208 var ast = new EcmaDesc () { DescKind = EcmaDesc.Kind.Type,
209 Namespace = "Novell.Directory.Ldap",
210 TypeName = "Connection",
211 NestedType = new EcmaDesc { DescKind = EcmaDesc.Kind.Type, TypeName = "ReaderThread" },
213 AssertUrlDesc (ast, "T:Novell.Directory.Ldap.Connection+ReaderThread/*");
217 public void SimpleTypeUrlParseTest ()
219 var ast = new EcmaDesc () { DescKind = EcmaDesc.Kind.Type,
221 Namespace = "System" };
222 AssertUrlDesc (ast, "T:System.String");
226 public void TypeWithOneGenericUrlParseTest ()
228 var generics = new[] {
230 DescKind = EcmaDesc.Kind.Type,
231 Namespace = string.Empty,
235 var ast = new EcmaDesc () { DescKind = EcmaDesc.Kind.Type,
237 Namespace = "System",
238 GenericTypeArguments = generics,
241 AssertUrlDesc (ast, "T:System.String<T>");
245 public void TypeWithOneGenericUrlParseTestUsingAspNetStyleUrl ()
247 var generics = new[] {
249 DescKind = EcmaDesc.Kind.Type,
250 Namespace = string.Empty,
254 var ast = new EcmaDesc () { DescKind = EcmaDesc.Kind.Type,
256 Namespace = "System",
257 GenericTypeArguments = generics,
260 AssertUrlDesc (ast, "T:System.String{T}");
264 public void TypeWithNestedGenericUrlParseTest ()
266 var generics = new[] {
268 DescKind = EcmaDesc.Kind.Type,
270 Namespace = string.Empty
273 DescKind = EcmaDesc.Kind.Type,
274 Namespace = "System.Collections.Generic",
276 GenericTypeArguments = new[] {
278 DescKind = EcmaDesc.Kind.Type,
280 Namespace = string.Empty
285 var ast = new EcmaDesc () { DescKind = EcmaDesc.Kind.Type,
287 Namespace = "System",
288 GenericTypeArguments = generics,
291 AssertUrlDesc (ast, "T:System.String<T, System.Collections.Generic.List<V>>");
295 public void SimpleMethodUrlParseTest ()
297 var ast = new EcmaDesc () { DescKind = EcmaDesc.Kind.Method,
299 Namespace = "System",
300 MemberName = "FooBar"
302 AssertUrlDesc (ast, "M:System.String.FooBar()");
306 public void MethodWithArgsUrlParseTest ()
310 DescKind = EcmaDesc.Kind.Type,
311 Namespace = "System",
315 DescKind = EcmaDesc.Kind.Type,
317 Namespace = string.Empty
320 var ast = new EcmaDesc () { DescKind = EcmaDesc.Kind.Method,
322 Namespace = "System",
323 MemberName = "FooBar",
324 MemberArguments = args
326 AssertUrlDesc (ast, "M:System.String.FooBar(System.String, Int32)");
330 public void MethodWithArgsAndGenericsUrlParseTest ()
334 DescKind = EcmaDesc.Kind.Type,
335 Namespace = "System",
339 DescKind = EcmaDesc.Kind.Type,
340 Namespace = "System.Collections.Generic",
341 TypeName = "Dictionary",
342 GenericTypeArguments = new[] {
344 DescKind = EcmaDesc.Kind.Type,
346 Namespace = string.Empty
349 DescKind = EcmaDesc.Kind.Type,
351 Namespace = string.Empty
357 var generics = new[] {
359 DescKind = EcmaDesc.Kind.Type,
361 Namespace = string.Empty,
362 GenericTypeArguments = new[] {
364 DescKind = EcmaDesc.Kind.Type,
365 Namespace = "System",
369 DescKind = EcmaDesc.Kind.Type,
371 Namespace = string.Empty
377 var ast = new EcmaDesc () { DescKind = EcmaDesc.Kind.Method,
379 Namespace = "System",
380 MemberName = "FooBar",
381 MemberArguments = args,
382 GenericMemberArguments = generics
384 AssertUrlDesc (ast, "M:System.String.FooBar<Action<System.Single, int>>(System.String, System.Collections.Generic.Dictionary<K, V>)");
388 public void ExplicitMethodImplementationParseTest ()
390 var inner = new EcmaDesc {
391 MemberName = "Dispose",
392 TypeName = "IDisposable",
395 var ast = new EcmaDesc {
396 DescKind = EcmaDesc.Kind.Method,
397 TypeName = "RegistryKey",
398 Namespace = "Microsoft.Win32",
399 ExplicitImplMember = inner
401 AssertUrlDesc (ast, "M:Microsoft.Win32.RegistryKey$System.IDisposable.Dispose");
405 public void SimpleMethodWithNumberInType ()
407 var ast = new EcmaDesc {
408 DescKind = EcmaDesc.Kind.Method,
410 Namespace = "Mono.Security",
413 AssertUrlDesc (ast, "M:Mono.Security.ASN1.Add");
417 public void JaggedArrayWithDimensions ()
419 var ast = new EcmaDesc {
420 DescKind = EcmaDesc.Kind.Type,
422 Namespace = "System",
423 ArrayDimensions = new int[] { 3, 1, 1 }
425 AssertUrlDesc (ast, "T:System.Int32[,,][][]");
429 public void ExplicitIndexerImplementation ()
431 var explicitImpl = new EcmaDesc {
432 Namespace = "System.Web.SessionState",
433 TypeName = "IHttpSessionState",
435 MemberArguments = new [] { new EcmaDesc { DescKind = EcmaDesc.Kind.Type, Namespace = "System", TypeName = "Int32" } },
437 var ast = new EcmaDesc {
438 DescKind = EcmaDesc.Kind.Property,
439 TypeName = "HttpSessionStateContainer",
440 Namespace = "System.Web.SessionState",
441 ExplicitImplMember = explicitImpl,
443 AssertUrlDesc (ast, "P:System.Web.SessionState.HttpSessionStateContainer$System.Web.SessionState.IHttpSessionState.Item(System.Int32)");
447 public void TreeParsabilityTest ()
449 var rootTree = RootTree.LoadTree ("/home/jeremie/monodoc/");
451 var generator = new CheckGenerator ();
453 foreach (var leaf in GetLeaves (rootTree.RootNode).Where (IsEcmaNode))
454 AssertUrl (leaf.PublicUrl);
457 IEnumerable<Node> GetLeaves (Node node)
465 foreach (var child in node.Nodes) {
466 if (!string.IsNullOrEmpty (child.Element) && !child.Element.StartsWith ("root:/"))
468 foreach (var childLeaf in GetLeaves (child))
469 yield return childLeaf;
474 bool IsEcmaNode (Node node)
476 var url = node.PublicUrl;
477 return url != null && url.Length > 2 && url[1] == ':';