Skip to content

Commit 1044b9c

Browse files
committed
Merge pull request #1175 from autoboosh/emptyfix
Fixes + operator handling of Empty and Strings
2 parents 68265a9 + 77f429e commit 1044b9c

File tree

3 files changed

+10
-2
lines changed

3 files changed

+10
-2
lines changed

Rubberduck.Parsing/Preprocessing/BinaryPlusExpression.cs

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -19,7 +19,7 @@ public override IValue Evaluate()
1919
{
2020
return null;
2121
}
22-
if (left.ValueType == ValueType.String)
22+
if (left.ValueType == ValueType.String || right.ValueType == ValueType.String)
2323
{
2424
return new StringValue(left.AsString+ right.AsString);
2525
}

Rubberduck.Parsing/Preprocessing/NameExpression.cs

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -16,7 +16,7 @@ public NameExpression(
1616
public override IValue Evaluate()
1717
{
1818
var identifier = _identifier.Evaluate().AsString;
19-
// Special case, identifier that does not exist is VBAEmpty.
19+
// Special case, identifier that does not exist is Empty.
2020
// Could add them to the symbol table, but since they are all constants
2121
// they never change anyway.
2222
if (!_symbolTable.HasSymbol(identifier))

RubberduckTests/Preprocessing/VBAPreprocessorVisitorTests.cs

Lines changed: 8 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -94,13 +94,19 @@ public void TestPlusOperator()
9494
#Const c = True + False + True
9595
#Const d = Nothing
9696
#Const e = ""5"" + ""4""
97+
#Const f = Empty + Empty
98+
#Const g = Empty + ""a""
99+
#Const h = ""a"" + Empty
97100
";
98101
var result = Preprocess(code);
99102
Assert.AreEqual(1544.242m, result.Item1.Get("a").AsDecimal);
100103
Assert.AreEqual(new DateTime(2298, 3, 7), result.Item1.Get("b").AsDate);
101104
Assert.AreEqual(-2m, result.Item1.Get("c").AsDecimal);
102105
Assert.AreEqual(null, result.Item1.Get("d"));
103106
Assert.AreEqual("54", result.Item1.Get("e").AsString);
107+
Assert.AreEqual(0m, result.Item1.Get("f").AsDecimal);
108+
Assert.AreEqual("a", result.Item1.Get("g").AsString);
109+
Assert.AreEqual("a", result.Item1.Get("h").AsString);
104110
}
105111

106112
[TestMethod]
@@ -1088,12 +1094,14 @@ public void TestLocale()
10881094
#Const a = CDate(""2016/03/02"")
10891095
#Const b = CBool(""tRuE"")
10901096
#Const c = CBool(""#TRUE#"")
1097+
#Const d = ""ß"" = ""ss""
10911098
";
10921099
System.Threading.Thread.CurrentThread.CurrentCulture = new CultureInfo("ja-jp");
10931100
var result = Preprocess(code);
10941101
Assert.AreEqual(new DateTime(2016, 3, 2), result.Item1.Get("a").AsDate);
10951102
Assert.AreEqual(true, result.Item1.Get("b").AsBool);
10961103
Assert.AreEqual(true, result.Item1.Get("c").AsBool);
1104+
Assert.AreEqual(true, result.Item1.Get("d").AsBool);
10971105
}
10981106

10991107
[TestMethod]

0 commit comments

Comments
 (0)