Skip to content

Commit 155adc3

Browse files
committed
Added Integer Division
1 parent 1e696df commit 155adc3

File tree

2 files changed

+35
-4
lines changed

2 files changed

+35
-4
lines changed

Rubberduck.Inspections/Concrete/UnreachableCaseInspection/ParseTreeExpressionEvaluator.cs

Lines changed: 2 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -19,6 +19,7 @@ public class ParseTreeExpressionEvaluator : IParseTreeExpressionEvaluator
1919
{
2020
[MathSymbols.MULTIPLY] = delegate (double LHS, double RHS) { return LHS * RHS; },
2121
[MathSymbols.DIVIDE] = delegate (double LHS, double RHS) { return LHS / RHS; },
22+
[MathSymbols.INTEGER_DIVIDE] = delegate (double LHS, double RHS) { return Math.Truncate(Convert.ToDouble(Convert.ToInt64(LHS) / Convert.ToInt64(RHS))); },
2223
[MathSymbols.PLUS] = delegate (double LHS, double RHS) { return LHS + RHS; },
2324
[MathSymbols.MINUS] = delegate (double LHS, double RHS) { return LHS - RHS; },
2425
[MathSymbols.EXPONENT] = Math.Pow,
@@ -146,6 +147,7 @@ internal static class MathSymbols
146147

147148
public static string MULTIPLY => _multiply ?? LoadSymbols(VBAParser.MULT);
148149
public static string DIVIDE => _divide ?? LoadSymbols(VBAParser.DIV);
150+
public static string INTEGER_DIVIDE => @"\";
149151
public static string PLUS => _plus ?? LoadSymbols(VBAParser.PLUS);
150152
public static string MINUS => _minusSign ?? LoadSymbols(VBAParser.MINUS);
151153
public static string ADDITIVE_INVERSE => MINUS;

RubberduckTests/Inspections/UnreachableCaseInspectionTests.cs

Lines changed: 33 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -293,6 +293,15 @@ public void UciUnit_Division(string operands, string expected, string typeName)
293293
TestBinaryOp(MathSymbols.DIVIDE, operands, expected, typeName);
294294
}
295295

296+
[TestCase(@"9.5_\_2.4", "5", "Long")]
297+
[TestCase(@"10_\_4", "2", "Long")]
298+
[TestCase(@"5.423_\_1", "5", "Long")]
299+
[Category("Inspections")]
300+
public void UciUnit_IntegerDivision(string operands, string expected, string typeName)
301+
{
302+
TestBinaryOp(MathSymbols.INTEGER_DIVIDE, operands, expected, typeName);
303+
}
304+
296305
[TestCase("10.51_+_11.2", "21.71", "Double")]
297306
[TestCase("10_+_11.2", "21.2", "Double")]
298307
[TestCase("11.2_+_10", "21.2", "Double")]
@@ -2075,10 +2084,6 @@ End Select
20752084
[Category("Inspections")]
20762085
public void UciFunctional_IsStmtAndNegativeRangeWithConstants()
20772086
{
2078-
var test1 = VBAParser.DefaultVocabulary.GetDisplayName(VBAParser.EQ);
2079-
var test2 = VBAParser.DefaultVocabulary.GetLiteralName(VBAParser.EQ);
2080-
var test3 = VBAParser.DefaultVocabulary.GetSymbolicName(VBAParser.EQ);
2081-
20822087
const string inputCode =
20832088
@"
20842089
private const START As Long = 10
@@ -2188,6 +2193,30 @@ End Select
21882193
CheckActualResultsEqualsExpected(inputCode, unreachable: 1);
21892194
}
21902195

2196+
[Test]
2197+
[Category("Inspections")]
2198+
public void UciFunctional_IntegerDivision()
2199+
{
2200+
string inputCode =
2201+
@"
2202+
private const START As Long = 3
2203+
private const FINISH As Long = 10
2204+
2205+
Sub Foo(x As Long, y As Long, z As Long)
2206+
Select Case z
2207+
Case x
2208+
'OK
2209+
Case START
2210+
'OK
2211+
Case FINISH \ START
2212+
'Unreachable
2213+
End Select
2214+
2215+
End Sub";
2216+
2217+
CheckActualResultsEqualsExpected(inputCode, unreachable: 1);
2218+
}
2219+
21912220
private static void CheckActualResultsEqualsExpected(string inputCode, int unreachable = 0, int mismatch = 0, int caseElse = 0)
21922221
{
21932222
var expected = new Dictionary<string, int>

0 commit comments

Comments
 (0)