@@ -134,6 +134,15 @@ void TestExpressionParser::multiRegistersDuplicate()
134134 verifyParsing (input, expDataPoints, expExpressions);
135135}
136136
137+ void TestExpressionParser::singleExpressionDuplicate ()
138+ {
139+ auto input = QStringList () << " ${45332} + ${45332}" ;
140+ auto expExpressions = QStringList () << " r(0 ) + r(0 )" ;
141+ auto expDataPoints = QList<DataPoint>() << DataPoint (" ${45332}" , Device::cFirstDeviceId);
142+
143+ verifyParsing (input, expDataPoints, expExpressions);
144+ }
145+
137146void TestExpressionParser::failure ()
138147{
139148 auto input = QStringList () << " ${}" ;
@@ -236,16 +245,34 @@ void TestExpressionParser::manyRegisters()
236245 verifyParsing (input, expDataPoints, expExpressions);
237246}
238247
239- void TestExpressionParser::verifyParsing (QStringList exprList,
240- QList<DataPoint>& expectedDataPoints,
241- QStringList& expectedExpression)
248+ void TestExpressionParser::manyRegistersHighIndex ()
242249{
243- QList<DataPoint> actualDataPoints;
244- QStringList actualExpressionList;
250+ /* Verify qMax(0,...) guard: ${0} is 4 chars, but assigned index 10 (after 10 prior registers).
251+ * Unguarded: spacesCount = 4-3-2 = -1. Guarded: clamped to 0, producing r(10) instead of garbage. */
252+ auto input = QStringList () << " ${1}" << " ${2}" << " ${3}" << " ${4}" << " ${5}"
253+ << " ${6}" << " ${7}" << " ${8}" << " ${9}" << " ${10}" << " ${0}" ;
254+ auto expDataPoints = QList<DataPoint>()
255+ << DataPoint (" ${1}" , Device::cFirstDeviceId) << DataPoint (" ${2}" , Device::cFirstDeviceId)
256+ << DataPoint (" ${3}" , Device::cFirstDeviceId) << DataPoint (" ${4}" , Device::cFirstDeviceId)
257+ << DataPoint (" ${5}" , Device::cFirstDeviceId) << DataPoint (" ${6}" , Device::cFirstDeviceId)
258+ << DataPoint (" ${7}" , Device::cFirstDeviceId) << DataPoint (" ${8}" , Device::cFirstDeviceId)
259+ << DataPoint (" ${9}" , Device::cFirstDeviceId) << DataPoint (" ${10}" , Device::cFirstDeviceId)
260+ << DataPoint (" ${0}" , Device::cFirstDeviceId);
261+ /* ${10} at idx=9: size=5, spacesCount=5-3-1=1 → r(9 )
262+ * ${0} at idx=10: size=4, spacesCount=qMax(0,4-3-2)=0 → r(10) */
263+ auto expExpressions = QStringList () << " r(0)" << " r(1)" << " r(2)" << " r(3)" << " r(4)"
264+ << " r(5)" << " r(6)" << " r(7)" << " r(8)" << " r(9 )" << " r(10)" ;
245265
266+ verifyParsing (input, expDataPoints, expExpressions);
267+ }
268+
269+ void TestExpressionParser::verifyParsing (const QStringList& exprList,
270+ const QList<DataPoint>& expectedDataPoints,
271+ const QStringList& expectedExpression)
272+ {
246273 ExpressionParser parser (exprList);
247- parser.dataPoints (actualDataPoints );
248- parser.processedExpressions (actualExpressionList );
274+ const QList<DataPoint> actualDataPoints = parser.dataPoints ();
275+ const QStringList actualExpressionList = parser.processedExpressions ();
249276
250277 QVERIFY (actualDataPoints == expectedDataPoints);
251278 QVERIFY (actualExpressionList == expectedExpression);
0 commit comments