@@ -1133,6 +1133,51 @@ TEST_F(LLVMCodeBuilderTest, Round)
11331133 addOpTest (nan, 0 );
11341134}
11351135
1136+ TEST_F (LLVMCodeBuilderTest, Abs)
1137+ {
1138+ std::string expected;
1139+
1140+ auto addOpTest = [this , &expected](Value v1, double expectedResult) {
1141+ createBuilder (true );
1142+
1143+ m_builder->addConstValue (v1);
1144+ m_builder->createAbs ();
1145+ m_builder->addFunctionCall (" test_print_number" , Compiler::StaticType::Void, { Compiler::StaticType::Number });
1146+
1147+ m_builder->addConstValue (v1);
1148+ m_builder->addFunctionCall (" test_const_number" , Compiler::StaticType::Number, { Compiler::StaticType::Number });
1149+ m_builder->createAbs ();
1150+ m_builder->addFunctionCall (" test_print_number" , Compiler::StaticType::Void, { Compiler::StaticType::Number });
1151+
1152+ std::stringstream stream;
1153+ stream << expectedResult;
1154+ std::string str = stream.str () + ' \n ' ;
1155+ std::string expected = str + str;
1156+
1157+ auto code = m_builder->finalize ();
1158+ auto ctx = code->createExecutionContext (&m_target);
1159+
1160+ testing::internal::CaptureStdout ();
1161+ code->run (ctx.get ());
1162+ const std::string quotes1 = v1.isString () ? " \" " : " " ;
1163+ ASSERT_THAT (testing::internal::GetCapturedStdout (), Eq (expected)) << quotes1 << v1.toString () << quotes1;
1164+ };
1165+
1166+ static const double inf = std::numeric_limits<double >::infinity ();
1167+ static const double nan = std::numeric_limits<double >::quiet_NaN ();
1168+
1169+ addOpTest (4.0 , 4.0 );
1170+ addOpTest (3.2 , 3.2 );
1171+ addOpTest (-2.0 , 2.0 );
1172+ addOpTest (-2.5 , 2.5 );
1173+ addOpTest (-2.6 , 2.6 );
1174+ addOpTest (0.0 , 0.0 );
1175+ addOpTest (-0.0 , 0.0 );
1176+ addOpTest (inf, inf);
1177+ addOpTest (-inf, inf);
1178+ addOpTest (nan, 0 );
1179+ }
1180+
11361181TEST_F (LLVMCodeBuilderTest, Yield)
11371182{
11381183 auto build = [this ]() {
0 commit comments