NArrange Visual Basic parser implementation.
Inheritance: NArrange.Core.CodeParser
Esempio n. 1
0
        public void ExpectedBlockCloseTest()
        {
            StringReader reader = new StringReader(
                "namespace SampleNamespace");

            VBParser parser = new VBParser();
            parser.Parse(reader);
        }
Esempio n. 2
0
        public void ParseSingleNamespaceTest()
        {
            VBParser parser = new VBParser();

            VBTestFile testFile = VBTestUtilities.GetSingleNamespaceFile();
            using (TextReader reader = testFile.GetReader())
            {
                ReadOnlyCollection<ICodeElement> elements = parser.Parse(reader);

                Assert.IsNotNull(elements, "Code element collection should not be null.");
                Assert.AreEqual(1, elements.Count, "An unexpected number of elements were parsed.");

                NamespaceElement namespaceElement = elements[0] as NamespaceElement;
                Assert.IsNotNull(namespaceElement, "Expected a NamespaceElement.");
                Assert.AreEqual("SampleNamespace", namespaceElement.Name, "Unexpected namespace name.");
                Assert.IsNotNull(namespaceElement.Children, "Children collection should not be null.");
                Assert.AreEqual(0, namespaceElement.Children.Count, "Children collection should not be null.");
            }
        }
Esempio n. 3
0
        public void ParseAssemblyAttributesTest()
        {
            VBParser parser = new VBParser();

            VBTestFile testFile = VBTestUtilities.GetAssemblyAttributesFile();
            using (TextReader reader = testFile.GetReader())
            {
                ReadOnlyCollection<ICodeElement> elements = parser.Parse(reader);

                Assert.IsNotNull(elements, "Code element collection should not be null.");
                Assert.AreEqual(15, elements.Count, "An unexpected number of elements were parsed.");

                //
                // Using statements
                //
                UsingElement usingElement;

                usingElement = elements[0] as UsingElement;
                Assert.IsNotNull(usingElement, "Element is not a UsingElement.");
                Assert.AreEqual("System.Reflection", usingElement.Name, "Unexpected name.");

                usingElement = elements[1] as UsingElement;
                Assert.IsNotNull(usingElement, "Element is not a UsingElement.");
                Assert.AreEqual("System.Runtime.CompilerServices", usingElement.Name, "Unexpected name.");

                usingElement = elements[2] as UsingElement;
                Assert.IsNotNull(usingElement, "Element is not a UsingElement.");
                Assert.AreEqual("System.Runtime.InteropServices", usingElement.Name, "Unexpected name.");

                //
                // Attributes
                //
                AttributeElement attributeElement;

                attributeElement = elements[3] as AttributeElement;
                Assert.IsNotNull(attributeElement, "Element is not an AttributeElement.");
                Assert.AreEqual("assembly", attributeElement.Target, "Unexpected attribute target.");
                Assert.AreEqual("AssemblyTitle", attributeElement.Name, "Unexpected attribute name.");
                Assert.AreEqual("\"NArrange.Core.Tests\"", attributeElement.BodyText, "Unexpected attribute text.");
                Assert.AreEqual(3, attributeElement.HeaderComments.Count,
                    "An unexpected number of header comment lines were parsed.");

                attributeElement = elements[4] as AttributeElement;
                Assert.IsNotNull(attributeElement, "Element is not an AttributeElement.");
                Assert.AreEqual("assembly", attributeElement.Target, "Unexpected attribute target.");
                Assert.AreEqual("AssemblyDescription", attributeElement.Name, "Unexpected attribute name.");
                Assert.AreEqual("\"\"", attributeElement.BodyText, "Unexpected attribute text.");
                Assert.AreEqual(0, attributeElement.HeaderComments.Count,
                    "An unexpected number of header comment lines were parsed.");

                attributeElement = elements[5] as AttributeElement;
                Assert.IsNotNull(attributeElement, "Element is not an AttributeElement.");
                Assert.AreEqual("assembly", attributeElement.Target, "Unexpected attribute target.");
                Assert.AreEqual("AssemblyConfiguration", attributeElement.Name, "Unexpected attribute name.");
                Assert.AreEqual("\"\"", attributeElement.BodyText, "Unexpected attribute text.");
                Assert.AreEqual(0, attributeElement.HeaderComments.Count,
                    "An unexpected number of header comment lines were parsed.");

                attributeElement = elements[6] as AttributeElement;
                Assert.IsNotNull(attributeElement, "Element is not an AttributeElement.");
                Assert.AreEqual("assembly", attributeElement.Target, "Unexpected attribute target.");
                Assert.AreEqual("AssemblyCompany", attributeElement.Name, "Unexpected attribute name.");
                Assert.AreEqual("\"\"", attributeElement.BodyText, "Unexpected attribute text.");
                Assert.AreEqual(0, attributeElement.HeaderComments.Count,
                    "An unexpected number of header comment lines were parsed.");

                attributeElement = elements[7] as AttributeElement;
                Assert.IsNotNull(attributeElement, "Element is not an AttributeElement.");
                Assert.AreEqual("assembly", attributeElement.Target, "Unexpected attribute target.");
                Assert.AreEqual("AssemblyProduct", attributeElement.Name, "Unexpected attribute name.");
                Assert.AreEqual("\"NArrange.Core.Tests\"", attributeElement.BodyText, "Unexpected attribute text.");
                Assert.AreEqual(0, attributeElement.HeaderComments.Count,
                    "An unexpected number of header comment lines were parsed.");

                attributeElement = elements[8] as AttributeElement;
                Assert.IsNotNull(attributeElement, "Element is not an AttributeElement.");
                Assert.AreEqual("assembly", attributeElement.Target, "Unexpected attribute target.");
                Assert.AreEqual("AssemblyCopyright", attributeElement.Name, "Unexpected attribute name.");
                Assert.AreEqual("\"Copyright ©  2007\"", attributeElement.BodyText, "Unexpected attribute text.");
                Assert.AreEqual(0, attributeElement.HeaderComments.Count,
                    "An unexpected number of header comment lines were parsed.");

                attributeElement = elements[9] as AttributeElement;
                Assert.IsNotNull(attributeElement, "Element is not an AttributeElement.");
                Assert.AreEqual("assembly", attributeElement.Target, "Unexpected attribute target.");
                Assert.AreEqual("AssemblyTrademark", attributeElement.Name, "Unexpected attribute name.");
                Assert.AreEqual("\"\"", attributeElement.BodyText, "Unexpected attribute text.");
                Assert.AreEqual(0, attributeElement.HeaderComments.Count,
                    "An unexpected number of header comment lines were parsed.");

                attributeElement = elements[10] as AttributeElement;
                Assert.IsNotNull(attributeElement, "Element is not an AttributeElement.");
                Assert.AreEqual("assembly", attributeElement.Target, "Unexpected attribute target.");
                Assert.AreEqual("AssemblyCulture", attributeElement.Name, "Unexpected attribute name.");
                Assert.AreEqual("\"\"", attributeElement.BodyText, "Unexpected attribute text.");
                Assert.AreEqual(0, attributeElement.HeaderComments.Count,
                    "An unexpected number of header comment lines were parsed.");

                attributeElement = elements[11] as AttributeElement;
                Assert.IsNotNull(attributeElement, "Element is not an AttributeElement.");
                Assert.AreEqual("assembly", attributeElement.Target, "Unexpected attribute target.");
                Assert.AreEqual("ComVisible", attributeElement.Name, "Unexpected attribute name.");
                Assert.AreEqual("False", attributeElement.BodyText, "Unexpected attribute text.");
                Assert.AreEqual(3, attributeElement.HeaderComments.Count,
                    "An unexpected number of header comment lines were parsed.");

                attributeElement = elements[12] as AttributeElement;
                Assert.IsNotNull(attributeElement, "Element is not an AttributeElement.");
                Assert.AreEqual("assembly", attributeElement.Target, "Unexpected attribute target.");
                Assert.AreEqual("Guid", attributeElement.Name, "Unexpected attribute name.");
                Assert.AreEqual("\"def01aba-79c5-4082-9522-e570c52a2df1\"", attributeElement.BodyText, "Unexpected attribute text.");
                Assert.AreEqual(1, attributeElement.HeaderComments.Count,
                    "An unexpected number of header comment lines were parsed.");

                attributeElement = elements[13] as AttributeElement;
                Assert.IsNotNull(attributeElement, "Element is not an AttributeElement.");
                Assert.AreEqual("assembly", attributeElement.Target, "Unexpected attribute target.");
                Assert.AreEqual("AssemblyVersion", attributeElement.Name, "Unexpected attribute name.");
                Assert.AreEqual("\"1.0.0.0\"", attributeElement.BodyText, "Unexpected attribute text.");
                Assert.AreEqual(9, attributeElement.HeaderComments.Count,
                    "An unexpected number of header comment lines were parsed.");

                attributeElement = elements[14] as AttributeElement;
                Assert.IsNotNull(attributeElement, "Element is not an AttributeElement.");
                Assert.AreEqual("assembly", attributeElement.Target, "Unexpected attribute target.");
                Assert.AreEqual("AssemblyFileVersion", attributeElement.Name, "Unexpected attribute name.");
                Assert.AreEqual("\"1.0.0.0\"", attributeElement.BodyText, "Unexpected attribute text.");
                Assert.AreEqual(0, attributeElement.HeaderComments.Count,
                    "An unexpected number of header comment lines were parsed.");
            }
        }
Esempio n. 4
0
        public void ParseClassUnspecifiedAccessTest()
        {
            StringReader reader = new StringReader(
                "class Test\r\n" +
                "class Nested\r\n" +
                "end class\r\n" +
                "end class");

            VBParser parser = new VBParser();
            ReadOnlyCollection<ICodeElement> elements = parser.Parse(reader);

            Assert.AreEqual(1, elements.Count, "An unexpected number of elements were parsed.");
            TypeElement typeElement = elements[0] as TypeElement;
            Assert.IsNotNull(typeElement, "Element is not a TypeElement.");
            Assert.AreEqual("Test", typeElement.Name, "Unexpected name.");
            Assert.AreEqual(CodeAccess.None, typeElement.Access, "Unexpected code access.");
            Assert.AreEqual(TypeElementType.Class, typeElement.Type, "Unexpected type element type.");

            Assert.AreEqual(1, typeElement.Children.Count, "An unexpected number of child elements were parsed.");
            TypeElement nestedtypeElement = typeElement.Children[0] as TypeElement;
            Assert.IsNotNull(nestedtypeElement, "Element is not a TypeElement.");
            Assert.AreEqual("Nested", nestedtypeElement.Name, "Unexpected name.");
            Assert.AreEqual(CodeAccess.None, nestedtypeElement.Access, "Unexpected code access.");
            Assert.AreEqual(TypeElementType.Class, nestedtypeElement.Type, "Unexpected type element type.");
        }
Esempio n. 5
0
        public void ParseClassUnclosedTypeParameterTest()
        {
            StringReader reader = new StringReader(
                "Public Class Test(Of T\r\nEnd Class");

            VBParser parser = new VBParser();
            ReadOnlyCollection<ICodeElement> elements = parser.Parse(reader);
        }
Esempio n. 6
0
        public void ParseClassSimpleTest()
        {
            StringReader reader = new StringReader(
                "public class Test\r\n" +
                "end class");

            VBParser parser = new VBParser();
            ReadOnlyCollection<ICodeElement> elements = parser.Parse(reader);

            Assert.AreEqual(1, elements.Count, "An unexpected number of elements were parsed.");
            TypeElement typeElement = elements[0] as TypeElement;
            Assert.IsNotNull(typeElement, "Element is not a TypeElement.");
            Assert.AreEqual("Test", typeElement.Name, "Unexpected name.");
            Assert.AreEqual(CodeAccess.Public, typeElement.Access, "Unexpected code access.");
            Assert.AreEqual(TypeElementType.Class, typeElement.Type, "Unexpected type element type.");
        }
Esempio n. 7
0
        public void ParseClassMultipleTypeParameterTest3()
        {
            StringReader reader = new StringReader(
                "Partial Public Class NewClass(Of T as {new, IDisposable}, S as new, R)\r\n" +
                "End Class");

            VBParser parser = new VBParser();
            ReadOnlyCollection<ICodeElement> elements = parser.Parse(reader);

            TypeElement classElement = elements[0] as TypeElement;
            Assert.IsNotNull(classElement, "Expected a class element");
            Assert.AreEqual(TypeElementType.Class, classElement.Type, "Expected a class.");
            Assert.AreEqual("NewClass", classElement.Name, "Unexpected class name.");
            Assert.AreEqual(CodeAccess.Public, classElement.Access, "Unexpected access.");
            Assert.IsTrue(classElement.IsPartial, "Expected a partial class.");
            Assert.AreEqual(3, classElement.TypeParameters.Count, "Unexpected number of type parameters.");
            Assert.AreEqual("T", classElement.TypeParameters[0].Name);
            Assert.AreEqual(2, classElement.TypeParameters[0].Constraints.Count);
            Assert.AreEqual("new", classElement.TypeParameters[0].Constraints[0]);
            Assert.AreEqual("IDisposable", classElement.TypeParameters[0].Constraints[1]);
            Assert.AreEqual("S", classElement.TypeParameters[1].Name);
            Assert.AreEqual(1, classElement.TypeParameters[1].Constraints.Count);
            Assert.AreEqual("new", classElement.TypeParameters[1].Constraints[0]);
            Assert.AreEqual("R", classElement.TypeParameters[2].Name);
            Assert.AreEqual(0, classElement.TypeParameters[2].Constraints.Count);
        }
Esempio n. 8
0
        public void ParseClassMultipleTypeParameterInvalidTest3()
        {
            StringReader reader = new StringReader(
                "Partial Public Class NewClass(Of T as new, IDisposable, S as new, IComparable})\r\n" +
                "End Class");

            VBParser parser = new VBParser();
            ReadOnlyCollection<ICodeElement> elements = parser.Parse(reader);

            Assert.Fail();
        }
Esempio n. 9
0
        public void ParseUsingEmptyTypeOrNamespaceTest()
        {
            StringReader reader = new StringReader(
                "Imports Test = \r\n");

            VBParser parser = new VBParser();
            ReadOnlyCollection<ICodeElement> elements = parser.Parse(reader);
        }
Esempio n. 10
0
        public void ParseUnkownKeywordTest()
        {
            StringReader reader = new StringReader("Blah");

            VBParser parser = new VBParser();
            parser.Parse(reader);
        }
Esempio n. 11
0
        public void ParseUnhandledPreprocessorTest()
        {
            StringReader reader = new StringReader(
                "Public Class Test\r\n" +
                "#Const TEST = 1\r\n" +
                "End Class");

            VBParser parser = new VBParser();
            ReadOnlyCollection<ICodeElement> elements = parser.Parse(reader);
        }
Esempio n. 12
0
        public void ParseTypeImplementsTest()
        {
            StringReader reader = new StringReader(
                "Public Class TestClass : Implements IList\r\n" +
                "\tImplements IDisposable, IBindingList\r\n" +
                "End Class");

            VBParser parser = new VBParser();
            ReadOnlyCollection<ICodeElement> elements = parser.Parse(reader);

            Assert.AreEqual(1, elements.Count, "An unexpected number of elements were parsed.");
            TypeElement typeElement = elements[0] as TypeElement;
            Assert.IsNotNull(typeElement, "Expected a type element.");
            Assert.AreEqual(TypeElementType.Class, typeElement.Type, "Unexpected type element type.");
            Assert.AreEqual(3, typeElement.Interfaces.Count);
            Assert.AreEqual("IList", typeElement.Interfaces[0].Name);
            Assert.AreEqual("IDisposable", typeElement.Interfaces[1].Name);
            Assert.AreEqual("IBindingList", typeElement.Interfaces[2].Name);
            foreach (InterfaceReference interfaceReference in typeElement.Interfaces)
            {
                Assert.AreEqual(InterfaceReferenceType.Interface, interfaceReference.ReferenceType);
            }
        }
Esempio n. 13
0
        public void ParseSubTest()
        {
            StringReader reader = new StringReader(
                "Private Sub DoSomething()\r\n" +
                "End Sub");

            VBParser parser = new VBParser();
            ReadOnlyCollection<ICodeElement> elements = parser.Parse(reader);

            Assert.AreEqual(1, elements.Count, "An unexpected number of elements were parsed.");
            MethodElement methodElement = elements[0] as MethodElement;
            Assert.IsNotNull(methodElement, "Element is not a MethodElement.");
            Assert.AreEqual("DoSomething", methodElement.Name, "Unexpected name.");
            Assert.AreEqual(CodeAccess.Private, methodElement.Access, "Unexpected code access.");
            Assert.IsNull(methodElement.Type, "Unexpected member type.");

            reader = new StringReader(
                "Sub DoSomething()\r\n" +
                "End Sub");

            elements = parser.Parse(reader);

            Assert.AreEqual(1, elements.Count, "An unexpected number of elements were parsed.");
            methodElement = elements[0] as MethodElement;
            Assert.IsNotNull(methodElement, "Element is not a MethodElement.");
            Assert.AreEqual("DoSomething", methodElement.Name, "Unexpected name.");
            Assert.AreEqual(CodeAccess.None, methodElement.Access, "Unexpected code access.");
            Assert.IsNull(methodElement.Type, "Unexpected member type.");
        }
Esempio n. 14
0
        public void ParseSubExternalTest()
        {
            string[] variations =
            {
                "Public Declare Ansi Sub ExternalSub Lib \"Some.dll\" Alias \"doit\" (ByVal filename As String)",
                "Public Declare Ansi Sub _\r\nExternalSub Lib _\r\n\"Some.dll\" Alias _\r\n \"doit\" (ByVal filename As String)"
            };

            foreach (string variation in variations)
            {
                StringReader reader = new StringReader(variation);

                VBParser parser = new VBParser();
                ReadOnlyCollection<ICodeElement> elements = parser.Parse(reader);

                Assert.AreEqual(1, elements.Count, "An unexpected number of elements were parsed.");
                MethodElement methodElement = elements[0] as MethodElement;
                Assert.IsNotNull(methodElement, "Element is not a MethodElement.");
                Assert.AreEqual("ExternalSub", methodElement.Name, "Unexpected name.");
                Assert.AreEqual(CodeAccess.Public, methodElement.Access, "Unexpected code access.");
                Assert.AreEqual("ByVal filename As String", methodElement.Parameters, "Unexpected parameters.");
                Assert.IsNull(methodElement.Type, "Unexpected return type.");
                Assert.AreEqual("Ansi", methodElement[VBExtendedProperties.ExternalModifier], "Unexpected external modifier.");
                Assert.AreEqual("Some.dll", methodElement[VBExtendedProperties.ExternalLibrary], "Unexpected external library.");
                Assert.AreEqual("doit", methodElement[VBExtendedProperties.ExternalAlias], "Unexpected external alias.");
            }
        }
Esempio n. 15
0
        public void ParseStructDefinitionTest()
        {
            VBParser parser = new VBParser();

            VBTestFile testFile = VBTestUtilities.GetStructDefinitionFile();
            using (TextReader reader = testFile.GetReader())
            {
                ReadOnlyCollection<ICodeElement> elements = parser.Parse(reader);

                Assert.IsNotNull(elements, "Code element collection should not be null.");
                Assert.AreEqual(2, elements.Count, "An unexpected number of elements were parsed.");

                UsingElement using1 = elements[0] as UsingElement;
                Assert.IsNotNull(using1, "Expected a UsingElement.");
                Assert.AreEqual("System", using1.Name, "Unexpected using name.");

                NamespaceElement namespaceElement = elements[1] as NamespaceElement;
                Assert.IsNotNull(namespaceElement, "Expected a NamespaceElement.");
                Assert.AreEqual("SampleNamespace", namespaceElement.Name, "Unexpected namespace name.");

                Assert.IsNotNull(namespaceElement.Children, "Namespace Children collection should not be null.");
                Assert.AreEqual(1, namespaceElement.Children.Count, "An unexpected number of namespace child elements were parsed.");

                TypeElement structElement = namespaceElement.Children[0] as TypeElement;
                Assert.IsNotNull(structElement, "Expected a TypeElement.");
                Assert.AreEqual(TypeElementType.Structure, structElement.Type, "Expected type to be a structure.");
                Assert.IsFalse(structElement.IsStatic, "Structure should not be static.");
                Assert.IsFalse(structElement.IsSealed, "Structures should not be sealed.");
                Assert.AreEqual("SampleStruct", structElement.Name, "Unexpected structure name.");
                Assert.AreEqual(3, structElement.HeaderComments.Count,
                    "An unexpected number of class header comment lines were parsed.");
                foreach (ICommentElement comment in structElement.HeaderComments)
                {
                    Assert.AreEqual(CommentType.XmlLine, comment.Type, "Structure header comment should be an XML comment.");
                }
                Assert.AreEqual(CodeAccess.Public, structElement.Access, "Unexpected code access level.");
            }
        }
Esempio n. 16
0
        public void ParseUsingInvalidTest()
        {
            StringReader reader = new StringReader(
                "Imports System Text\r\n");

            VBParser parser = new VBParser();
            ReadOnlyCollection<ICodeElement> elements = parser.Parse(reader);
        }
Esempio n. 17
0
        public void ParseClassMissingRegionNameTest()
        {
            StringReader reader = new StringReader(
                "Public Class Test\r\n" +
                "\t#Region\r\n" +
                "\t#Endregion\r\n" +
                "End Class");

            VBParser parser = new VBParser();
            ReadOnlyCollection<ICodeElement> elements = parser.Parse(reader);
        }
Esempio n. 18
0
        public void ParseUsingRedefineTest()
        {
            string[] usingVariations = new string[]
            {
                "Imports Redefined = System.Text.Encoder",
                "Imports Redefined = System.Text.Encoder\r\n",
                "Imports  Redefined = System.Text.Encoder",
                "Imports _\r\nRedefined = System.Text.Encoder",
                "Imports _\r\n\tRedefined = System.Text.Encoder",
                "Imports _ \t\r\nRedefined = System.Text.Encoder",
                "Imports Redefined _\r\n= System.Text.Encoder",
                "Imports Redefined _ \t\r\n= System.Text.Encoder",
                "Imports Redefined _\r\n= _\r\nSystem.Text.Encoder",
                "Imports Redefined _ \t\r\n= _ \t\r\nSystem.Text.Encoder"
            };

            foreach (string usingStr in usingVariations)
            {
                StringReader reader = new StringReader(usingStr);
                VBParser parser = new VBParser();
                ReadOnlyCollection<ICodeElement> elements = parser.Parse(reader);

                Assert.AreEqual(1, elements.Count, "An unexpected number of elements were parsed.");
                UsingElement usingElement = elements[0] as UsingElement;
                Assert.IsNotNull(usingElement, "Element is not a UsingElement.");
                Assert.AreEqual("Redefined", usingElement.Name);
                Assert.AreEqual("System.Text.Encoder", usingElement.Redefine);
            }
        }
Esempio n. 19
0
        public void ParseClassMultipleTypeParameterTest1()
        {
            string[] variations = new string[]
            {
                "Partial Public Class NewClass(Of T as new,R,S as new,Q)\r\n" +
                "End Class",
                "Partial Public Class NewClass(Of T as new, R, S as new, Q)\r\n" +
                "End Class"
            };

            foreach (string variation in variations)
            {
                StringReader reader = new StringReader(variation);

                VBParser parser = new VBParser();
                ReadOnlyCollection<ICodeElement> elements = parser.Parse(reader);

                TypeElement classElement = elements[0] as TypeElement;
                Assert.IsNotNull(classElement, "Expected a class element");
                Assert.AreEqual(TypeElementType.Class, classElement.Type, "Expected a class.");
                Assert.AreEqual("NewClass", classElement.Name, "Unexpected class name.");
                Assert.AreEqual(CodeAccess.Public, classElement.Access, "Unexpected access.");
                Assert.IsTrue(classElement.IsPartial, "Expected a partial class.");
                Assert.AreEqual(4, classElement.TypeParameters.Count, "Unexpected number of type parameters.");
                Assert.AreEqual("T", classElement.TypeParameters[0].Name);
                Assert.AreEqual(1, classElement.TypeParameters[0].Constraints.Count);
                Assert.AreEqual("new", classElement.TypeParameters[0].Constraints[0]);
                Assert.AreEqual("R", classElement.TypeParameters[1].Name);
                Assert.AreEqual(0, classElement.TypeParameters[1].Constraints.Count);
                Assert.AreEqual("S", classElement.TypeParameters[2].Name);
                Assert.AreEqual(1, classElement.TypeParameters[2].Constraints.Count);
                Assert.AreEqual("new", classElement.TypeParameters[2].Constraints[0]);
                Assert.AreEqual("Q", classElement.TypeParameters[3].Name);
                Assert.AreEqual(0, classElement.TypeParameters[3].Constraints.Count);
            }
        }
Esempio n. 20
0
        public void ParseUsingTest()
        {
            string[] usingVariations = new string[]
            {
                "Imports System.Text",
                "Imports System.Text\r\n",
                "Imports  System.Text",
                "Imports _\r\nSystem.Text",
                "Imports _\r\n\tSystem.Text",
                "Imports _ \t\r\n\tSystem.Text"
            };

            foreach (string usingStr in usingVariations)
            {
                StringReader reader = new StringReader(usingStr);

                VBParser parser = new VBParser();
                ReadOnlyCollection<ICodeElement> elements = parser.Parse(reader);

                Assert.AreEqual(1, elements.Count, "An unexpected number of elements were parsed from '{0}'", usingStr);
                UsingElement usingElement = elements[0] as UsingElement;
                Assert.IsNotNull(usingElement, "Element is not a UsingElement.  '{0}'", usingStr);
                Assert.AreEqual("System.Text", usingElement.Name, "Unexpected name from '{0}'", usingStr);
                Assert.IsFalse(usingElement.IsMovable, "VB should not support moving import directives.");
            }
        }
Esempio n. 21
0
        public void ExpectedFieldInitialValueTest()
        {
            StringReader reader = new StringReader(
                "namespace SampleNamespace\r\n" +
                "    public class SampleClass\r\n" +
                "        private test as string = \r\n" +
                "    end class\r\n" +
                "end namespace");

            VBParser parser = new VBParser();
            ReadOnlyCollection<ICodeElement> elements = parser.Parse(reader);
        }
Esempio n. 22
0
        /// <summary>
        /// Gets the ClassMembers test class.
        /// </summary>
        /// <param name="reader">The reader.</param>
        /// <returns>A type code element.</returns>
        private static TypeElement GetMembersTestClass(TextReader reader)
        {
            TypeElement classElement;
            VBParser parser = new VBParser();

            ReadOnlyCollection<ICodeElement> elements = parser.Parse(reader);

            Assert.AreEqual(9, elements.Count, "Unexpected number of top-level elements.");

            NamespaceElement namespaceElement = elements[8] as NamespaceElement;
            Assert.IsNotNull(namespaceElement, "Expected a namespace element.");

            Assert.AreEqual(1, namespaceElement.Children.Count, "Unexpected number of namespace elements.");

            classElement = namespaceElement.Children[0] as TypeElement;
            Assert.IsNotNull(classElement, "Expected a type element.");
            Assert.AreEqual(TypeElementType.Class, classElement.Type, "Expected a class type.");
            Assert.AreEqual("SampleClass", classElement.Name, "Unexpected class name.");

            return classElement;
        }
Esempio n. 23
0
        public void ParseClassUnclosedTypeParameterConstraintTest()
        {
            StringReader reader = new StringReader(
                "Public Class Test(Of T As IComparable(Of T");

            VBParser parser = new VBParser();
            ReadOnlyCollection<ICodeElement> elements = parser.Parse(reader);
        }
Esempio n. 24
0
        public void ParseBlockWithClosingCommentTest()
        {
            StringReader reader;
            VBParser parser = new VBParser();
            ReadOnlyCollection<ICodeElement> elements;
            TextCodeElement textCodeElement;

            reader = new StringReader(
                "Private Sub DoSomething()\r\n" +
                "\t'Comment here\r\n" +
                "End Sub \t'New");

            elements = parser.Parse(reader);
            Assert.AreEqual(1, elements.Count, "An unexpected number of elements were parsed.");
            textCodeElement = elements[0] as TextCodeElement;
            Assert.AreEqual("'Comment here", textCodeElement.BodyText, "Unexpected body text.");
        }
Esempio n. 25
0
 public void ParseClassUnhandledElementTest3()
 {
     StringReader reader = new StringReader(
         "public class Test\r\n;\r\n\r\nPublic Test as String\r\nend class");
     VBParser parser = new VBParser();
     ReadOnlyCollection<ICodeElement> elements = parser.Parse(reader);
 }
Esempio n. 26
0
        public void ParseClassDefinitionTest()
        {
            VBParser parser = new VBParser();

            VBTestFile testFile = VBTestUtilities.GetClassDefinitionFile();
            using (TextReader reader = testFile.GetReader())
            {
                ReadOnlyCollection<ICodeElement> elements = parser.Parse(reader);

                Assert.IsNotNull(elements, "Code element collection should not be null.");
                Assert.AreEqual(7, elements.Count, "An unexpected number of elements were parsed.");

                CommentElement commentElement1 = elements[0] as CommentElement;
                Assert.IsNotNull(commentElement1, "Expected a CommentElement.");
                Assert.AreEqual(" This is comment line 1", commentElement1.Text, "Unexpected comment text.");

                CommentElement commentElement2 = elements[1] as CommentElement;
                Assert.IsNotNull(commentElement2, "Expected a CommentElement.");
                Assert.AreEqual(" This is comment line 2", commentElement2.Text, "Unexpected comment text.");

                CommentElement commentElement3 = elements[2] as CommentElement;
                Assert.IsNotNull(commentElement3, "Expected a CommentElement.");
                Assert.AreEqual(" This is comment line 3", commentElement3.Text, "Unexpected comment text.");

                UsingElement using1 = elements[3] as UsingElement;
                Assert.IsNotNull(using1, "Expected a UsingElement.");
                Assert.AreEqual("System", using1.Name, "Unexpected using name.");

                UsingElement using2 = elements[4] as UsingElement;
                Assert.IsNotNull(using2, "Expected a UsingElement.");
                Assert.AreEqual("System.Collections.Generic", using2.Name, "Unexpected using name.");

                UsingElement using3 = elements[5] as UsingElement;
                Assert.IsNotNull(using3, "Expected a UsingElement.");
                Assert.AreEqual("System.Text", using3.Name, "Unexpected using name.");

                NamespaceElement namespaceElement = elements[6] as NamespaceElement;
                Assert.IsNotNull(namespaceElement, "Expected a NamespaceElement.");
                Assert.AreEqual("SampleNamespace", namespaceElement.Name, "Unexpected namespace name.");

                Assert.IsNotNull(namespaceElement.Children, "Namespace Children collection should not be null.");
                Assert.AreEqual(1, namespaceElement.Children.Count, "An unexpected number of namespace child elements were parsed.");

                TypeElement classElement = namespaceElement.Children[0] as TypeElement;
                Assert.IsNotNull(classElement, "Expected a TypeElement.");
                Assert.AreEqual("SampleClass", classElement.Name, "Unexpected class name.");
                Assert.AreEqual(3, classElement.HeaderComments.Count,
                    "An unexpected number of class header comment lines were parsed.");
                foreach (ICommentElement comment in
                    classElement.HeaderComments)
                {
                    Assert.AreEqual(CommentType.XmlLine, comment.Type, "Class header comment should be an XML comment.");
                }
                Assert.AreEqual(CodeAccess.Public, classElement.Access, "Unexpected class code access level.");
            }
        }
Esempio n. 27
0
        public void ParseCommentedMemberTest()
        {
            StringReader reader = new StringReader(
                "'Private Sub DoSomething()\r\n" +
                "'End Sub");

            VBParser parser = new VBParser();
            ReadOnlyCollection<ICodeElement> elements = parser.Parse(reader);

            Assert.AreEqual(2, elements.Count, "An unexpected number of elements were parsed.");
            Assert.AreEqual("Private Sub DoSomething()", ((ICommentElement) elements[0]).Text, "Unexpected comment text.");
            Assert.AreEqual("End Sub", ((ICommentElement) elements[1]).Text, "Unexpected comment text.");
        }
Esempio n. 28
0
        public void ParseClassExpectedTypeImplementsTest()
        {
            StringReader reader = new StringReader(
                "Public Class Test(Of T");

            VBParser parser = new VBParser();
            ReadOnlyCollection<ICodeElement> elements = parser.Parse(reader);
        }
Esempio n. 29
0
        public void ParseCommentLineInvalidTest()
        {
            StringReader reader = new StringReader("REMBlah Blah");

            VBParser parser = new VBParser();
            parser.Parse(reader);
        }
Esempio n. 30
0
        public void ParseRegionUnmatchedEndDirectiveTest()
        {
            StringReader reader = new StringReader("\t#End Region \"Fields\"");

            VBParser parser = new VBParser();
            ReadOnlyCollection<ICodeElement> elements = parser.Parse(reader);
        }