File tree 2 files changed +34
-1
lines changed
2 files changed +34
-1
lines changed Original file line number Diff line number Diff line change @@ -1086,6 +1086,25 @@ TEST_CASE("Copy", "[copy]")
1086
1086
}
1087
1087
}
1088
1088
1089
+ TEST_CASE (" Empty" , " [empty]" )
1090
+ {
1091
+ te_parser tep;
1092
+
1093
+ SECTION (" Empty Eval" )
1094
+ {
1095
+ CHECK (std::isnan (tep.evaluate ()));
1096
+ CHECK_FALSE (tep.success ());
1097
+ CHECK (std::string{ " Expression is emtpy." } == tep.get_last_error_message ());
1098
+ }
1099
+
1100
+ SECTION (" Empty String" )
1101
+ {
1102
+ CHECK (std::isnan (tep.evaluate (" " )));
1103
+ CHECK_FALSE (tep.success ());
1104
+ CHECK (std::string{ " Expression is emtpy." } == tep.get_last_error_message ());
1105
+ }
1106
+ }
1107
+
1089
1108
TEST_CASE (" Inf" , " [inf]" )
1090
1109
{
1091
1110
te_parser tep;
Original file line number Diff line number Diff line change @@ -2484,7 +2484,7 @@ bool te_parser::compile(const std::string_view expression)
2484
2484
reset_state ();
2485
2485
if (get_list_separator () == get_decimal_separator ())
2486
2486
{
2487
- throw std::runtime_error (" List and decimal separators cannot be the same" );
2487
+ throw std::runtime_error (" List and decimal separators cannot be the same. " );
2488
2488
}
2489
2489
if (expression.empty ())
2490
2490
{
@@ -2561,6 +2561,12 @@ te_type te_parser::evaluate()
2561
2561
{
2562
2562
try
2563
2563
{
2564
+ if (m_expression.empty ())
2565
+ {
2566
+ m_parseSuccess = false ;
2567
+ m_errorPos = 0 ;
2568
+ m_lastErrorMessage = " Expression is emtpy." ;
2569
+ }
2564
2570
m_result = (m_compiledExpression != nullptr ) ? te_eval (m_compiledExpression) : te_nan;
2565
2571
}
2566
2572
catch (const std::exception & expt)
@@ -2583,6 +2589,14 @@ te_parser::evaluate(const std::string_view expression) // NOLINT(-readability-id
2583
2589
{
2584
2590
return evaluate ();
2585
2591
}
2592
+
2593
+ if (expression.empty ())
2594
+ {
2595
+ m_parseSuccess = false ;
2596
+ m_errorPos = 0 ;
2597
+ m_lastErrorMessage = " Expression is emtpy." ;
2598
+ }
2599
+
2586
2600
return te_nan;
2587
2601
}
2588
2602
You can’t perform that action at this time.
0 commit comments