Exemple #1
0
        public void VBNetComplexGenericClassTypeDeclarationTest()
        {
            string          declr = @"
Public Class Generic(Of T As MyNamespace.IMyInterface, S As {G(Of T()), IAnotherInterface})
	Implements System.IComparable

End Class
";
            TypeDeclaration td    = ParseUtil.ParseGlobal <TypeDeclaration>(declr);

            Assert.AreEqual(ClassType.Class, td.Type);
            Assert.AreEqual("Generic", td.Name);
            Assert.AreEqual(Modifiers.Public, td.Modifier);
            Assert.AreEqual(1, td.BaseTypes.Count);
            Assert.AreEqual("System.IComparable", td.BaseTypes[0].Type);

            Assert.AreEqual(2, td.Templates.Count);
            Assert.AreEqual("T", td.Templates[0].Name);
            Assert.AreEqual("MyNamespace.IMyInterface", td.Templates[0].Bases[0].Type);

            Assert.AreEqual("S", td.Templates[1].Name);
            Assert.AreEqual(2, td.Templates[1].Bases.Count);
            Assert.AreEqual("G", td.Templates[1].Bases[0].Type);
            Assert.AreEqual(1, td.Templates[1].Bases[0].GenericTypes.Count);
            Assert.IsTrue(td.Templates[1].Bases[0].GenericTypes[0].IsArrayType);
            Assert.AreEqual("T", td.Templates[1].Bases[0].GenericTypes[0].Type);
            Assert.AreEqual(new int[] { 0 }, td.Templates[1].Bases[0].GenericTypes[0].RankSpecifier);
            Assert.AreEqual("IAnotherInterface", td.Templates[1].Bases[1].Type);
        }
Exemple #2
0
        public void VBNetMissingBaseClassTest()
        {
            // SD2-1499: test that this invalid code doesn't crash
            TypeDeclaration td = ParseUtil.ParseGlobal <TypeDeclaration>("public class test inherits", true);

            Assert.AreEqual(0, td.BaseTypes.Count);
        }
        public void VBNetInferOptionDeclarationTest()
        {
            string            program = "Option Infer\n";
            OptionDeclaration opDec   = ParseUtil.ParseGlobal <OptionDeclaration>(program);

            Assert.AreEqual(OptionType.Infer, opDec.OptionType);
            Assert.IsTrue(opDec.OptionValue);
        }
        public void VBNetCompareTextOptionDeclarationTest()
        {
            string            program = "Option Compare Text\n";
            OptionDeclaration opDec   = ParseUtil.ParseGlobal <OptionDeclaration>(program);

            Assert.AreEqual(OptionType.CompareText, opDec.OptionType);
            Assert.IsTrue(opDec.OptionValue);
        }
        public void VBNetExplicitOptionDeclarationTest()
        {
            string            program = "Option Explicit Off\n";
            OptionDeclaration opDec   = ParseUtil.ParseGlobal <OptionDeclaration>(program);

            Assert.AreEqual(OptionType.Explicit, opDec.OptionType);
            Assert.IsFalse(opDec.OptionValue, "Off option value excepted!");
        }
        public void VBNetSimpleNamespaceTest()
        {
            string program = "Namespace TestNamespace" + Environment.NewLine +
                             "End Namespace" + Environment.NewLine;
            NamespaceDeclaration ns = ParseUtil.ParseGlobal <NamespaceDeclaration>(program);

            Assert.AreEqual("TestNamespace", ns.Name);
        }
Exemple #7
0
        public void AssemblyAttribute()
        {
            string           program = @"<assembly: System.Attribute()>";
            AttributeSection decl    = ParseUtil.ParseGlobal <AttributeSection>(program);

            Assert.AreEqual(new Location(1, 1), decl.StartLocation);
            Assert.AreEqual("assembly", decl.AttributeTarget);
        }
Exemple #8
0
        public void VBNetEnumOnSingleLine2()
        {
            string          program = "Enum TestEnum : A : : B = 1 :: C : End Enum";
            TypeDeclaration td      = ParseUtil.ParseGlobal <TypeDeclaration>(program);

            Assert.AreEqual("TestEnum", td.Name);
            Assert.AreEqual(ClassType.Enum, td.Type);
            Assert.AreEqual(3, td.Children.Count);
        }
Exemple #9
0
        public void VBNetPartialPublicClass()
        {
            string          program = "Partial Public Class TestClass\nEnd Class\n";
            TypeDeclaration td      = ParseUtil.ParseGlobal <TypeDeclaration>(program);

            Assert.AreEqual("TestClass", td.Name);
            Assert.AreEqual(ClassType.Class, td.Type);
            Assert.AreEqual(Modifiers.Partial | Modifiers.Public, td.Modifier);
        }
        public void VBNetMultiFieldsOnSingleLineTest()
        {
            string          program = "Class TestClass : Dim a : Dim b : End Class";
            TypeDeclaration td      = ParseUtil.ParseGlobal <TypeDeclaration>(program);

            Assert.AreEqual(2, td.Children.Count);
            Assert.IsTrue(td.Children[0] is FieldDeclaration);
            Assert.IsTrue(td.Children[1] is FieldDeclaration);
        }
Exemple #11
0
        public void VBNetSimpleClassTypeDeclarationWithColon()
        {
            string program = "Class TestClass\n" +
                             " : \n" +
                             "End Class";
            TypeDeclaration td = ParseUtil.ParseGlobal <TypeDeclaration>(program);

            Assert.AreEqual("TestClass", td.Name);
            Assert.AreEqual(ClassType.Class, td.Type);
        }
Exemple #12
0
        public void GlobalAttribute()
        {
            string          program = @"<Global.Microsoft.VisualBasic.CompilerServices.DesignerGenerated()> _
Public Class Form1
	
End Class";
            TypeDeclaration decl    = ParseUtil.ParseGlobal <TypeDeclaration>(program);

            Assert.AreEqual("Microsoft.VisualBasic.CompilerServices.DesignerGenerated", decl.Attributes[0].Attributes[0].Name);
        }
Exemple #13
0
        public void VBNetEnumWithSystemBaseClassDeclarationTest()
        {
            string program = "Enum TestEnum As System.UInt16\n" +
                             "End Enum\n";
            TypeDeclaration td = ParseUtil.ParseGlobal <TypeDeclaration>(program);

            Assert.AreEqual("TestEnum", td.Name);
            Assert.AreEqual(ClassType.Enum, td.Type);
            Assert.AreEqual("System.UInt16", td.BaseTypes[0].Type);
            Assert.AreEqual(0, td.Children.Count);
        }
Exemple #14
0
        public void VBNetSimpleClassTypeDeclarationWithoutLastNewLineTest()
        {
            string program = "Class TestClass\n" +
                             "End Class";
            TypeDeclaration td = ParseUtil.ParseGlobal <TypeDeclaration>(program);

            Assert.AreEqual("TestClass", td.Name);
            Assert.AreEqual(ClassType.Class, td.Type);
            Assert.AreEqual(1, td.StartLocation.Line, "start line");
            Assert.AreEqual(2, td.EndLocation.Line, "end line");
        }
Exemple #15
0
        public void VBNetSimpleClassTypeDeclarationTest()
        {
            string program = "Class TestClass\n" +
                             "End Class\n";
            TypeDeclaration td = ParseUtil.ParseGlobal <TypeDeclaration>(program);

            Assert.AreEqual("TestClass", td.Name);
            Assert.AreEqual(ClassType.Class, td.Type);
            Assert.AreEqual(1, td.StartLocation.Line, "start line");
            Assert.AreEqual(1, td.BodyStartLocation.Line, "bodystart line");
            Assert.AreEqual(16, td.BodyStartLocation.Column, "bodystart col");
            Assert.AreEqual(2, td.EndLocation.Line, "end line");
            Assert.AreEqual(10, td.EndLocation.Column, "end col");
        }
Exemple #16
0
        public void AttributeOnModule()
        {
            string          program = @"
<HideModule> _
Public Module MyExtra

	Public i As Integer
	Public d As Double
	
End Module
";
            TypeDeclaration decl    = ParseUtil.ParseGlobal <TypeDeclaration>(program);

            Assert.AreEqual("HideModule", decl.Attributes[0].Attributes[0].Name);
        }
Exemple #17
0
        public void AttributeOnStructure()
        {
            string          program = @"
<StructLayout( LayoutKind.Explicit )> _
Public Structure MyUnion

	<FieldOffset( 0 )> Public i As Integer
	< FieldOffset( 0 )> Public d As Double
	
End Structure 'MyUnion
";
            TypeDeclaration decl    = ParseUtil.ParseGlobal <TypeDeclaration>(program);

            Assert.AreEqual("StructLayout", decl.Attributes[0].Attributes[0].Name);
        }
Exemple #18
0
        public void VBNetGenericClassTypeDeclarationTest()
        {
            string          declr = @"
Public Class Test(Of T)

End Class
";
            TypeDeclaration td    = ParseUtil.ParseGlobal <TypeDeclaration>(declr);

            Assert.AreEqual(ClassType.Class, td.Type);
            Assert.AreEqual("Test", td.Name);
            Assert.AreEqual(Modifiers.Public, td.Modifier);
            Assert.AreEqual(0, td.BaseTypes.Count);
            Assert.AreEqual(1, td.Templates.Count);
            Assert.AreEqual("T", td.Templates[0].Name);
        }
Exemple #19
0
        public void VBNetGenericClassWithConstraint()
        {
            string          declr = @"
Public Class Test(Of T As IMyInterface)

End Class
";
            TypeDeclaration td    = ParseUtil.ParseGlobal <TypeDeclaration>(declr);

            Assert.AreEqual(ClassType.Class, td.Type);
            Assert.AreEqual("Test", td.Name);

            Assert.AreEqual(1, td.Templates.Count);
            Assert.AreEqual("T", td.Templates[0].Name);
            Assert.AreEqual("IMyInterface", td.Templates[0].Bases[0].Type);
        }
        public void VBNetBigReDimStatementTest()
        {
            string          program         = @"
Class X
	Sub x
		ReDim sU(m - 1, n - 1)
		ReDim sW(n - 1)
		ReDim sV(n - 1, n - 1)
		ReDim rv1(n - 1)
		ReDim sMt(iNrCols - 1, 0)
		ReDim Preserve sMt(iNrCols - 1, iRowNr)
		ReDim sM(iRowNr - 1, iNrCols - 1)
		If (IsNothing(ColLengths)) Then ReDim ColLengths(0)
		If (ColLengths.Length = (SubItem + 1)) Then ReDim Preserve ColLengths(SubItem + 1)
		ReDim sTransform(2, iTransformType - 1)
		ReDim Preserve _Items(_Count)
		ReDim Preserve _Items(nCapacity)
		ReDim Preserve _Items(0 To _Count)
		ReDim Preserve _Items(0 To nCapacity)
		ReDim sU(m - 1, n - 1)
		ReDim sW(n - 1)
		ReDim sV(n - 1, n - 1)
		ReDim rv1(n - 1)
		ReDim sMt(iNrCols - 1, 0)
		ReDim Preserve sMt(iNrCols - 1, iRowNr)
		ReDim sM(iRowNr - 1, iNrCols - 1)
		If (IsNothing(ColLengths)) Then ReDim ColLengths(0)
		If (ColLengths.Length = (SubItem + 1)) Then ReDim Preserve ColLengths(SubItem + 1)
		ReDim sTransform(2, iTransformType - 1)
		ReDim Preserve Samples(Samples.GetUpperBound(0) + 1)
		ReDim Samples(0)
		ReDim BaseCssContent(BaseCssContentRows - 1)
		ReDim mabtRxBuf(Bytes2Read - 1)
		ReDim Preserve primarykey(primarykey.Length)
		ReDim Preserve IntArray(10, 10, 15)
		ReDim X(10, 10)
		ReDim Preserve IntArray(0 To 10, 10, 0 To 20)
		ReDim Preserve IntArray(10, 10, 15)
		ReDim X(0 To 10, 0 To 10)
		ReDim GetMe().IntArray(0 To 10, 10, 0 To 20)
		ReDim GetMe(ExplicitParameter := 3).IntArray(0 To 10, 10, 0 To 20)
		ReDim SomeType(Of Integer).IntArray(0 To 10, 10, 0 To 20)
	End Sub
End Class";
            TypeDeclaration typeDeclaration = ParseUtil.ParseGlobal <TypeDeclaration>(program);
        }
        public void VBNetJuggedNamespaceTest()
        {
            string program = "Namespace N1 'TestNamespace\n" +
                             "    Namespace N2   ' Declares a namespace named N2 within N1.\n" +
                             "    End Namespace\n" +
                             "End Namespace\n";

            NamespaceDeclaration ns = ParseUtil.ParseGlobal <NamespaceDeclaration>(program);

            Assert.AreEqual("N1", ns.Name);

            Assert.IsTrue(ns.Children[0] is NamespaceDeclaration);

            ns = (NamespaceDeclaration)ns.Children[0];

            Assert.AreEqual("N2", ns.Name);
        }
Exemple #22
0
        public void VBNetGenericMethodInInterface()
        {
            const string      program = @"Interface MyInterface
				Function MyMethod(Of T As {ISomeInterface})(a As T) As T
				End Interface"                ;
            TypeDeclaration   td      = ParseUtil.ParseGlobal <TypeDeclaration>(program);
            MethodDeclaration md      = (MethodDeclaration)td.Children[0];

            Assert.AreEqual("T", md.TypeReference.Type);
            Assert.AreEqual(1, md.Parameters.Count);
            Assert.AreEqual("T", ((ParameterDeclarationExpression)md.Parameters[0]).TypeReference.Type);
            Assert.AreEqual("a", ((ParameterDeclarationExpression)md.Parameters[0]).ParameterName);

            Assert.AreEqual(1, md.Templates.Count);
            Assert.AreEqual("T", md.Templates[0].Name);
            Assert.AreEqual(1, md.Templates[0].Bases.Count);
            Assert.AreEqual("ISomeInterface", md.Templates[0].Bases[0].Type);
        }
Exemple #23
0
        public void InvalidImportsStatement2()
        {
            string program = "Imports ,\n";

            ParseUtil.ParseGlobal <ImportsStatement>(program, true);
        }
        public void SimpleVBNetDelegateDeclarationTest()
        {
            string program = "Public Delegate Sub MyDelegate(ByVal a As Integer, ByVal secondParam As Integer, ByVal lastParam As MyObj)\n";

            TestDelegateDeclaration(ParseUtil.ParseGlobal <DelegateDeclaration>(program));
        }
        public void InvalidOptionSyntax()
        {
            string program = "Option\n";

            ParseUtil.ParseGlobal <OptionStatement>(program, true);
        }
Exemple #26
0
 public void ModuleAttributeTargetEscaped()
 {
     // check that this doesn't crash the parser:
     ParseUtil.ParseGlobal <AttributeSection>("<[Module]: SuppressMessageAttribute>", true);
 }