@@ -340,6 +340,65 @@ TEST_F(LLVMCodeBuilderTest, Multiply)
340340 ASSERT_EQ (testing::internal::GetCapturedStdout (), expected);
341341}
342342
343+ TEST_F (LLVMCodeBuilderTest, Divide)
344+ {
345+ std::string expected;
346+
347+ auto addOpTest = [this , &expected](Value v1, Value v2, double expectedResult) {
348+ m_builder->addConstValue (v1);
349+ m_builder->addConstValue (v2);
350+ m_builder->createDiv ();
351+ m_builder->addFunctionCall (" test_print_string" , Compiler::StaticType::Void, { Compiler::StaticType::String });
352+
353+ m_builder->addConstValue (v1);
354+ m_builder->addFunctionCall (" test_const_number" , Compiler::StaticType::Number, { Compiler::StaticType::Number });
355+ m_builder->addConstValue (v2);
356+ m_builder->addFunctionCall (" test_const_number" , Compiler::StaticType::Number, { Compiler::StaticType::Number });
357+ m_builder->createDiv ();
358+ m_builder->addFunctionCall (" test_print_string" , Compiler::StaticType::Void, { Compiler::StaticType::String });
359+
360+ std::string str = Value (expectedResult).toString () + ' \n ' ;
361+ expected += str;
362+ expected += str;
363+ };
364+
365+ createBuilder (true );
366+
367+ addOpTest (50 , 2 , 25 );
368+ addOpTest (-500 , 25 , -20 );
369+ addOpTest (" -500" , -25 , 20 );
370+ addOpTest (" 3.5" , " 2.5" , 1.4 );
371+ addOpTest (true , true , 1 );
372+ addOpTest (" Infinity" , " Infinity" , std::numeric_limits<double >::quiet_NaN ());
373+ addOpTest (" Infinity" , 0 , std::numeric_limits<double >::infinity ());
374+ addOpTest (" Infinity" , 2 , std::numeric_limits<double >::infinity ());
375+ addOpTest (" Infinity" , -2 , -std::numeric_limits<double >::infinity ());
376+ addOpTest (" Infinity" , " -Infinity" , std::numeric_limits<double >::quiet_NaN ());
377+ addOpTest (" -Infinity" , " Infinity" , std::numeric_limits<double >::quiet_NaN ());
378+ addOpTest (" -Infinity" , 0 , -std::numeric_limits<double >::infinity ());
379+ addOpTest (" -Infinity" , 2 , -std::numeric_limits<double >::infinity ());
380+ addOpTest (" -Infinity" , -2 , std::numeric_limits<double >::infinity ());
381+ addOpTest (" -Infinity" , " -Infinity" , std::numeric_limits<double >::quiet_NaN ());
382+ addOpTest (0 , " Infinity" , 0 );
383+ addOpTest (2 , " Infinity" , 0 );
384+ addOpTest (-2 , " Infinity" , 0 );
385+ addOpTest (0 , " -Infinity" , 0 );
386+ addOpTest (2 , " -Infinity" , 0 );
387+ addOpTest (-2 , " -Infinity" , 0 );
388+ addOpTest (1 , " NaN" , std::numeric_limits<double >::infinity ());
389+ addOpTest (" NaN" , 1 , 0 );
390+ addOpTest (5 , 0 , std::numeric_limits<double >::infinity ());
391+ addOpTest (-5 , 0 , -std::numeric_limits<double >::infinity ());
392+ addOpTest (0 , 0 , std::numeric_limits<double >::quiet_NaN ());
393+
394+ auto code = m_builder->finalize ();
395+ auto ctx = code->createExecutionContext (&m_target);
396+
397+ testing::internal::CaptureStdout ();
398+ code->run (ctx.get ());
399+ ASSERT_EQ (testing::internal::GetCapturedStdout (), expected);
400+ }
401+
343402TEST_F (LLVMCodeBuilderTest, Yield)
344403{
345404 auto build = [this ]() {
0 commit comments