Example #1
0
        public void PropertyBlockFromPrototype_PropertyGetAccessibility(string targetIdentifier, DeclarationType declarationType, string typeName, Accessibility accessibility)
        {
            var    testParams = new PropertyBlockFromPrototypeParams("Bazz", DeclarationType.PropertyGet, accessibility);
            string inputCode  =
                $@"

Private Type TTestType
    FirstValue As Long
    SecondValue As Variant
End Type

Private Enum ETestType
    EFirstValue = 0
    ESecondValue
End Enum

Public Enum ETestType2
    EThirdValue = 0
    EFourthValue
End Enum

Private fizz As Integer

Private fazz As ETestType

Private fuzz As ETestType2
";
            var result = ParseAndTest <Declaration>(inputCode,
                                                    targetIdentifier,
                                                    declarationType,
                                                    testParams,
                                                    PropertyGetBlockFromPrototypeTest);

            StringAssert.Contains($"{accessibility} Property Get {testParams.Identifier}() As {typeName}", result);
        }
Example #2
0
        public void PropertyBlockFromVariousPrototypeTypes_PropertyGet(string inputCode, DeclarationType declarationType, string expectedTypeName)
        {
            var testParams = new PropertyBlockFromPrototypeParams("Bazz", DeclarationType.PropertyGet);

            var result = ParseAndTest <Declaration>(inputCode,
                                                    "fizz",
                                                    declarationType,
                                                    testParams,
                                                    PropertyGetBlockFromPrototypeTest);

            StringAssert.Contains($"Property Get Bazz() As {expectedTypeName}", result);
        }
Example #3
0
        public void PropertyBlockFromPrototype_PropertyGetChangeParamName()
        {
            var    testParams = new PropertyBlockFromPrototypeParams("Bazz", DeclarationType.PropertyGet, paramIdentifier: "testParam");
            string inputCode  =
                $@"
Private fizz As Integer
";
            var result = ParseAndTest <Declaration>(inputCode,
                                                    "fizz",
                                                    DeclarationType.Variable,
                                                    testParams,
                                                    PropertyGetBlockFromPrototypeTest);

            StringAssert.Contains("Property Get Bazz() As Integer", result);
        }
Example #4
0
        public void PropertyBlockFromPrototype_PropertySet(string targetIdentifier, DeclarationType declarationType, string typeName)
        {
            var    testParams = new PropertyBlockFromPrototypeParams("Bazz", DeclarationType.PropertySet);
            string inputCode  =
                $@"

Private Type TTestType
    FirstValue As Long
    SecondValue As Variant
End Type

Private fizz As Variant

";
            var result = ParseAndTest <Declaration>(inputCode,
                                                    targetIdentifier,
                                                    declarationType,
                                                    testParams,
                                                    PropertySetBlockFromPrototypeTest);

            StringAssert.Contains($"Property Set {testParams.Identifier}(ByVal {_rhsIdentifier} As {typeName})", result);
        }
Example #5
0
        public void PropertyBlockFromFromFunctionPrototypes(string memberType, string memberEndStatement, DeclarationType declarationType, string typeName)
        {
            var targetIdentifier = "TestValue";
            var testParams       = new PropertyBlockFromPrototypeParams("Bazz", DeclarationType.PropertyLet);
            var inputCode        =
                $@"

Private mTestValue As {typeName}

Public {memberType} TestValue() As {typeName}
    TestValue = mTestValue
End {memberEndStatement}
";

            var result = ParseAndTest <Declaration>(inputCode,
                                                    targetIdentifier,
                                                    declarationType,
                                                    testParams,
                                                    PropertyLetBlockFromPrototypeTest);

            StringAssert.Contains($"Property Let {testParams.Identifier}(ByVal RHS As {typeName})", result);
        }
Example #6
0
        public void PropertyBlockFromPrototype_PropertyGetContent(string targetIdentifier, DeclarationType declarationType, string content)
        {
            var    testParams = new PropertyBlockFromPrototypeParams("Bazz", DeclarationType.PropertyGet, content: content);
            string inputCode  =
                $@"

Private Type TTestType
    FirstValue As Long
    SecondValue As Variant
End Type

Private Enum ETestType
    EFirstValue = 0
    ESecondValue
End Enum

Public Enum ETestType2
    EThirdValue = 0
    EFourthValue
End Enum

Private fizz As Integer

Private fozz As TTestType

Private fazz As ETestType

Private fezz As ETestType2

Private fuzz As TTestType2
";
            var result = ParseAndTest <Declaration>(inputCode,
                                                    targetIdentifier,
                                                    declarationType,
                                                    testParams,
                                                    PropertyGetBlockFromPrototypeTest);

            StringAssert.Contains(content, result);
        }
Example #7
0
 private static string PropertySetBlockFromPrototypeTest <T>(T target, PropertyBlockFromPrototypeParams testParams) where T : Declaration
 {
     CreateCodeBuilder().TryBuildPropertySetCodeBlock(target, testParams.Identifier, out string result, testParams.Accessibility, testParams.Content, testParams.WriteParam);
     return(result);
 }
Example #8
0
        private string ParseAndTest <T>(string inputCode, string targetIdentifier, DeclarationType declarationType, PropertyBlockFromPrototypeParams testParams, Func <T, PropertyBlockFromPrototypeParams, string> theTest)
        {
            var vbe   = MockVbeBuilder.BuildFromSingleStandardModule(inputCode, out _).Object;
            var state = MockParser.CreateAndParse(vbe);

            using (state)
            {
                var target = state.DeclarationFinder.DeclarationsWithType(declarationType)
                             .Where(d => d.IdentifierName == targetIdentifier).OfType <T>()
                             .Single();
                return(theTest(target, testParams));
            }
        }