Exemple #1
0
        public void IndexerDeclarationTest()
        {
            IndexerDeclaration id = ParseUtilCSharp.ParseTypeMember <IndexerDeclaration>("public int this[int a, string b] { get { } protected set { } }");

            Assert.AreEqual(2, id.Parameters.Count());
            Assert.IsNotNull(id.Getter, "No get region found!");
            Assert.IsNotNull(id.Setter, "No set region found!");
            Assert.AreEqual(Modifiers.Public, id.Modifiers);
            Assert.AreEqual(Modifiers.None, id.Getter.Modifiers);
            Assert.AreEqual(Modifiers.Protected, id.Setter.Modifiers);
        }
        public void IncompleteConstraintsTest()
        {
            MethodDeclaration md = ParseUtilCSharp.ParseTypeMember <MethodDeclaration>(
                "void a<T>() where T { }", true                 // expect errors
                );

            Assert.AreEqual("a", md.Name);
            Assert.AreEqual(1, md.TypeParameters.Count);
            Assert.AreEqual("T", md.TypeParameters.Single().Name);
            Assert.AreEqual(0, md.Constraints.Count());
        }
Exemple #3
0
        public void VoidExtensionMethodTest()
        {
            MethodDeclaration md = ParseUtilCSharp.ParseTypeMember <MethodDeclaration>(
                "public static void Print(this string s) { Console.WriteLine(s); }"
                );

            Assert.AreEqual("Print", md.Name);
            Assert.AreEqual("s", md.Parameters.First().Name);
            Assert.AreEqual(ParameterModifier.This, md.Parameters.First().ParameterModifier);
            Assert.AreEqual("string", ((PrimitiveType)md.Parameters.First().Type).Keyword);
            Assert.IsTrue(md.IsExtensionMethod);
        }
Exemple #4
0
        public void ExtensionMethodTest()
        {
            MethodDeclaration md = ParseUtilCSharp.ParseTypeMember <MethodDeclaration>(
                "public static int ToInt32(this string s) { return int.Parse(s); }"
                );

            Assert.AreEqual("ToInt32", md.Name);
            Assert.AreEqual("s", md.Parameters.First().Name);
            Assert.AreEqual(ParameterModifier.This, md.Parameters.First().ParameterModifier);
            Assert.AreEqual("string", ((PrimitiveType)md.Parameters.First().Type).Keyword);
            Assert.IsTrue(md.IsExtensionMethod);
        }
        public void PropertyImplementingGenericInterfaceTest()
        {
            PropertyDeclaration pd = ParseUtilCSharp.ParseTypeMember <PropertyDeclaration>("int MyInterface<string>.MyProperty { get {} } ");

            Assert.AreEqual("MyProperty", pd.Name);
            Assert.IsFalse(pd.Getter.IsNull);
            Assert.IsTrue(pd.Setter.IsNull);

            Assert.IsNotNull(new SimpleType {
                Identifier = "MyInterface", TypeArguments = { new PrimitiveType("string") }
            }.Match(pd.PrivateImplementationType));
        }
Exemple #6
0
        public void ExtensionMethodWithAttributeTest()
        {
            MethodDeclaration md = ParseUtilCSharp.ParseTypeMember <MethodDeclaration>(
                "public static int ToInt32([Attr] this string s) { return int.Parse(s); }"
                );

            Assert.AreEqual("ToInt32", md.Name);
            Assert.IsTrue(md.IsExtensionMethod);
            Assert.AreEqual("s", md.Parameters.Single().Name);
            Assert.AreEqual(KnownTypeCode.String, ((PrimitiveType)md.Parameters.Single().Type).KnownTypeCode);
            Assert.AreEqual(1, md.Parameters.Single().Attributes.Count);
        }
Exemple #7
0
        public void MethodWithEmptyAssignmentErrorInBody()
        {
            MethodDeclaration md = ParseUtilCSharp.ParseTypeMember <MethodDeclaration>(
                "void A ()\n" +
                "{\n" +
                "int a = 3;\n" +
                " = 4;\n" +
                "}", true                 // expect errors
                );

            Assert.AreEqual("A", md.Name);
            Assert.AreEqual(new TextLocation(2, 1), md.Body.StartLocation);
            Assert.AreEqual(new TextLocation(5, 2), md.Body.EndLocation);
        }
Exemple #8
0
        public void MethodWithModifiersRegionTest()
        {
            const string      program = @"
		public static void MyMethod()
		{
			OtherMethod();
		}
";
            MethodDeclaration md      = ParseUtilCSharp.ParseTypeMember <MethodDeclaration>(program);

            Assert.AreEqual(2, md.StartLocation.Line, "StartLocation.Y");
            Assert.AreEqual(5, md.EndLocation.Line, "EndLocation.Y");
            Assert.AreEqual(3, md.StartLocation.Column, "StartLocation.X");
            Assert.AreEqual(4, md.EndLocation.Column, "EndLocation.X");
        }
        public void UnsafeDestructorDeclarationTest()
        {
            DestructorDeclaration dd = ParseUtilCSharp.ParseTypeMember <DestructorDeclaration>("unsafe ~MyClass() {}");

            Assert.AreEqual(Modifiers.Unsafe, dd.Modifiers);
        }
        public void ExternDestructorDeclarationTest()
        {
            DestructorDeclaration dd = ParseUtilCSharp.ParseTypeMember <DestructorDeclaration>("extern ~MyClass();");

            Assert.AreEqual(Modifiers.Extern, dd.Modifiers);
        }
 public void DestructorDeclarationTest()
 {
     ParseUtilCSharp.ParseTypeMember <DestructorDeclaration>("~MyClass() {}");
 }
        public void ConstructorDeclarationTest1()
        {
            ConstructorDeclaration cd = ParseUtilCSharp.ParseTypeMember <ConstructorDeclaration>("MyClass() {}");

            Assert.IsTrue(cd.Initializer.IsNull);
        }
 public void InvalidOperatorTrueDeclaration()
 {
     ParseUtilCSharp.ParseTypeMember <OperatorDeclaration>("public static implicit operator true(MyBool b) {}", expectErrors: true);
 }