42 std::string expression;
47 const std::vector<TestCase> cases = {
49 {
"@{dateformat(0)}",
"1970-01-01",
false },
50 {
"@{dateformat(0, \"ISO\")}",
"1970-01-01",
false },
51 {
"@{dateformat(0, \"iso\")}",
"1970-01-01",
false },
52 {
"@{dateformat(0, \"US\")}",
"01/01/1970",
false },
53 {
"@{dateformat(0, \"us\")}",
"01/01/1970",
false },
54 {
"@{dateformat(0, \"EU\")}",
"01/01/1970",
false },
55 {
"@{dateformat(0, \"european\")}",
"01/01/1970",
false },
56 {
"@{dateformat(0, \"long\")}",
"January 1, 1970",
false },
57 {
"@{dateformat(0, \"short\")}",
"Jan 1, 1970",
false },
60 {
"@{dateformat(365)}",
"1971-01-01",
false },
61 {
"@{dateformat(1000)}",
"1972-09-27",
false },
64 {
"@{weekdayname(0)}",
"Thursday",
false },
65 {
"@{weekdayname(1)}",
"Friday",
false },
66 {
"@{weekdayname(2)}",
"Saturday",
false },
67 {
"@{weekdayname(3)}",
"Sunday",
false },
68 {
"@{weekdayname(4)}",
"Monday",
false },
69 {
"@{weekdayname(5)}",
"Tuesday",
false },
70 {
"@{weekdayname(6)}",
"Wednesday",
false },
71 {
"@{weekdayname(7)}",
"Thursday",
false },
74 {
"@{dateformat(-1)}",
"1969-12-31",
false },
75 {
"@{weekdayname(-1)}",
"Wednesday",
false },
78 for(
const auto& testCase : cases )
80 auto result = evaluator.
Evaluate( wxString::FromUTF8( testCase.expression ) );
82 if( testCase.shouldError )
88 BOOST_CHECK_MESSAGE( !evaluator.
HasErrors(),
89 "Error in expression: " + testCase.expression +
104 std::string expression;
109 const std::vector<TestCase> cases = {
111 {
"@{dateformat(0, \"Chinese\")}",
"1970年01月01日",
false },
112 {
"@{dateformat(0, \"chinese\")}",
"1970年01月01日",
false },
113 {
"@{dateformat(0, \"CN\")}",
"1970年01月01日",
false },
114 {
"@{dateformat(0, \"cn\")}",
"1970年01月01日",
false },
116 {
"@{dateformat(0, \"Japanese\")}",
"1970年01月01日",
false },
117 {
"@{dateformat(0, \"japanese\")}",
"1970年01月01日",
false },
118 {
"@{dateformat(0, \"JP\")}",
"1970年01月01日",
false },
119 {
"@{dateformat(0, \"jp\")}",
"1970年01月01日",
false },
121 {
"@{dateformat(0, \"Korean\")}",
"1970년 01월 01일",
false },
122 {
"@{dateformat(0, \"korean\")}",
"1970년 01월 01일",
false },
123 {
"@{dateformat(0, \"KR\")}",
"1970년 01월 01일",
false },
124 {
"@{dateformat(0, \"kr\")}",
"1970년 01월 01일",
false },
127 {
"@{dateformat(365, \"Chinese\")}",
"1971年01月01日",
false },
128 {
"@{dateformat(365, \"Japanese\")}",
"1971年01月01日",
false },
129 {
"@{dateformat(365, \"Korean\")}",
"1971년 01월 01일",
false },
131 {
"@{dateformat(1000, \"Chinese\")}",
"1972年09月27日",
false },
132 {
"@{dateformat(1000, \"Japanese\")}",
"1972年09月27日",
false },
133 {
"@{dateformat(1000, \"Korean\")}",
"1972년 09월 27일",
false },
136 {
"@{dateformat(-1, \"Chinese\")}",
"1969年12月31日",
false },
137 {
"@{dateformat(-1, \"Japanese\")}",
"1969年12月31日",
false },
138 {
"@{dateformat(-1, \"Korean\")}",
"1969년 12월 31일",
false },
141 {
"@{dateformat(789, \"Chinese\")}",
"1972年02月29日",
false },
142 {
"@{dateformat(789, \"Japanese\")}",
"1972年02月29日",
false },
143 {
"@{dateformat(789, \"Korean\")}",
"1972년 02월 29일",
false },
146 for(
const auto& testCase : cases )
148 auto result = evaluator.
Evaluate( wxString::FromUTF8( testCase.expression ) );
150 if( testCase.shouldError )
156 BOOST_CHECK_MESSAGE( !evaluator.
HasErrors(),
157 "Error in expression: " + testCase.expression +
172 std::string expression;
177 const std::vector<TestCase> cases = {
179 {
"@{dateformat(0)}",
"1970-01-01",
false },
180 {
"@{upper(\"test\")}",
"TEST",
false },
183 {
"@{datestring(\"2024-03-15\")}",
"19797",
false },
184 {
"@{datestring(\"1970-01-01\")}",
"0",
false },
187 {
"@{datestring('2024年03月15日')}",
"19797",
false },
188 {
"@{datestring('1970年01月01日')}",
"0",
false },
189 {
"@{datestring('2024年01月01日')}",
"19723",
false },
190 {
"@{datestring('1972年02月29日')}",
"789",
false },
191 {
"@{datestring('1969年12月31日')}",
"-1",
false },
194 {
"@{datestring(\"2024년 03월 15일\")}",
"19797",
false },
195 {
"@{datestring(\"1970년 01월 01일\")}",
"0",
false },
196 {
"@{datestring(\"2024년 01월 01일\")}",
"19723",
false },
197 {
"@{datestring(\"1972년 02월 29일\")}",
"789",
false },
198 {
"@{datestring(\"1969년 12월 31일\")}",
"-1",
false },
201 {
"@{datestring(\"2024년03월15일\")}",
"19797",
false },
202 {
"@{datestring(\"1970년01월01일\")}",
"0",
false },
205 {
"@{dateformat(datestring('2024年03월15일'), 'ISO')}",
"2024-03-15",
false },
206 {
"@{dateformat(datestring('2024년 03월 15일'), 'ISO')}",
"2024-03-15",
false },
207 {
"@{dateformat(datestring('1970年01月01日'), 'US')}",
"01/01/1970",
false },
208 {
"@{dateformat(datestring('1970년 01월 01일'), 'EU')}",
"01/01/1970",
false },
211 {
"@{dateformat(datestring('2024年03월15日'), 'Chinese')}",
"2024年03月15日",
false },
212 {
"@{dateformat(datestring('2024년 03월 15일'), 'Korean')}",
"2024년 03월 15일",
false },
215 {
"@{datestring('2024年13月15日')}",
"",
true },
216 {
"@{datestring('2024년 02월 30일')}",
"",
true },
217 {
"@{datestring('2024年02月')}",
"",
true },
218 {
"@{datestring('2024년')}",
"",
true },
221 for(
const auto& testCase : cases )
223 auto result = evaluator.
Evaluate( wxString::FromUTF8( testCase.expression ) );
225 if( testCase.shouldError )
227 BOOST_CHECK_MESSAGE( evaluator.
HasErrors(),
228 "Expected error but got result: " +
229 result.ToStdString( wxConvUTF8 ) +
230 " for expression: " + testCase.expression );
234 BOOST_CHECK_MESSAGE( !evaluator.
HasErrors(),
235 "Error in expression: " + testCase.expression +
249 auto todayResult = evaluator.
Evaluate(
"@{today()}" );
253 double todayDays = std::stod( todayResult.ToStdString() );
257 BOOST_CHECK_GT( todayDays, 19000 );
258 BOOST_CHECK_LT( todayDays, 50000 );
261 auto nowResult = evaluator.
Evaluate(
"@{now()}" );
265 double nowTimestamp = std::stod( nowResult.ToStdString() );
268 auto currentTime = std::chrono::system_clock::now();
269 auto currentTimestamp = std::chrono::system_clock::to_time_t( currentTime );
270 double currentTimestampDouble =
static_cast<double>( currentTimestamp );
273 BOOST_CHECK_CLOSE( nowTimestamp, currentTimestampDouble, 1.0 );
276 auto todayResult2 = evaluator.
Evaluate(
"@{today()}" );
280 auto formattedToday = evaluator.
Evaluate(
"@{dateformat(today(), \"ISO\")}" );
284 std::regex isoDateRegex( R
"(\d{4}-\d{2}-\d{2})" );
285 BOOST_CHECK( std::regex_match( formattedToday.ToStdString(), isoDateRegex ) );
296 std::string expression;
301 const std::vector<TestCase> cases = {
303 {
"@{dateformat(0 + 1)}",
"1970-01-02",
false },
304 {
"@{dateformat(0 + 7)}",
"1970-01-08",
false },
305 {
"@{dateformat(0 + 30)}",
"1970-01-31",
false },
306 {
"@{dateformat(0 + 365)}",
"1971-01-01",
false },
309 {
"@{dateformat(365 + 365 + 366)}",
"1973-01-01",
false },
312 {
"@{365 - 0}",
"365",
false },
315 {
"@{weekdayname(today())}",
"",
false },
318 for(
const auto& testCase : cases )
320 auto result = evaluator.
Evaluate( wxString::FromUTF8( testCase.expression ) );
322 if( testCase.shouldError )
330 if( !testCase.expected.empty() )
337 BOOST_CHECK( !
result.empty() );
351 std::string expression;
356 const std::vector<TestCase> cases = {
358 {
"@{dateformat(365 + 365 + 59)}",
"1972-02-29",
false },
359 {
"@{dateformat(365 + 365 + 60)}",
"1972-03-01",
false },
362 {
"@{dateformat(365 - 1)}",
"1970-12-31",
false },
363 {
"@{dateformat(365)}",
"1971-01-01",
false },
366 {
"@{dateformat(30)}",
"1970-01-31",
false },
367 {
"@{dateformat(31)}",
"1970-02-01",
false },
368 {
"@{dateformat(58)}",
"1970-02-28",
false },
369 {
"@{dateformat(59)}",
"1970-03-01",
false },
372 {
"@{dateformat(36525)}",
"2070-01-01",
false },
375 {
"@{dateformat(-365)}",
"1969-01-01",
false },
376 {
"@{dateformat(-1)}",
"1969-12-31",
false },
379 {
"@{weekdayname(-1)}",
"Wednesday",
false },
380 {
"@{weekdayname(-7)}",
"Thursday",
false },
383 {
"@{weekdayname(7000)}",
"Thursday",
false },
386 for(
const auto& testCase : cases )
388 auto result = evaluator.
Evaluate( wxString::FromUTF8( testCase.expression ) );
390 if( testCase.shouldError )
396 BOOST_CHECK_MESSAGE( !evaluator.
HasErrors(),
397 "Error in expression: " + testCase.expression );
412 std::string expression;
416 const std::vector<TestCase> cases = {
418 {
"Today is @{dateformat(today())} which is @{weekdayname(today())}",
true },
419 {
"Date: @{dateformat(0 + ${days_offset}, \"long\")}",
true },
420 {
"In @{format(${days_offset})} days: @{dateformat(today() + ${days_offset})}",
true },
423 {
"@{upper(weekdayname(today()))}",
true },
424 {
"@{lower(dateformat(today(), \"long\"))}",
true },
427 {
"Start: @{dateformat(0)} End: @{dateformat(365)} Duration: @{365 - 0} days",
true },
430 for(
const auto& testCase : cases )
432 auto result = evaluator.
Evaluate( wxString::FromUTF8( testCase.expression ) );
434 if( testCase.shouldWork )
436 BOOST_CHECK_MESSAGE( !evaluator.
HasErrors(),
437 "Error in expression: " + testCase.expression +
438 " Result: " +
result.ToStdString( wxConvUTF8 ) );
439 BOOST_CHECK( !
result.empty() );
456 auto start = std::chrono::high_resolution_clock::now();
459 for(
int i = 0; i < 1000; ++i )
461 auto result = evaluator.
Evaluate(
"@{dateformat(" + std::to_string(i) +
")}" );
465 auto end = std::chrono::high_resolution_clock::now();
466 auto duration = std::chrono::duration_cast<std::chrono::milliseconds>(
end - start );
469 BOOST_CHECK_LT( duration.count(), 100 );
High-level wrapper for evaluating mathematical and string expressions in wxString format.
wxString Evaluate(const wxString &aInput)
Main evaluation function - processes input string and evaluates all} expressions.
bool HasErrors() const
Check if the last evaluation had errors.
wxString GetErrorSummary() const
Get detailed error information from the last evaluation.
void SetVariable(const wxString &aName, double aValue)
Set a numeric variable for use in expressions.
BOOST_AUTO_TEST_CASE(HorizontalAlignment)
BOOST_AUTO_TEST_SUITE(CadstarPartParser)
BOOST_AUTO_TEST_SUITE_END()
VECTOR3I expected(15, 30, 45)
wxString result
Test unit parsing edge cases and error handling.
BOOST_CHECK_EQUAL(result, "25.4")
BOOST_AUTO_TEST_CASE(DateFormatting)