@@ -200,6 +200,50 @@ TEST_F(LLVMCodeBuilderTest, RawValueCasting)
200200 ASSERT_EQ (testing::internal::GetCapturedStdout (), expected);
201201}
202202
203+ TEST_F (LLVMCodeBuilderTest, Add)
204+ {
205+ std::string expected;
206+
207+ auto addOpTest = [this , &expected](Value v1, Value v2, double expectedResult) {
208+ m_builder->addConstValue (v1);
209+ m_builder->addConstValue (v2);
210+ m_builder->createAdd ();
211+ m_builder->addFunctionCall (" test_print_string" , Compiler::StaticType::Void, { Compiler::StaticType::String });
212+
213+ m_builder->addConstValue (v1);
214+ m_builder->addFunctionCall (" test_const_number" , Compiler::StaticType::Number, { Compiler::StaticType::Number });
215+ m_builder->addConstValue (v2);
216+ m_builder->addFunctionCall (" test_const_number" , Compiler::StaticType::Number, { Compiler::StaticType::Number });
217+ m_builder->createAdd ();
218+ m_builder->addFunctionCall (" test_print_string" , Compiler::StaticType::Void, { Compiler::StaticType::String });
219+
220+ std::string str = Value (expectedResult).toString () + ' \n ' ;
221+ expected += str;
222+ expected += str;
223+ };
224+
225+ createBuilder (true );
226+
227+ addOpTest (50 , 25 , 75 );
228+ addOpTest (-500 , 25 , -475 );
229+ addOpTest (-500 , -25 , -525 );
230+ addOpTest (" 2.54" , " 6.28" , 8.82 );
231+ addOpTest (2.54 , " -6.28" , -3.74 );
232+ addOpTest (true , true , 2 );
233+ addOpTest (" Infinity" , " Infinity" , std::numeric_limits<double >::infinity ());
234+ addOpTest (" Infinity" , " -Infinity" , std::numeric_limits<double >::quiet_NaN ());
235+ addOpTest (" -Infinity" , " Infinity" , std::numeric_limits<double >::quiet_NaN ());
236+ addOpTest (" -Infinity" , " -Infinity" , -std::numeric_limits<double >::infinity ());
237+ addOpTest (1 , " NaN" , 1 );
238+
239+ auto code = m_builder->finalize ();
240+ auto ctx = code->createExecutionContext (&m_target);
241+
242+ testing::internal::CaptureStdout ();
243+ code->run (ctx.get ());
244+ ASSERT_EQ (testing::internal::GetCapturedStdout (), expected);
245+ }
246+
203247TEST_F (LLVMCodeBuilderTest, Yield)
204248{
205249 auto build = [this ]() {
0 commit comments