38 std::string expression;
43 const std::vector<TestCase> cases = {
45 {
"@{dateformat(0)}",
"1970-01-01",
false },
46 {
"@{dateformat(0, \"ISO\")}",
"1970-01-01",
false },
47 {
"@{dateformat(0, \"iso\")}",
"1970-01-01",
false },
48 {
"@{dateformat(0, \"US\")}",
"01/01/1970",
false },
49 {
"@{dateformat(0, \"us\")}",
"01/01/1970",
false },
50 {
"@{dateformat(0, \"EU\")}",
"01/01/1970",
false },
51 {
"@{dateformat(0, \"european\")}",
"01/01/1970",
false },
52 {
"@{dateformat(0, \"long\")}",
"January 1, 1970",
false },
53 {
"@{dateformat(0, \"short\")}",
"Jan 1, 1970",
false },
56 {
"@{dateformat(365)}",
"1971-01-01",
false },
57 {
"@{dateformat(1000)}",
"1972-09-27",
false },
60 {
"@{weekdayname(0)}",
"Thursday",
false },
61 {
"@{weekdayname(1)}",
"Friday",
false },
62 {
"@{weekdayname(2)}",
"Saturday",
false },
63 {
"@{weekdayname(3)}",
"Sunday",
false },
64 {
"@{weekdayname(4)}",
"Monday",
false },
65 {
"@{weekdayname(5)}",
"Tuesday",
false },
66 {
"@{weekdayname(6)}",
"Wednesday",
false },
67 {
"@{weekdayname(7)}",
"Thursday",
false },
70 {
"@{dateformat(-1)}",
"1969-12-31",
false },
71 {
"@{weekdayname(-1)}",
"Wednesday",
false },
74 for(
const auto& testCase : cases )
76 auto result = evaluator.
Evaluate( wxString::FromUTF8( testCase.expression ) );
78 if( testCase.shouldError )
85 "Error in expression: " + testCase.expression +
100 std::string expression;
105 const std::vector<TestCase> cases = {
107 {
"@{dateformat(0, \"Chinese\")}",
"1970年01月01日",
false },
108 {
"@{dateformat(0, \"chinese\")}",
"1970年01月01日",
false },
109 {
"@{dateformat(0, \"CN\")}",
"1970年01月01日",
false },
110 {
"@{dateformat(0, \"cn\")}",
"1970年01月01日",
false },
112 {
"@{dateformat(0, \"Japanese\")}",
"1970年01月01日",
false },
113 {
"@{dateformat(0, \"japanese\")}",
"1970年01月01日",
false },
114 {
"@{dateformat(0, \"JP\")}",
"1970年01月01日",
false },
115 {
"@{dateformat(0, \"jp\")}",
"1970年01月01日",
false },
117 {
"@{dateformat(0, \"Korean\")}",
"1970년 01월 01일",
false },
118 {
"@{dateformat(0, \"korean\")}",
"1970년 01월 01일",
false },
119 {
"@{dateformat(0, \"KR\")}",
"1970년 01월 01일",
false },
120 {
"@{dateformat(0, \"kr\")}",
"1970년 01월 01일",
false },
123 {
"@{dateformat(365, \"Chinese\")}",
"1971年01月01日",
false },
124 {
"@{dateformat(365, \"Japanese\")}",
"1971年01月01日",
false },
125 {
"@{dateformat(365, \"Korean\")}",
"1971년 01월 01일",
false },
127 {
"@{dateformat(1000, \"Chinese\")}",
"1972年09月27日",
false },
128 {
"@{dateformat(1000, \"Japanese\")}",
"1972年09月27日",
false },
129 {
"@{dateformat(1000, \"Korean\")}",
"1972년 09월 27일",
false },
132 {
"@{dateformat(-1, \"Chinese\")}",
"1969年12月31日",
false },
133 {
"@{dateformat(-1, \"Japanese\")}",
"1969年12月31日",
false },
134 {
"@{dateformat(-1, \"Korean\")}",
"1969년 12월 31일",
false },
137 {
"@{dateformat(789, \"Chinese\")}",
"1972年02月29日",
false },
138 {
"@{dateformat(789, \"Japanese\")}",
"1972年02月29日",
false },
139 {
"@{dateformat(789, \"Korean\")}",
"1972년 02월 29일",
false },
142 for(
const auto& testCase : cases )
144 auto result = evaluator.
Evaluate( wxString::FromUTF8( testCase.expression ) );
146 if( testCase.shouldError )
153 "Error in expression: " + testCase.expression +
168 std::string expression;
173 const std::vector<TestCase> cases = {
175 {
"@{dateformat(0)}",
"1970-01-01",
false },
176 {
"@{upper(\"test\")}",
"TEST",
false },
179 {
"@{datestring(\"2024-03-15\")}",
"19797",
false },
180 {
"@{datestring(\"1970-01-01\")}",
"0",
false },
183 {
"@{datestring('2024年03月15日')}",
"19797",
false },
184 {
"@{datestring('1970年01月01日')}",
"0",
false },
185 {
"@{datestring('2024年01月01日')}",
"19723",
false },
186 {
"@{datestring('1972年02月29日')}",
"789",
false },
187 {
"@{datestring('1969年12月31日')}",
"-1",
false },
190 {
"@{datestring(\"2024년 03월 15일\")}",
"19797",
false },
191 {
"@{datestring(\"1970년 01월 01일\")}",
"0",
false },
192 {
"@{datestring(\"2024년 01월 01일\")}",
"19723",
false },
193 {
"@{datestring(\"1972년 02월 29일\")}",
"789",
false },
194 {
"@{datestring(\"1969년 12월 31일\")}",
"-1",
false },
197 {
"@{datestring(\"2024년03월15일\")}",
"19797",
false },
198 {
"@{datestring(\"1970년01월01일\")}",
"0",
false },
201 {
"@{dateformat(datestring('2024年03월15일'), 'ISO')}",
"2024-03-15",
false },
202 {
"@{dateformat(datestring('2024년 03월 15일'), 'ISO')}",
"2024-03-15",
false },
203 {
"@{dateformat(datestring('1970年01月01日'), 'US')}",
"01/01/1970",
false },
204 {
"@{dateformat(datestring('1970년 01월 01일'), 'EU')}",
"01/01/1970",
false },
207 {
"@{dateformat(datestring('2024年03월15日'), 'Chinese')}",
"2024年03月15日",
false },
208 {
"@{dateformat(datestring('2024년 03월 15일'), 'Korean')}",
"2024년 03월 15일",
false },
211 {
"@{datestring('2024年13月15日')}",
"",
true },
212 {
"@{datestring('2024년 02월 30일')}",
"",
true },
213 {
"@{datestring('2024年02月')}",
"",
true },
214 {
"@{datestring('2024년')}",
"",
true },
217 for(
const auto& testCase : cases )
219 auto result = evaluator.
Evaluate( wxString::FromUTF8( testCase.expression ) );
221 if( testCase.shouldError )
224 "Expected error but got result: " +
225 result.ToStdString( wxConvUTF8 ) +
226 " for expression: " + testCase.expression );
231 "Error in expression: " + testCase.expression +
245 auto todayResult = evaluator.
Evaluate(
"@{today()}" );
249 double todayDays = std::stod( todayResult.ToStdString() );
253 BOOST_CHECK_GT( todayDays, 19000 );
254 BOOST_CHECK_LT( todayDays, 50000 );
257 auto nowResult = evaluator.
Evaluate(
"@{now()}" );
261 double nowTimestamp = std::stod( nowResult.ToStdString() );
264 auto currentTime = std::chrono::system_clock::now();
265 auto currentTimestamp = std::chrono::system_clock::to_time_t( currentTime );
266 double currentTimestampDouble =
static_cast<double>( currentTimestamp );
269 BOOST_CHECK_CLOSE( nowTimestamp, currentTimestampDouble, 1.0 );
272 auto todayResult2 = evaluator.
Evaluate(
"@{today()}" );
276 auto formattedToday = evaluator.
Evaluate(
"@{dateformat(today(), \"ISO\")}" );
280 std::regex isoDateRegex( R
"(\d{4}-\d{2}-\d{2})" );
281 BOOST_CHECK( std::regex_match( formattedToday.ToStdString(), isoDateRegex ) );
292 std::string expression;
297 const std::vector<TestCase> cases = {
299 {
"@{dateformat(0 + 1)}",
"1970-01-02",
false },
300 {
"@{dateformat(0 + 7)}",
"1970-01-08",
false },
301 {
"@{dateformat(0 + 30)}",
"1970-01-31",
false },
302 {
"@{dateformat(0 + 365)}",
"1971-01-01",
false },
305 {
"@{dateformat(365 + 365 + 366)}",
"1973-01-01",
false },
308 {
"@{365 - 0}",
"365",
false },
311 {
"@{weekdayname(today())}",
"",
false },
314 for(
const auto& testCase : cases )
316 auto result = evaluator.
Evaluate( wxString::FromUTF8( testCase.expression ) );
318 if( testCase.shouldError )
326 if( !testCase.expected.empty() )
333 BOOST_CHECK( !
result.empty() );
347 std::string expression;
352 const std::vector<TestCase> cases = {
354 {
"@{dateformat(365 + 365 + 59)}",
"1972-02-29",
false },
355 {
"@{dateformat(365 + 365 + 60)}",
"1972-03-01",
false },
358 {
"@{dateformat(365 - 1)}",
"1970-12-31",
false },
359 {
"@{dateformat(365)}",
"1971-01-01",
false },
362 {
"@{dateformat(30)}",
"1970-01-31",
false },
363 {
"@{dateformat(31)}",
"1970-02-01",
false },
364 {
"@{dateformat(58)}",
"1970-02-28",
false },
365 {
"@{dateformat(59)}",
"1970-03-01",
false },
368 {
"@{dateformat(36525)}",
"2070-01-01",
false },
371 {
"@{dateformat(-365)}",
"1969-01-01",
false },
372 {
"@{dateformat(-1)}",
"1969-12-31",
false },
375 {
"@{weekdayname(-1)}",
"Wednesday",
false },
376 {
"@{weekdayname(-7)}",
"Thursday",
false },
379 {
"@{weekdayname(7000)}",
"Thursday",
false },
382 for(
const auto& testCase : cases )
384 auto result = evaluator.
Evaluate( wxString::FromUTF8( testCase.expression ) );
386 if( testCase.shouldError )
393 "Error in expression: " + testCase.expression );
408 std::string expression;
412 const std::vector<TestCase> cases = {
414 {
"Today is @{dateformat(today())} which is @{weekdayname(today())}",
true },
415 {
"Date: @{dateformat(0 + ${days_offset}, \"long\")}",
true },
416 {
"In @{format(${days_offset})} days: @{dateformat(today() + ${days_offset})}",
true },
419 {
"@{upper(weekdayname(today()))}",
true },
420 {
"@{lower(dateformat(today(), \"long\"))}",
true },
423 {
"Start: @{dateformat(0)} End: @{dateformat(365)} Duration: @{365 - 0} days",
true },
426 for(
const auto& testCase : cases )
428 auto result = evaluator.
Evaluate( wxString::FromUTF8( testCase.expression ) );
430 if( testCase.shouldWork )
433 "Error in expression: " + testCase.expression +
434 " Result: " +
result.ToStdString( wxConvUTF8 ) );
435 BOOST_CHECK( !
result.empty() );
452 auto start = std::chrono::high_resolution_clock::now();
455 for(
int i = 0; i < 1000; ++i )
457 auto result = evaluator.
Evaluate(
"@{dateformat(" + std::to_string(i) +
")}" );
461 auto end = std::chrono::high_resolution_clock::now();
462 auto duration = std::chrono::duration_cast<std::chrono::milliseconds>(
end - start );
465 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)
BOOST_CHECK_MESSAGE(totalMismatches==0, std::to_string(totalMismatches)+" board(s) with strategy disagreements")
wxString result
Test unit parsing edge cases and error handling.
BOOST_CHECK_EQUAL(result, "25.4")
BOOST_AUTO_TEST_CASE(DateFormatting)