@@ -1024,6 +1024,67 @@ TEST_F(LLVMCodeBuilderTest, Not)
10241024 addOpTest (" nan" );
10251025}
10261026
1027+ TEST_F (LLVMCodeBuilderTest, Mod)
1028+ {
1029+ std::string expected;
1030+
1031+ auto addOpTest = [this , &expected](Value v1, Value v2) {
1032+ createBuilder (true );
1033+
1034+ m_builder->addConstValue (v1);
1035+ m_builder->addConstValue (v2);
1036+ m_builder->createMod ();
1037+ m_builder->addFunctionCall (" test_print_string" , Compiler::StaticType::Void, { Compiler::StaticType::String });
1038+
1039+ m_builder->addConstValue (v1);
1040+ m_builder->addFunctionCall (" test_const_number" , Compiler::StaticType::Number, { Compiler::StaticType::Number });
1041+ m_builder->addConstValue (v2);
1042+ m_builder->addFunctionCall (" test_const_number" , Compiler::StaticType::Number, { Compiler::StaticType::Number });
1043+ m_builder->createMod ();
1044+ m_builder->addFunctionCall (" test_print_string" , Compiler::StaticType::Void, { Compiler::StaticType::String });
1045+
1046+ std::string str = (v1 % v2).toString () + ' \n ' ;
1047+ std::string expected = str + str;
1048+
1049+ auto code = m_builder->finalize ();
1050+ auto ctx = code->createExecutionContext (&m_target);
1051+
1052+ testing::internal::CaptureStdout ();
1053+ code->run (ctx.get ());
1054+ const std::string quotes1 = v1.isString () ? " \" " : " " ;
1055+ const std::string quotes2 = v2.isString () ? " \" " : " " ;
1056+ ASSERT_THAT (testing::internal::GetCapturedStdout (), Eq (expected)) << quotes1 << v1.toString () << quotes1 << " " << quotes2 << v2.toString () << quotes2;
1057+ };
1058+
1059+ addOpTest (4 , 3 );
1060+ addOpTest (3 , 3 );
1061+ addOpTest (2 , 3 );
1062+ addOpTest (1 , 3 );
1063+ addOpTest (0 , 3 );
1064+ addOpTest (-1 , 3 );
1065+ addOpTest (-2 , 3 );
1066+ addOpTest (-3 , 3 );
1067+ addOpTest (-4 , 3 );
1068+ addOpTest (4.75 , 2 );
1069+ addOpTest (-4.75 , 2 );
1070+ addOpTest (-4.75 , -2 );
1071+ addOpTest (4.75 , -2 );
1072+ addOpTest (5 , 0 );
1073+ addOpTest (-5 , 0 );
1074+ addOpTest (-2.5 , " Infinity" );
1075+ addOpTest (-1.2 , " -Infinity" );
1076+ addOpTest (2.5 , " Infinity" );
1077+ addOpTest (1.2 , " -Infinity" );
1078+ addOpTest (" Infinity" , 2 );
1079+ addOpTest (" -Infinity" , 2 );
1080+ addOpTest (" Infinity" , -2 );
1081+ addOpTest (" -Infinity" , -2 );
1082+ addOpTest (3 , " NaN" );
1083+ addOpTest (-3 , " NaN" );
1084+ addOpTest (" NaN" , 5 );
1085+ addOpTest (" NaN" , -5 );
1086+ }
1087+
10271088TEST_F (LLVMCodeBuilderTest, Yield)
10281089{
10291090 auto build = [this ]() {
0 commit comments