4 using System.Reflection;
5 using System.Collections.Generic;
10 using Monodoc.Generators;
12 namespace MonoTests.Monodoc
15 public class EcmaDocTest
17 // Because EcmaDoc is internal and we can't use InternalsVisibleTo since test assemblies aren't
18 // signed/strong-named by the build, we have to resort to reflection
19 TDelegate GetTestedMethod<TDelegate> (string methodName)
21 var ecmaDoc = Type.GetType ("Monodoc.Providers.EcmaDoc, monodoc, PublicKey=0738eb9f132ed756");
22 return (TDelegate)(object)Delegate.CreateDelegate (typeof (TDelegate), ecmaDoc.GetMethod (methodName));
26 public void CountTypeGenericArgumentsTest ()
28 var realCountTypeGenericArguments = GetTestedMethod<Func<string, int, int>> ("CountTypeGenericArguments");
29 // Since we don't use the optional start index parameters, bypass it by wrapping the func
30 Func<string, int> countTypeGenericArguments = s => realCountTypeGenericArguments (s, 0);
32 Assert.AreEqual (0, countTypeGenericArguments ("T:System.String"), "#0a");
33 Assert.AreEqual (0, countTypeGenericArguments ("T:String"), "#0b");
34 Assert.AreEqual (0, countTypeGenericArguments ("String"), "#0c");
36 Assert.AreEqual (1, countTypeGenericArguments ("T:System.Collections.Foo<T>"), "#1a");
37 Assert.AreEqual (1, countTypeGenericArguments ("T:System.Foo<T>"), "#1b");
38 Assert.AreEqual (1, countTypeGenericArguments ("T:Foo<T>"), "#1c");
39 Assert.AreEqual (1, countTypeGenericArguments ("Foo<T>"), "#1d");
41 Assert.AreEqual (2, countTypeGenericArguments ("T:System.Collections.Foo<T, U>"), "#2a");
42 Assert.AreEqual (2, countTypeGenericArguments ("T:System.Foo<TKey, TValue>"), "#2b");
43 Assert.AreEqual (2, countTypeGenericArguments ("T:Foo<Something,Else>"), "#2c");
44 Assert.AreEqual (2, countTypeGenericArguments ("Foo<TDelegate,TArray>"), "#2d");
46 Assert.AreEqual (3, countTypeGenericArguments ("T:System.Collections.Foo<T, U, V>"), "#3a");
47 Assert.AreEqual (3, countTypeGenericArguments ("T:System.Foo<TKey, TValue, THash>"), "#3b");
48 Assert.AreEqual (3, countTypeGenericArguments ("T:Foo<Something,Else,Really>"), "#3c");
49 Assert.AreEqual (3, countTypeGenericArguments ("Foo<TDelegate,TArray,TEvent>"), "#3d");
53 public void CountTypeGenericArgumentsTest_Nested ()
55 var realCountTypeGenericArguments = GetTestedMethod<Func<string, int, int>> ("CountTypeGenericArguments");
56 // Since we don't use the optional start index parameters, bypass it by wrapping the func
57 Func<string, int> countTypeGenericArguments = s => realCountTypeGenericArguments (s, 0);
59 Assert.AreEqual (1, countTypeGenericArguments ("T:System.Collections.Foo<T[]>"), "#1a");
60 Assert.AreEqual (1, countTypeGenericArguments ("T:System.Collections.Foo<IList<T>>"), "#1b");
61 Assert.AreEqual (2, countTypeGenericArguments ("T:System.Collections.Foo<T, KeyValuePair<T, U>>"), "#2a");
62 Assert.AreEqual (2, countTypeGenericArguments ("T:System.Collections.Foo<T, KeyValuePair<IProducerConsumerCollection<U>, IEquatable<V>>>"), "#2b");
63 Assert.AreEqual (3, countTypeGenericArguments ("T:System.Collections.Foo<T, IProducerConsumerCollection<U>, IEquatable<V>>"), "#3a");