Skip to content

Commit 38e0b5c

Browse files
committed
Add test cases for creating Let/Set properties
Adds MCVE tests for parameter list bug. Scenarios: 'Property Let' prototype used to create a 'Property Set' member and 'Property Set' prototype used to create a 'Property Let' member.
1 parent 3a9b233 commit 38e0b5c

File tree

1 file changed

+164
-1
lines changed

1 file changed

+164
-1
lines changed

RubberduckTests/CodeBuilderTests.cs

Lines changed: 164 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -1,6 +1,5 @@
11
using NUnit.Framework;
22
using Rubberduck.Common;
3-
using Rubberduck.Parsing.Grammar;
43
using Rubberduck.Parsing.Symbols;
54
using Rubberduck.Refactorings;
65
using Rubberduck.SmartIndenter;
@@ -356,6 +355,170 @@ public void PropertyGetFromFromPropertySetWithParameters(string accessibilityTok
356355
StringAssert.Contains(expected, result);
357356
}
358357

358+
//Creating a Set from a Set prototype typicaly needs a new name
359+
[TestCase(DeclarationType.PropertySet, "NewSetProperty")]
360+
[TestCase(DeclarationType.PropertyLet, null)]
361+
[Category(nameof(CodeBuilder))]
362+
public void PropertySetFromPropertyMutator(DeclarationType prototypeDeclarationType, string propertyName)
363+
{
364+
(string procType, string endStmt) = ProcedureTypeIdentifier(prototypeDeclarationType);
365+
366+
string inputCode =
367+
$@"
368+
Public {procType} {_defaultPropertyIdentifier}(ByVal RHS As Variant)
369+
End Property
370+
";
371+
372+
var prototype = GetPrototypeDeclaration<ModuleBodyElementDeclaration>(
373+
inputCode, _defaultPropertyIdentifier, prototypeDeclarationType);
374+
375+
var tryResult = CreateCodeBuilder().TryBuildPropertySetCodeBlock(
376+
prototype, propertyName ?? _defaultPropertyIdentifier,
377+
out var result, prototype.Accessibility);
378+
379+
Assert.IsTrue(tryResult,
380+
"TryBuildPropertySetCodeBlock(...) returned false");
381+
382+
var expected =
383+
$"Public Property Set {propertyName ?? _defaultPropertyIdentifier}(ByVal RHS As Variant)";
384+
385+
StringAssert.Contains(expected, result);
386+
}
387+
388+
//Creating a Set from a Set prototype typicaly needs a new name
389+
[TestCase(DeclarationType.PropertySet, "NewSetProperty")]
390+
[TestCase(DeclarationType.PropertyLet, null)]
391+
[Category(nameof(CodeBuilder))]
392+
public void PropertySetFromParameterizedPropertyMutator(DeclarationType prototypeDeclarationType, string propertyName)
393+
{
394+
(string procType, string endStmt) = ProcedureTypeIdentifier(prototypeDeclarationType);
395+
396+
string inputCode =
397+
$@"
398+
Public {procType} {_defaultPropertyIdentifier}(ByVal index1 As Long, ByVal index2 As Long, ByVal RHS As Variant)
399+
End Property
400+
";
401+
402+
var prototype = GetPrototypeDeclaration<ModuleBodyElementDeclaration>(
403+
inputCode, _defaultPropertyIdentifier, prototypeDeclarationType);
404+
405+
var tryResult = CreateCodeBuilder().TryBuildPropertySetCodeBlock(
406+
prototype, propertyName ?? _defaultPropertyIdentifier,
407+
out var result, prototype.Accessibility);
408+
409+
Assert.IsTrue(tryResult,
410+
"TryBuildPropertySetCodeBlock(...) returned false");
411+
412+
var expected =
413+
$"Public Property Set {propertyName ?? _defaultPropertyIdentifier}(ByVal index1 As Long, ByVal index2 As Long, ByVal RHS As Variant)";
414+
415+
StringAssert.Contains(expected, result);
416+
}
417+
418+
//Creating a Let from a Let prototype typicaly needs a new name
419+
[TestCase(DeclarationType.PropertyLet, "NewLetProperty")]
420+
[TestCase(DeclarationType.PropertySet, null)]
421+
[Category(nameof(CodeBuilder))]
422+
public void PropertyLetFromPropertyMutator(DeclarationType prototypeDeclarationType, string propertyName)
423+
{
424+
(string procType, string endStmt) = ProcedureTypeIdentifier(prototypeDeclarationType);
425+
426+
string inputCode =
427+
$@"
428+
Public {procType} {_defaultPropertyIdentifier}(ByVal RHS As Variant)
429+
End Property
430+
";
431+
432+
var prototype = GetPrototypeDeclaration<ModuleBodyElementDeclaration>(
433+
inputCode, _defaultPropertyIdentifier, prototypeDeclarationType);
434+
435+
var tryResult = CreateCodeBuilder().TryBuildPropertyLetCodeBlock(
436+
prototype, propertyName ?? _defaultPropertyIdentifier,
437+
out var result, prototype.Accessibility);
438+
439+
Assert.IsTrue(tryResult,
440+
"TryBuildPropertyLetCodeBlock(...) returned false");
441+
442+
var expected =
443+
$"Public Property Let {propertyName ?? _defaultPropertyIdentifier}(ByVal RHS As Variant)";
444+
445+
StringAssert.Contains(expected, result);
446+
}
447+
448+
//Creating a Let from a Let prototype typicaly needs a new name
449+
[TestCase(DeclarationType.PropertyLet, "NewLetProperty")]
450+
[TestCase(DeclarationType.PropertySet, null)]
451+
[Category(nameof(CodeBuilder))]
452+
public void PropertyLetFromParameterizedPropertyMutator(DeclarationType prototypeDeclarationType, string propertyName)
453+
{
454+
(string procType, string endStmt) = ProcedureTypeIdentifier(prototypeDeclarationType);
455+
456+
string inputCode =
457+
$@"
458+
Public {procType} {_defaultPropertyIdentifier}(ByVal index1 As Long, ByVal index2 As Long, ByVal RHS As Variant)
459+
End Property
460+
";
461+
462+
var prototype = GetPrototypeDeclaration<ModuleBodyElementDeclaration>(
463+
inputCode, _defaultPropertyIdentifier, prototypeDeclarationType);
464+
465+
var tryResult = CreateCodeBuilder().TryBuildPropertyLetCodeBlock(
466+
prototype, propertyName ?? _defaultPropertyIdentifier,
467+
out var result, prototype.Accessibility);
468+
469+
Assert.IsTrue(tryResult,
470+
"TryBuildPropertyLetCodeBlock(...) returned false");
471+
472+
var expected =
473+
$"Public Property Let {propertyName ?? _defaultPropertyIdentifier}(ByVal index1 As Long, ByVal index2 As Long, ByVal RHS As Variant)";
474+
475+
StringAssert.Contains(expected, result);
476+
}
477+
478+
[Test]
479+
[Category(nameof(CodeBuilder))]
480+
public void PropertyLetFromObjectPropertySet_ReturnsFalse()
481+
{
482+
(string procType, string endStmt) = ProcedureTypeIdentifier(DeclarationType.PropertySet);
483+
484+
string inputCode =
485+
$@"
486+
Public {procType} {_defaultPropertyIdentifier}(ByVal RHS As Collection)
487+
End Property
488+
";
489+
490+
var prototype = GetPrototypeDeclaration<ModuleBodyElementDeclaration>(
491+
inputCode, _defaultPropertyIdentifier, DeclarationType.PropertySet);
492+
493+
var tryResult = CreateCodeBuilder().TryBuildPropertyLetCodeBlock(
494+
prototype, _defaultPropertyIdentifier,
495+
out var result, prototype.Accessibility);
496+
497+
Assert.IsFalse(tryResult);
498+
}
499+
500+
[Test]
501+
[Category(nameof(CodeBuilder))]
502+
public void PropertySetFromSimpleValueTypePropertyLet_ReturnsFalse()
503+
{
504+
(string procType, string endStmt) = ProcedureTypeIdentifier(DeclarationType.PropertyLet);
505+
506+
string inputCode =
507+
$@"
508+
Public {procType} {_defaultPropertyIdentifier}(ByVal RHS As Long)
509+
End Property
510+
";
511+
512+
var prototype = GetPrototypeDeclaration<ModuleBodyElementDeclaration>(
513+
inputCode, _defaultPropertyIdentifier, DeclarationType.PropertyLet);
514+
515+
var tryResult = CreateCodeBuilder().TryBuildPropertySetCodeBlock(
516+
prototype, _defaultPropertyIdentifier,
517+
out var result, prototype.Accessibility);
518+
519+
Assert.IsFalse(tryResult);
520+
}
521+
359522
[TestCase("fizz", DeclarationType.Variable, "Integer")]
360523
[TestCase("FirstValue", DeclarationType.UserDefinedTypeMember, "Long")]
361524
[TestCase("fazz", DeclarationType.Variable, "Long")]

0 commit comments

Comments
 (0)