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