Skip to content

Commit

Permalink
Tests added, hack removed, resolver happy
Browse files Browse the repository at this point in the history
  • Loading branch information
mansellan committed Jun 23, 2018
1 parent 57e51f3 commit 9238e68
Show file tree
Hide file tree
Showing 2 changed files with 115 additions and 10 deletions.
12 changes: 3 additions & 9 deletions Rubberduck.Parsing/Binding/Bindings/SimpleNameDefaultBinding.cs
@@ -1,7 +1,6 @@
using Antlr4.Runtime;
using Rubberduck.Parsing.Symbols;
using System.Linq;
using Rubberduck.Parsing.Grammar;

namespace Rubberduck.Parsing.Binding
{
Expand Down Expand Up @@ -75,14 +74,9 @@ public IBoundExpression Resolve()
var bracketedExpression = _declarationFinder.OnBracketedExpression(_context.GetText(), _context);
return new SimpleNameExpression(bracketedExpression, ExpressionClassification.Unbound, _context);
}
//TODO - this is a complete and total hack to prevent `Mid` and `Mid$` from creating undeclared variables
//pending an actual fix to the grammar. See #2618
else if (!_name.Equals("Mid") && !_name.Equals("Mid$"))
{
var undeclaredLocal = _declarationFinder.OnUndeclaredVariable(_parent, _name, _context);
return new SimpleNameExpression(undeclaredLocal, ExpressionClassification.Variable, _context);
}
return new ResolutionFailedExpression();

var undeclaredLocal = _declarationFinder.OnUndeclaredVariable(_parent, _name, _context);
return new SimpleNameExpression(undeclaredLocal, ExpressionClassification.Variable, _context);
}

private IBoundExpression ResolveProcedureNamespace()
Expand Down
113 changes: 112 additions & 1 deletion RubberduckTests/Grammar/VBAParserTests.cs
Expand Up @@ -2873,7 +2873,118 @@ End Sub
var parseResult = Parse(code);
AssertTree(parseResult.Item1, parseResult.Item2, "//midStatement", matches => matches.Count == 1);
}


[Category("Parser")]
[Test]
public void MidDollarStatement()
{
const string code = @"
Public Sub Test()
Dim TestString As String
TestString = ""The dog jumps""
Mid$(TestString, 5, 3) = ""fox""
End Sub
";
var parseResult = Parse(code);
AssertTree(parseResult.Item1, parseResult.Item2, "//midStatement", matches => matches.Count == 1);
}

public void MidBStatement()
{
const string code = @"
Public Sub Test()
Dim TestString As String
TestString = ""The dog jumps""
MidB(TestString, 5, 3) = ""fox""
End Sub
";
var parseResult = Parse(code);
AssertTree(parseResult.Item1, parseResult.Item2, "//midStatement", matches => matches.Count == 1);
}

[Category("Parser")]
[Test]
public void MidBDollarStatement()
{
const string code = @"
Public Sub Test()
Dim TestString As String
TestString = ""The dog jumps""
MidB$(TestString, 5, 3) = ""fox""
End Sub
";
var parseResult = Parse(code);
AssertTree(parseResult.Item1, parseResult.Item2, "//midStatement", matches => matches.Count == 1);
}

[Category("Parser")]
[Test]
public void MidFunction()
{
const string code = @"
Public Sub Test()
Dim TestString As String
TestString = ""The dog jumps""
If Mid(TestString, 5, 3) = ""fox"" Then
MsgBox ""Found""
End If
End Sub
";
var parseResult = Parse(code);
AssertTree(parseResult.Item1, parseResult.Item2, "//midStatement", matches => matches.Count == 0);
}

[Category("Parser")]
[Test]
public void MidDollarFunction()
{
const string code = @"
Public Sub Test()
Dim TestString As String
TestString = ""The dog jumps""
If Mid$(TestString, 5, 3) = ""fox"" Then
MsgBox ""Found""
End If
End Sub
";
var parseResult = Parse(code);
AssertTree(parseResult.Item1, parseResult.Item2, "//midStatement", matches => matches.Count == 0);
}

[Category("Parser")]
[Test]
public void MidBFunction()
{
const string code = @"
Public Sub Test()
Dim TestString As String
TestString = ""The dog jumps""
If MidB(TestString, 5, 3) = ""fox"" Then
MsgBox ""Found""
End If
End Sub
";
var parseResult = Parse(code);
AssertTree(parseResult.Item1, parseResult.Item2, "//midStatement", matches => matches.Count == 0);
}

[Category("Parser")]
[Test]
public void MidBDollarFunction()
{
const string code = @"
Public Sub Test()
Dim TestString As String
TestString = ""The dog jumps""
If MidB$(TestString, 5, 3) = ""fox"" Then
MsgBox ""Found""
End If
End Sub
";
var parseResult = Parse(code);
AssertTree(parseResult.Item1, parseResult.Item2, "//midStatement", matches => matches.Count == 0);
}

private Tuple<VBAParser, ParserRuleContext> Parse(string code, PredictionMode predictionMode = null)
{
var stream = new AntlrInputStream(code);
Expand Down

0 comments on commit 9238e68

Please sign in to comment.