using System; using System.IO; using System.Linq; using System.Reflection; using System.Collections.Generic; using NUnit.Framework; using Monodoc; using Monodoc.Generators; namespace MonoTests.Monodoc { [TestFixture] public class EcmaDocTest { // Because EcmaDoc is internal and we can't use InternalsVisibleTo since test assemblies aren't // signed/strong-named by the build, we have to resort to reflection TDelegate GetTestedMethod (string methodName) { var ecmaDoc = Type.GetType ("Monodoc.Providers.EcmaDoc, monodoc, PublicKey=0738eb9f132ed756"); return (TDelegate)(object)Delegate.CreateDelegate (typeof (TDelegate), ecmaDoc.GetMethod (methodName)); } [Test] public void CountTypeGenericArgumentsTest () { var realCountTypeGenericArguments = GetTestedMethod> ("CountTypeGenericArguments"); // Since we don't use the optional start index parameters, bypass it by wrapping the func Func countTypeGenericArguments = s => realCountTypeGenericArguments (s, 0); Assert.AreEqual (0, countTypeGenericArguments ("T:System.String"), "#0a"); Assert.AreEqual (0, countTypeGenericArguments ("T:String"), "#0b"); Assert.AreEqual (0, countTypeGenericArguments ("String"), "#0c"); Assert.AreEqual (1, countTypeGenericArguments ("T:System.Collections.Foo"), "#1a"); Assert.AreEqual (1, countTypeGenericArguments ("T:System.Foo"), "#1b"); Assert.AreEqual (1, countTypeGenericArguments ("T:Foo"), "#1c"); Assert.AreEqual (1, countTypeGenericArguments ("Foo"), "#1d"); Assert.AreEqual (2, countTypeGenericArguments ("T:System.Collections.Foo"), "#2a"); Assert.AreEqual (2, countTypeGenericArguments ("T:System.Foo"), "#2b"); Assert.AreEqual (2, countTypeGenericArguments ("T:Foo"), "#2c"); Assert.AreEqual (2, countTypeGenericArguments ("Foo"), "#2d"); Assert.AreEqual (3, countTypeGenericArguments ("T:System.Collections.Foo"), "#3a"); Assert.AreEqual (3, countTypeGenericArguments ("T:System.Foo"), "#3b"); Assert.AreEqual (3, countTypeGenericArguments ("T:Foo"), "#3c"); Assert.AreEqual (3, countTypeGenericArguments ("Foo"), "#3d"); } [Test] public void CountTypeGenericArgumentsTest_Nested () { var realCountTypeGenericArguments = GetTestedMethod> ("CountTypeGenericArguments"); // Since we don't use the optional start index parameters, bypass it by wrapping the func Func countTypeGenericArguments = s => realCountTypeGenericArguments (s, 0); Assert.AreEqual (1, countTypeGenericArguments ("T:System.Collections.Foo"), "#1a"); Assert.AreEqual (1, countTypeGenericArguments ("T:System.Collections.Foo>"), "#1b"); Assert.AreEqual (2, countTypeGenericArguments ("T:System.Collections.Foo>"), "#2a"); Assert.AreEqual (2, countTypeGenericArguments ("T:System.Collections.Foo, IEquatable>>"), "#2b"); Assert.AreEqual (3, countTypeGenericArguments ("T:System.Collections.Foo, IEquatable>"), "#3a"); } } }