コード例 #1
0
        public void WhenIsAnonymousType()
        {
            var code  = "public static class StaticClass { void A() { var a = new {}; var b = new { A = 9}; } } ";
            var types = SkuldTest.SimpleGenerateTypeSymbolInfos(code);

            Assert.False(types["StaticClass"].IsAnonymousType);
        }
コード例 #2
0
        public void WhenFields()
        {
            var code  = @"public class ClassT { public int x, y; }";
            var types = SkuldTest.SimpleGenerateTypeSymbolInfos(code);

            Assert.Empty(types["ClassT"].Interfaces);
        }
コード例 #3
0
        public void IsGenericTypeWhenIA()
        {
            var code             = @"public class PublicClass
    { }     public class IA<out T> where T : PublicClass, new()
    {
        public T A() => new IA<PublicClass>();
    }
            ";
            var types            = SkuldTest.SimpleGenerateTypeSymbolInfos(code, false);
            var iaTypeDefinition = types["Norns.Destiny.UT.AOT.Generated.IA<T>"];

            Assert.True(iaTypeDefinition.IsGenericType);
            Assert.Single(iaTypeDefinition.TypeArguments);
            Assert.Single(iaTypeDefinition.TypeParameters);
            var tp = iaTypeDefinition.TypeParameters.First();

            Assert.Equal(0, tp.Ordinal);
            Assert.Equal("T", tp.Name);
            Assert.Equal(RefKindInfo.Out, tp.RefKind);
            Assert.True(tp.HasConstructorConstraint);
            Assert.False(tp.HasReferenceTypeConstraint);
            Assert.False(tp.HasValueTypeConstraint);
            Assert.Single(tp.ConstraintTypes);
            var tpc = tp.ConstraintTypes.First();

            Assert.Equal("PublicClass", tpc.Name);
        }
コード例 #4
0
        public void AccessibilityWhenNestedClass()
        {
            var code  = @"public abstract class AbstractPublicClass
    {
        private class PrivateClass
        { }

        private protected class ProtectedPrivateClass
        { }

        protected class ProtectedClass
        { }

        internal class InternalClass
        { }

        protected internal class ProtectedInternalClass
        { }

        public class PublicClass
        { }
    }";
            var types = SkuldTest.SimpleGenerateTypeSymbolInfos(code);

            Assert.Equal(AccessibilityInfo.Private, types["PrivateClass"].Accessibility);
            Assert.Equal(AccessibilityInfo.Protected, types["ProtectedClass"].Accessibility);
            Assert.Equal(AccessibilityInfo.Internal, types["InternalClass"].Accessibility);
            Assert.Equal(AccessibilityInfo.ProtectedOrInternal, types["ProtectedInternalClass"].Accessibility);
            Assert.Equal(AccessibilityInfo.ProtectedAndInternal, types["ProtectedPrivateClass"].Accessibility);
            Assert.Equal(AccessibilityInfo.Public, types["PublicClass"].Accessibility);
        }
コード例 #5
0
        public void WhenNameAndNamespace()
        {
            var code  = "public class ADD { } ";
            var types = SkuldTest.SimpleGenerateTypeSymbolInfos(code);

            Assert.Equal("Norns.Destiny.UT.AOT.Generated", types["ADD"].Namespace);
        }
コード例 #6
0
        public void AccessibilityWhenNormalClass()
        {
            var code  = "public class PublicClass {} internal class InternalClass{}";
            var types = SkuldTest.SimpleGenerateTypeSymbolInfos(code);

            Assert.Equal(AccessibilityInfo.Internal, types["InternalClass"].Accessibility);
            Assert.Equal(AccessibilityInfo.Public, types["PublicClass"].Accessibility);
        }
コード例 #7
0
        public void WhenIsStatic()
        {
            var code  = "public static class StaticClass {} class NonStaticClass{}";
            var types = SkuldTest.SimpleGenerateTypeSymbolInfos(code);

            Assert.True(types["StaticClass"].IsStatic);
            Assert.False(types["NonStaticClass"].IsStatic);
        }
コード例 #8
0
        public void WhenIsValueType()
        {
            var code  = "public struct MyStruct { } public class ClassT { }";
            var types = SkuldTest.SimpleGenerateTypeSymbolInfos(code);

            Assert.True(types["MyStruct"].IsValueType);
            Assert.False(types["ClassT"].IsValueType);
        }
コード例 #9
0
        public void WhenIsAbstract()
        {
            var code  = "public abstract class AbstractClass { } public class NonAbstractClass { }";
            var types = SkuldTest.SimpleGenerateTypeSymbolInfos(code);

            Assert.True(types["AbstractClass"].IsAbstract);
            Assert.False(types["NonAbstractClass"].IsAbstract);
        }
コード例 #10
0
        public void WhenIsSealed()
        {
            var code  = "public sealed class SealedClass { } public class NonSealedClass { }";
            var types = SkuldTest.SimpleGenerateTypeSymbolInfos(code);

            Assert.True(types["SealedClass"].IsSealed);
            Assert.False(types["NonSealedClass"].IsSealed);
        }
コード例 #11
0
        public void WhenBaseType()
        {
            var code  = @"public class ClassT { } public struct A {} interface IB {}
public class C : ClassT {}";
            var types = SkuldTest.SimpleGenerateTypeSymbolInfos(code);

            Assert.Equal(nameof(Object), types["ClassT"].BaseType.Name);
            Assert.Equal("ClassT", types["C"].BaseType.Name);
            Assert.Equal("ValueType", types["A"].BaseType.Name);
            Assert.Null(types["IB"].BaseType);
        }
コード例 #12
0
        public void WhenInterfaces()
        {
            var code  = @"public class ClassT { } public struct A {} interface IB {}
public class C : IB {}";
            var types = SkuldTest.SimpleGenerateTypeSymbolInfos(code);

            Assert.Empty(types["ClassT"].Interfaces);
            Assert.Single(types["C"].Interfaces);
            Assert.Equal("IB", types["C"].Interfaces.First().Name);
            Assert.Empty(types["A"].Interfaces);
            Assert.Empty(types["IB"].Interfaces);
            Assert.True(types["IB"].IsInterface);
        }
コード例 #13
0
        public void WhenIsGenericType()
        {
            var code  = @"public class ClassT { }

public class GenericClass<T> where T : ClassT, new()
{
    public T A() => default;
}";
            var types = SkuldTest.SimpleGenerateTypeSymbolInfos(code);

            Assert.True(types["GenericClass"].IsGenericType);
            Assert.True(types["GenericClass"].IsClass);
            Assert.False(types["ClassT"].IsGenericType);
        }
コード例 #14
0
        public void WhenAttribute()
        {
            var code  = @"
using Xunit;
[Collection(""a"")]
        public class PublicClass
        { }
    }";
            var attrs = SkuldTest.SimpleGenerateTypeSymbolInfos(code).First().Value.Attributes;

            Assert.Single(attrs);
            var a = attrs.First();

            Assert.Equal(@"Xunit.CollectionAttribute(""a"")", a.FullName);
            Assert.Equal(@"Xunit.CollectionAttribute", a.AttributeType.FullName);
            Assert.Single(a.ConstructorArguments);
            var ca = a.ConstructorArguments.First();

            Assert.Equal("a", ca.Value);
        }
コード例 #15
0
        public void MethodWhenHasReturnValue()
        {
            var code  = @"
using System.Threading.Tasks;
    public interface IC
    {
        int AddOne(int v);
        void AddVoid(int v);
        Task AddTask(int v);
Task<int> AddVTask(int v);
ValueTask<int> AddValueTask(int v);
    }";
            var types = SkuldTest.SimpleGenerateTypeSymbolInfos(code);
            var ms    = types["IC"].Members
                        .Select(i => i as IMethodSymbolInfo)
                        .Where(i => i != null)
                        .ToDictionary(i => i.FullName, i => i);
            var m = ms["Norns.Destiny.UT.AOT.Generated.IC.AddOne(int)"];

            Assert.True(m.HasReturnValue);
            Assert.False(m.IsAsync);

            m = ms["Norns.Destiny.UT.AOT.Generated.IC.AddVoid(int)"];
            Assert.False(m.HasReturnValue);
            Assert.False(m.IsAsync);

            m = ms["Norns.Destiny.UT.AOT.Generated.IC.AddTask(int)"];
            Assert.False(m.HasReturnValue);
            Assert.True(m.IsAsync);

            m = ms["Norns.Destiny.UT.AOT.Generated.IC.AddVTask(int)"];
            Assert.True(m.HasReturnValue);
            Assert.True(m.IsAsync);

            m = ms["Norns.Destiny.UT.AOT.Generated.IC.AddValueTask(int)"];
            Assert.True(m.HasReturnValue);
            Assert.True(m.IsAsync);
        }
コード例 #16
0
        public void WhenStructFields()
        {
            var code   = @"public unsafe struct StructFieldTest
        {
            internal fixed char name[30];
        }";
            var types  = SkuldTest.SimpleGenerateTypeSymbolInfos(code);
            var fields = types["StructFieldTest"].Members
                         .Select(i => i as IFieldSymbolInfo)
                         .Where(i => i != null)
                         .ToDictionary(i => i.Name, i => i);

            Assert.Single(fields);
            var f = fields["name"];

            Assert.False(f.HasConstantValue);
            Assert.False(f.IsConst);
            Assert.False(f.IsReadOnly);
            Assert.False(f.IsVolatile);
            Assert.True(f.IsFixedSizeBuffer);
            Assert.False(f.IsStatic);
            Assert.Equal(AccessibilityInfo.Internal, f.Accessibility);
        }
コード例 #17
0
        public void WhenMethods()
        {
            var code  = @"
    public static class Sta
    {
        public static int A(this int d) => d;
    }
public abstract class A
        {
            private void PrivateM()
            {
            }

            internal int InternalM()
            {
                return default;
            }

            protected virtual (int v, long s) ProtectedM()
            {
                return default;
            }

            protected internal abstract string PIS();

            protected private string PPS()
            {
                return default;
            }

            public T GetT<T>() where T : class
            {
                return default;
            }

            public Task GetTask()
            {
                return default;
            }

            public override string ToString()
            {
                return base.ToString();
            }
        }

        public class B : A
        {
            protected sealed override (int v, long s) ProtectedM()
            {
                return base.ProtectedM();
            }

            protected internal override string PIS()
            {
                return default;
            }

            public new Task GetTask()
            {
                return default;
            }
        }";
            var types = SkuldTest.SimpleGenerateTypeSymbolInfos(code);
            var ms    = types["A"].Members
                        .Select(i => i as IMethodSymbolInfo)
                        .Where(i => i != null)
                        .ToDictionary(i => i.FullName, i => i);
            var m = ms["Norns.Destiny.UT.AOT.Generated.A.PrivateM()"];

            Assert.Equal(AccessibilityInfo.Private, m.Accessibility);
            Assert.Empty(m.Parameters);
            Assert.Empty(m.TypeParameters);
            Assert.False(m.IsGenericMethod);
            Assert.False(m.IsExtensionMethod);
            Assert.False(m.IsStatic);
            Assert.False(m.IsSealed);
            Assert.False(m.IsAbstract);
            Assert.False(m.IsOverride);
            Assert.False(m.IsVirtual);
            Assert.Equal("void", m.ReturnType.FullName);

            m = ms["Norns.Destiny.UT.AOT.Generated.A.InternalM()"];
            Assert.Equal(AccessibilityInfo.Internal, m.Accessibility);
            Assert.Empty(m.Parameters);
            Assert.Empty(m.TypeParameters);
            Assert.False(m.IsGenericMethod);
            Assert.False(m.IsExtensionMethod);
            Assert.False(m.IsStatic);
            Assert.False(m.IsSealed);
            Assert.False(m.IsAbstract);
            Assert.False(m.IsOverride);
            Assert.False(m.IsVirtual);
            Assert.Equal("int", m.ReturnType.FullName);

            m = ms["Norns.Destiny.UT.AOT.Generated.A.ProtectedM()"];
            Assert.Equal(AccessibilityInfo.Protected, m.Accessibility);
            Assert.Empty(m.Parameters);
            Assert.Empty(m.TypeParameters);
            Assert.False(m.IsGenericMethod);
            Assert.False(m.IsExtensionMethod);
            Assert.False(m.IsStatic);
            Assert.False(m.IsSealed);
            Assert.False(m.IsAbstract);
            Assert.False(m.IsOverride);
            Assert.True(m.IsVirtual);
            Assert.Equal("ValueTuple", m.ReturnType.Name);

            m = ms["Norns.Destiny.UT.AOT.Generated.A.PIS()"];
            Assert.Equal(AccessibilityInfo.ProtectedOrInternal, m.Accessibility);
            Assert.Empty(m.Parameters);
            Assert.Empty(m.TypeParameters);
            Assert.False(m.IsGenericMethod);
            Assert.False(m.IsExtensionMethod);
            Assert.False(m.IsStatic);
            Assert.False(m.IsSealed);
            Assert.True(m.IsAbstract);
            Assert.False(m.IsOverride);
            Assert.False(m.IsVirtual);
            Assert.Equal("String", m.ReturnType.Name);

            m = ms["Norns.Destiny.UT.AOT.Generated.A.PPS()"];
            Assert.Equal(AccessibilityInfo.ProtectedAndInternal, m.Accessibility);
            Assert.Empty(m.Parameters);
            Assert.Empty(m.TypeParameters);
            Assert.False(m.IsGenericMethod);
            Assert.False(m.IsExtensionMethod);
            Assert.False(m.IsStatic);
            Assert.False(m.IsSealed);
            Assert.False(m.IsAbstract);
            Assert.False(m.IsOverride);
            Assert.False(m.IsVirtual);
            Assert.Equal("String", m.ReturnType.Name);

            m = ms["Norns.Destiny.UT.AOT.Generated.A.ToString()"];
            Assert.Equal(AccessibilityInfo.Public, m.Accessibility);
            Assert.Empty(m.Parameters);
            Assert.Empty(m.TypeParameters);
            Assert.False(m.IsGenericMethod);
            Assert.False(m.IsExtensionMethod);
            Assert.False(m.IsStatic);
            Assert.False(m.IsSealed);
            Assert.False(m.IsAbstract);
            Assert.True(m.IsOverride);
            Assert.False(m.IsVirtual);
            Assert.Equal("String", m.ReturnType.Name);

            m = ms["Norns.Destiny.UT.AOT.Generated.A.GetTask()"];
            Assert.Equal(AccessibilityInfo.Public, m.Accessibility);
            Assert.Empty(m.Parameters);
            Assert.Empty(m.TypeParameters);
            Assert.False(m.IsGenericMethod);
            Assert.False(m.IsExtensionMethod);
            Assert.False(m.IsStatic);
            Assert.False(m.IsSealed);
            Assert.False(m.IsAbstract);
            Assert.False(m.IsOverride);
            Assert.False(m.IsVirtual);
            Assert.Equal("Task", m.ReturnType.Name);

            m = ms["Norns.Destiny.UT.AOT.Generated.A.GetT<T>()"];
            Assert.Equal(AccessibilityInfo.Public, m.Accessibility);
            Assert.Empty(m.Parameters);
            Assert.True(m.IsGenericMethod);
            Assert.False(m.IsExtensionMethod);
            Assert.False(m.IsStatic);
            Assert.False(m.IsSealed);
            Assert.False(m.IsAbstract);
            Assert.False(m.IsOverride);
            Assert.False(m.IsVirtual);
            Assert.Equal("T", m.ReturnType.Name);
            Assert.Single(m.TypeParameters);
            Assert.True(m.TypeParameters.First().HasReferenceTypeConstraint);

            ms = types["B"].Members
                 .Select(i => i as IMethodSymbolInfo)
                 .Where(i => i != null)
                 .ToDictionary(i => i.FullName, i => i);
            m = ms["Norns.Destiny.UT.AOT.Generated.B.ProtectedM()"];
            Assert.Equal(AccessibilityInfo.Protected, m.Accessibility);
            Assert.Empty(m.Parameters);
            Assert.Empty(m.TypeParameters);
            Assert.False(m.IsGenericMethod);
            Assert.False(m.IsExtensionMethod);
            Assert.False(m.IsStatic);
            Assert.True(m.IsSealed);
            Assert.False(m.IsAbstract);
            Assert.True(m.IsOverride);
            Assert.False(m.IsVirtual);
            Assert.Equal("ValueTuple", m.ReturnType.Name);

            m = ms["Norns.Destiny.UT.AOT.Generated.B.PIS()"];
            Assert.Equal(AccessibilityInfo.ProtectedOrInternal, m.Accessibility);
            Assert.Empty(m.Parameters);
            Assert.Empty(m.TypeParameters);
            Assert.False(m.IsGenericMethod);
            Assert.False(m.IsExtensionMethod);
            Assert.False(m.IsStatic);
            Assert.False(m.IsSealed);
            Assert.False(m.IsAbstract);
            Assert.True(m.IsOverride);
            Assert.False(m.IsVirtual);
            Assert.Equal("String", m.ReturnType.Name);

            m = ms["Norns.Destiny.UT.AOT.Generated.B.GetTask()"];
            Assert.Equal(AccessibilityInfo.Public, m.Accessibility);
            Assert.Empty(m.Parameters);
            Assert.Empty(m.TypeParameters);
            Assert.False(m.IsGenericMethod);
            Assert.False(m.IsExtensionMethod);
            Assert.False(m.IsStatic);
            Assert.False(m.IsSealed);
            Assert.False(m.IsAbstract);
            Assert.False(m.IsOverride);
            Assert.False(m.IsVirtual);
            Assert.Equal("Task", m.ReturnType.Name);

            ms = types["Sta"].Members
                 .Select(i => i as IMethodSymbolInfo)
                 .Where(i => i != null)
                 .ToDictionary(i => i.FullName, i => i);
            m = ms["Norns.Destiny.UT.AOT.Generated.Sta.A(int)"];
            Assert.Equal(AccessibilityInfo.Public, m.Accessibility);
            Assert.Empty(m.TypeParameters);
            Assert.False(m.IsGenericMethod);
            Assert.True(m.IsExtensionMethod);
            Assert.True(m.IsStatic);
            Assert.False(m.IsSealed);
            Assert.False(m.IsAbstract);
            Assert.False(m.IsOverride);
            Assert.False(m.IsVirtual);
            Assert.Equal("Int32", m.ReturnType.Name);
            Assert.Single(m.Parameters);
            Assert.Equal("d", m.Parameters.First().Name);
        }
コード例 #18
0
        public void WhenClassFields()
        {
            var code   = @"public class FieldTest
        {
            public const int A = 3;
            internal static readonly string B = ""3"";
            protected volatile string C;
        protected internal long D;
        private protected long E;
        private long F;
    }";
            var types  = SkuldTest.SimpleGenerateTypeSymbolInfos(code);
            var fields = types["FieldTest"].Members
                         .Select(i => i as IFieldSymbolInfo)
                         .Where(i => i != null)
                         .ToDictionary(i => i.Name, i => i);

            Assert.Equal(6, fields.Count);
            var f = fields["A"];

            Assert.Equal(3, f.ConstantValue);
            Assert.True(f.IsConst);
            Assert.False(f.IsReadOnly);
            Assert.False(f.IsVolatile);
            Assert.False(f.IsFixedSizeBuffer);
            Assert.True(f.HasConstantValue);
            Assert.True(f.IsStatic);
            Assert.Equal(AccessibilityInfo.Public, f.Accessibility);

            f = fields["B"];
            Assert.False(f.HasConstantValue);
            Assert.False(f.IsConst);
            Assert.True(f.IsReadOnly);
            Assert.False(f.IsVolatile);
            Assert.False(f.IsFixedSizeBuffer);
            Assert.True(f.IsStatic);
            Assert.Equal(AccessibilityInfo.Internal, f.Accessibility);

            f = fields["C"];
            Assert.False(f.HasConstantValue);
            Assert.False(f.IsConst);
            Assert.False(f.IsReadOnly);
            Assert.True(f.IsVolatile);
            Assert.False(f.IsFixedSizeBuffer);
            Assert.False(f.IsStatic);
            Assert.Equal(AccessibilityInfo.Protected, f.Accessibility);

            f = fields["D"];
            Assert.False(f.HasConstantValue);
            Assert.False(f.IsConst);
            Assert.False(f.IsReadOnly);
            Assert.False(f.IsVolatile);
            Assert.False(f.IsFixedSizeBuffer);
            Assert.False(f.IsStatic);
            Assert.Equal(AccessibilityInfo.ProtectedOrInternal, f.Accessibility);

            f = fields["E"];
            Assert.False(f.HasConstantValue);
            Assert.False(f.IsConst);
            Assert.False(f.IsReadOnly);
            Assert.False(f.IsVolatile);
            Assert.False(f.IsFixedSizeBuffer);
            Assert.False(f.IsStatic);
            Assert.Equal(AccessibilityInfo.ProtectedAndInternal, f.Accessibility);

            f = fields["F"];
            Assert.False(f.HasConstantValue);
            Assert.False(f.IsConst);
            Assert.False(f.IsReadOnly);
            Assert.False(f.IsVolatile);
            Assert.False(f.IsFixedSizeBuffer);
            Assert.False(f.IsStatic);
            Assert.Equal(AccessibilityInfo.Private, f.Accessibility);
        }