@@ -244,6 +244,50 @@ TEST_F(LLVMCodeBuilderTest, Add)
244244 ASSERT_EQ (testing::internal::GetCapturedStdout (), expected);
245245}
246246
247+ TEST_F (LLVMCodeBuilderTest, Subtract)
248+ {
249+ std::string expected;
250+
251+ auto addOpTest = [this , &expected](Value v1, Value v2, double expectedResult) {
252+ m_builder->addConstValue (v1);
253+ m_builder->addConstValue (v2);
254+ m_builder->createSub ();
255+ m_builder->addFunctionCall (" test_print_string" , Compiler::StaticType::Void, { Compiler::StaticType::String });
256+
257+ m_builder->addConstValue (v1);
258+ m_builder->addFunctionCall (" test_const_number" , Compiler::StaticType::Number, { Compiler::StaticType::Number });
259+ m_builder->addConstValue (v2);
260+ m_builder->addFunctionCall (" test_const_number" , Compiler::StaticType::Number, { Compiler::StaticType::Number });
261+ m_builder->createSub ();
262+ m_builder->addFunctionCall (" test_print_string" , Compiler::StaticType::Void, { Compiler::StaticType::String });
263+
264+ std::string str = Value (expectedResult).toString () + ' \n ' ;
265+ expected += str;
266+ expected += str;
267+ };
268+
269+ createBuilder (true );
270+
271+ addOpTest (50 , 25 , 25 );
272+ addOpTest (-500 , 25 , -525 );
273+ addOpTest (-500 , -25 , -475 );
274+ addOpTest (" 2.54" , " 6.28" , -3.74 );
275+ addOpTest (2.54 , " -6.28" , 8.82 );
276+ addOpTest (true , true , 0 );
277+ addOpTest (" Infinity" , " Infinity" , std::numeric_limits<double >::quiet_NaN ());
278+ addOpTest (" Infinity" , " -Infinity" , std::numeric_limits<double >::infinity ());
279+ addOpTest (" -Infinity" , " Infinity" , -std::numeric_limits<double >::infinity ());
280+ addOpTest (" -Infinity" , " -Infinity" , std::numeric_limits<double >::quiet_NaN ());
281+ addOpTest (1 , " NaN" , 1 );
282+
283+ auto code = m_builder->finalize ();
284+ auto ctx = code->createExecutionContext (&m_target);
285+
286+ testing::internal::CaptureStdout ();
287+ code->run (ctx.get ());
288+ ASSERT_EQ (testing::internal::GetCapturedStdout (), expected);
289+ }
290+
247291TEST_F (LLVMCodeBuilderTest, Yield)
248292{
249293 auto build = [this ]() {
0 commit comments