Skip to content

Commit c6b2125

Browse files
committed
Add simple incorrect group specification test
1 parent 27dee65 commit c6b2125

File tree

1 file changed

+38
-0
lines changed

1 file changed

+38
-0
lines changed

RubberduckTests/RegexAssistant/RegularExpressionTests.cs

Lines changed: 38 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -248,5 +248,43 @@ public void GroupIsNotAnAlternativesExpression()
248248
new SingleAtomExpression(new Literal("b", Quantifier.None)),
249249
}.ToList()), "(a|b)", Quantifier.None), (expression as SingleAtomExpression).Atom);
250250
}
251+
252+
[Category("RegexAssistant")]
253+
[Test]
254+
public void UnbalancedGroupCorrectlyMarksPrecedingParenAsError()
255+
{
256+
var expected = new List<IRegularExpression>()
257+
{
258+
new ErrorExpression("("),
259+
new SingleAtomExpression(new Group(new SingleAtomExpression(new Literal("a", Quantifier.None)), "(a)", Quantifier.None))
260+
};
261+
var expression = VBRegexParser.Parse("((a)");
262+
Assert.IsInstanceOf(typeof(ConcatenatedExpression), expression);
263+
var subexpressions = (expression as ConcatenatedExpression).Subexpressions;
264+
Assert.AreEqual(expected.Count, subexpressions.Count);
265+
for (var i = 0; i < expected.Count; i++)
266+
{
267+
Assert.AreEqual(expected[i], subexpressions[i]);
268+
}
269+
}
270+
271+
[Category("RegexAssistant")]
272+
[Test]
273+
public void UnbalancedGroupCorrectlyMarksTrailingParenAsError()
274+
{
275+
var expected = new List<IRegularExpression>()
276+
{
277+
new SingleAtomExpression(new Group(new SingleAtomExpression(new Literal("a", Quantifier.None)), "(a)", Quantifier.None)),
278+
new ErrorExpression(")"),
279+
};
280+
var expression = VBRegexParser.Parse("(a))");
281+
Assert.IsInstanceOf(typeof(ConcatenatedExpression), expression);
282+
var subexpressions = (expression as ConcatenatedExpression).Subexpressions;
283+
Assert.AreEqual(expected.Count, subexpressions.Count);
284+
for (var i = 0; i < expected.Count; i++)
285+
{
286+
Assert.AreEqual(expected[i], subexpressions[i]);
287+
}
288+
}
251289
}
252290
}

0 commit comments

Comments
 (0)