Skip to content

Commit

Permalink
Added tests, fixed remaining issues.
Browse files Browse the repository at this point in the history
  • Loading branch information
mansellan committed Jun 22, 2018
1 parent afa628c commit 7e5fe7f
Show file tree
Hide file tree
Showing 3 changed files with 179 additions and 1 deletion.
1 change: 1 addition & 0 deletions Rubberduck.Parsing/Grammar/VBALexer.g4
Original file line number Diff line number Diff line change
Expand Up @@ -302,6 +302,7 @@ WS : [ \t];
GUIDLITERAL : '{' [0-9A-F]+ '-' [0-9A-F]+ '-' [0-9A-F]+ '-' [0-9A-F]+ '-' [0-9A-F]+ '}';
IDENTIFIER : ~[[\](){}\r\n\t.,'"|!@#$%^&*\-+:=; 0-9-/\\-] ~[[\](){}\r\n\t.,'"|!@#$%^&*\-+:=; -]*;
LINE_CONTINUATION : [ \t]* UNDERSCORE [ \t]* '\r'? '\n';
BARE_HEX_LITERAL : [0-9a-fA-F]+;
fragment LETTER : [a-zA-Z_äöüÄÖÜ];
fragment DIGIT : [0-9];
fragment LETTERORDIGIT : [a-zA-Z0-9_äöüÄÖÜ];
Expand Down
2 changes: 1 addition & 1 deletion Rubberduck.Parsing/Grammar/VBAParser.g4
Original file line number Diff line number Diff line change
Expand Up @@ -62,7 +62,7 @@ moduleConfigProperty :
;

moduleConfigElement :
lExpression whiteSpace? EQ whiteSpace? (shortcut | DOLLAR? expression) (COLON (numberLiteral | IDENTIFIER))? endOfStatement
(unrestrictedIdentifier | lExpression) whiteSpace? EQ whiteSpace? (shortcut | DOLLAR? expression) (COLON (numberLiteral | BARE_HEX_LITERAL | unrestrictedIdentifier))? endOfStatement
;

shortcut :
Expand Down
177 changes: 177 additions & 0 deletions RubberduckTests/Grammar/VBAParserTests.cs
Original file line number Diff line number Diff line change
Expand Up @@ -665,6 +665,183 @@ public void TestVBFormModuleConfig()
AssertTree(parseResult.Item1, parseResult.Item2, "//moduleConfig", matches => matches.Count == 1);
}

[Category("Parser")]
[Test]
public void TestVBFormWithHexLiteralModuleConfig()
{
string code = @"
Begin VB.Form Form1
BackColor = &H00FFFFFF&
Caption = ""Form1""
ClientHeight = 2640
ClientLeft = 45
ClientTop = 375
ClientWidth = 4710
OleObjectBlob = ""Form1.frx"":0000
StartUpPosition = 1 'CenterOwner
End
";
var parseResult = Parse(code);
AssertTree(parseResult.Item1, parseResult.Item2, "//moduleConfig", matches => matches.Count == 1);
}

[Category("Parser")]
[Test]
public void TestVBFormWithAbsoluteResourcePathConfig()
{
string code = @"
Begin VB.Form Form1
BackColor = &H00FFFFFF&
Caption = ""Form1""
ClientHeight = 2640
ClientLeft = 45
ClientTop = 375
ClientWidth = 4710
OleObjectBlob = ""C:\Test\Form1.frx"":0000
StartUpPosition = 1 'CenterOwner
End
";
var parseResult = Parse(code);
AssertTree(parseResult.Item1, parseResult.Item2, "//moduleConfig", matches => matches.Count == 1);
}

[Category("Parser")]
[Test]
public void TestVBFormWithDnsUncResourcePathConfig()
{
string code = @"
Begin VB.Form Form1
BackColor = &H00FFFFFF&
Caption = ""Form1""
ClientHeight = 2640
ClientLeft = 45
ClientTop = 375
ClientWidth = 4710
OleObjectBlob = ""\\initech.com\server01\c$\Test\Form1.frx"":0000
StartUpPosition = 1 'CenterOwner
End
";
var parseResult = Parse(code);
AssertTree(parseResult.Item1, parseResult.Item2, "//moduleConfig", matches => matches.Count == 1);
}

[Category("Parser")]
[Test]
public void TestVBFormWithIPUncResourcePathConfig()
{
string code = @"
Begin VB.Form Form1
BackColor = &H00FFFFFF&
Caption = ""Form1""
ClientHeight = 2640
ClientLeft = 45
ClientTop = 375
ClientWidth = 4710
OleObjectBlob = ""\\127.0.0.1\Test\Form1.frx"":0000
StartUpPosition = 1 'CenterOwner
End
";
var parseResult = Parse(code);
AssertTree(parseResult.Item1, parseResult.Item2, "//moduleConfig", matches => matches.Count == 1);
}

[Category("Parser")]
[Test]
public void TestVBFormWithDollarPrependedResourceModuleConfig()
{
string code = @"
Begin VB.Form Form1
Caption = ""Form1""
ClientHeight = 2640
ClientLeft = 45
ClientTop = 375
ClientWidth = 4710
OleObjectBlob = $""Form1.frx"":0000
StartUpPosition = 1 'CenterOwner
End
";
var parseResult = Parse(code);
AssertTree(parseResult.Item1, parseResult.Item2, "//moduleConfig", matches => matches.Count == 1);
}

[Category("Parser")]
[Test]
public void TestVBFormWithAlphaLeadingHexLiteralResourceOffsetModuleConfig()
{
string code = @"
Begin VB.Form Form1
Caption = ""Form1""
ClientHeight = 2640
ClientLeft = 45
ClientTop = 375
ClientWidth = 4710
OleObjectBlob = ""Form1.frx"":ACBD
StartUpPosition = 1 'CenterOwner
End
";
var parseResult = Parse(code);
AssertTree(parseResult.Item1, parseResult.Item2, "//moduleConfig", matches => matches.Count == 1);
}

[Category("Parser")]
[Test]
public void TestVBFormWithNumericLeadingHexLiteralResourceOffsetModuleConfig()
{
string code = @"
Begin VB.Form Form1
Caption = ""Form1""
ClientHeight = 2640
ClientLeft = 45
ClientTop = 375
ClientWidth = 4710
OleObjectBlob = ""Form1.frx"":9ABC
StartUpPosition = 1 'CenterOwner
End
";
var parseResult = Parse(code);
AssertTree(parseResult.Item1, parseResult.Item2, "//moduleConfig", matches => matches.Count == 1);
}

[Category("Parser")]
[Test]
[TestCase(@"^A")]
[TestCase(@"^Z")]
[TestCase(@"{F1}")]
[TestCase(@"{F12}")]
[TestCase(@"^{F1}")]
[TestCase(@"^{F12}")]
[TestCase(@"+^{F1}")]
[TestCase(@"+^{F12}")]
[TestCase(@"^{INSERT}")]
[TestCase(@"+{INSERT}")]
[TestCase(@"{DEL}")]
[TestCase(@"+{DEL}")]
[TestCase(@"%{BKSP}")]
public void TestVBFormWithMenuShortcutModuleConfig(string shortcut)
{
string code = @"
Begin VB.Form Form1
Caption = ""Form1""
ClientHeight = 2640
ClientLeft = 45
ClientTop = 375
ClientWidth = 4710
OleObjectBlob = ""Form1.frx"":0000
StartUpPosition = 1 'CenterOwner
Begin VB.Menu FileMenu
Caption = ""File""
Begin VB.Menu FileOpenMenu
Caption = ""Open""
Shortcut = " + shortcut + @"
End
End
End
";
var parseResult = Parse(code);
AssertTree(parseResult.Item1, parseResult.Item2, "//moduleConfig", matches => matches.Count == 3);
}


[Category("Parser")]
[Test]
public void TestNestedVbFormModuleConfig()
Expand Down

0 comments on commit 7e5fe7f

Please sign in to comment.