@@ -36,6 +36,8 @@ class LLVMCodeBuilderTest : public testing::Test
3636 CmpEQ,
3737 CmpGT,
3838 CmpLT,
39+ StrCmpEQCS,
40+ StrCmpEQCI,
3941 And,
4042 Or,
4143 Not,
@@ -127,6 +129,12 @@ class LLVMCodeBuilderTest : public testing::Test
127129 case OpType::CmpLT:
128130 return m_builder->createCmpLT (arg1, arg2);
129131
132+ case OpType::StrCmpEQCS:
133+ return m_builder->createStrCmpEQ (arg1, arg2, true );
134+
135+ case OpType::StrCmpEQCI:
136+ return m_builder->createStrCmpEQ (arg1, arg2, false );
137+
130138 case OpType::And:
131139 return m_builder->createAnd (arg1, arg2);
132140
@@ -235,6 +243,16 @@ class LLVMCodeBuilderTest : public testing::Test
235243 case OpType::CmpLT:
236244 return v1 < v2;
237245
246+ case OpType::StrCmpEQCS:
247+ return v1.toString () == v2.toString ();
248+
249+ case OpType::StrCmpEQCI: {
250+ // TODO: Use a custom function for string comparison
251+ std::string str1 = v1.toString ();
252+ std::string str2 = v2.toString ();
253+ return strcasecmp (str1.c_str (), str2.c_str ()) == 0 ;
254+ }
255+
238256 case OpType::And:
239257 return v1.toBool () && v2.toBool ();
240258
@@ -1089,6 +1107,152 @@ TEST_F(LLVMCodeBuilderTest, GreaterAndLowerThanComparison)
10891107 }
10901108}
10911109
1110+ TEST_F (LLVMCodeBuilderTest, StringEqualComparison)
1111+ {
1112+ std::vector<OpType> types = { OpType::StrCmpEQCS, OpType::StrCmpEQCI };
1113+
1114+ for (OpType type : types) {
1115+ runOpTest (type, 10 , 10 );
1116+ runOpTest (type, 10 , 8 );
1117+ runOpTest (type, 8 , 10 );
1118+
1119+ runOpTest (type, -4.25 , -4.25 );
1120+ runOpTest (type, -4.25 , 5.312 );
1121+ runOpTest (type, 5.312 , -4.25 );
1122+
1123+ runOpTest (type, true , true );
1124+ runOpTest (type, true , false );
1125+ runOpTest (type, false , true );
1126+
1127+ runOpTest (type, 1 , true );
1128+ runOpTest (type, 1 , false );
1129+
1130+ runOpTest (type, " abC def" , " abC def" );
1131+ runOpTest (type, " abC def" , " abc dEf" );
1132+ runOpTest (type, " abC def" , " ghi Jkl" );
1133+ runOpTest (type, " abC def" , " hello world" );
1134+
1135+ runOpTest (type, " " , " " );
1136+ runOpTest (type, " " , " 0" );
1137+ runOpTest (type, " " , 0 );
1138+ runOpTest (type, 0 , " " );
1139+ runOpTest (type, " " , " 0" );
1140+ runOpTest (type, " " , 0 );
1141+ runOpTest (type, 0 , " " );
1142+ runOpTest (type, " 0" , 0 );
1143+ runOpTest (type, 0 , " 0" );
1144+
1145+ runOpTest (type, 5.25 , " 5.25" );
1146+ runOpTest (type, " 5.25" , 5.25 );
1147+ runOpTest (type, 5.25 , " 5.25" );
1148+ runOpTest (type, " 5.25" , 5.25 );
1149+ runOpTest (type, 5.25 , " 5.25 " );
1150+ runOpTest (type, " 5.25 " , 5.25 );
1151+ runOpTest (type, 5.25 , " 5.25 " );
1152+ runOpTest (type, " 5.25 " , 5.25 );
1153+ runOpTest (type, 5.25 , " 5.26" );
1154+ runOpTest (type, " 5.26" , 5.25 );
1155+ runOpTest (type, " 5.25" , " 5.26" );
1156+ runOpTest (type, 5 , " 5 " );
1157+ runOpTest (type, " 5 " , 5 );
1158+ runOpTest (type, 0 , " 1" );
1159+ runOpTest (type, " 1" , 0 );
1160+ runOpTest (type, 0 , " test" );
1161+ runOpTest (type, " test" , 0 );
1162+
1163+ static const double inf = std::numeric_limits<double >::infinity ();
1164+ static const double nan = std::numeric_limits<double >::quiet_NaN ();
1165+
1166+ runOpTest (type, inf, inf);
1167+ runOpTest (type, -inf, -inf);
1168+ runOpTest (type, nan, nan);
1169+ runOpTest (type, inf, -inf);
1170+ runOpTest (type, -inf, inf);
1171+ runOpTest (type, inf, nan);
1172+ runOpTest (type, nan, inf);
1173+ runOpTest (type, -inf, nan);
1174+ runOpTest (type, nan, -inf);
1175+
1176+ runOpTest (type, 5 , inf);
1177+ runOpTest (type, 5 , -inf);
1178+ runOpTest (type, 5 , nan);
1179+ runOpTest (type, 0 , nan);
1180+
1181+ runOpTest (type, true , " true" );
1182+ runOpTest (type, " true" , true );
1183+ runOpTest (type, false , " false" );
1184+ runOpTest (type, " false" , false );
1185+ runOpTest (type, false , " true" );
1186+ runOpTest (type, " true" , false );
1187+ runOpTest (type, true , " false" );
1188+ runOpTest (type, " false" , true );
1189+ runOpTest (type, true , " TRUE" );
1190+ runOpTest (type, " TRUE" , true );
1191+ runOpTest (type, false , " FALSE" );
1192+ runOpTest (type, " FALSE" , false );
1193+
1194+ runOpTest (type, true , " 00001" );
1195+ runOpTest (type, " 00001" , true );
1196+ runOpTest (type, true , " 00000" );
1197+ runOpTest (type, " 00000" , true );
1198+ runOpTest (type, false , " 00000" );
1199+ runOpTest (type, " 00000" , false );
1200+
1201+ runOpTest (type, " true" , 1 );
1202+ runOpTest (type, 1 , " true" );
1203+ runOpTest (type, " true" , 0 );
1204+ runOpTest (type, 0 , " true" );
1205+ runOpTest (type, " false" , 0 );
1206+ runOpTest (type, 0 , " false" );
1207+ runOpTest (type, " false" , 1 );
1208+ runOpTest (type, 1 , " false" );
1209+
1210+ runOpTest (type, " true" , " TRUE" );
1211+ runOpTest (type, " true" , " FALSE" );
1212+ runOpTest (type, " false" , " FALSE" );
1213+ runOpTest (type, " false" , " TRUE" );
1214+
1215+ runOpTest (type, true , inf);
1216+ runOpTest (type, true , -inf);
1217+ runOpTest (type, true , nan);
1218+ runOpTest (type, false , inf);
1219+ runOpTest (type, false , -inf);
1220+ runOpTest (type, false , nan);
1221+
1222+ runOpTest (type, " Infinity" , inf);
1223+ runOpTest (type, " Infinity" , -inf);
1224+ runOpTest (type, " Infinity" , nan);
1225+ runOpTest (type, " infinity" , inf);
1226+ runOpTest (type, " infinity" , -inf);
1227+ runOpTest (type, " infinity" , nan);
1228+ runOpTest (type, " -Infinity" , inf);
1229+ runOpTest (type, " -Infinity" , -inf);
1230+ runOpTest (type, " -Infinity" , nan);
1231+ runOpTest (type, " -infinity" , inf);
1232+ runOpTest (type, " -infinity" , -inf);
1233+ runOpTest (type, " -infinity" , nan);
1234+ runOpTest (type, " NaN" , inf);
1235+ runOpTest (type, " NaN" , -inf);
1236+ runOpTest (type, " NaN" , nan);
1237+ runOpTest (type, " nan" , inf);
1238+ runOpTest (type, " nan" , -inf);
1239+ runOpTest (type, " nan" , nan);
1240+
1241+ runOpTest (type, inf, " abc" );
1242+ runOpTest (type, inf, " " );
1243+ runOpTest (type, inf, " " );
1244+ runOpTest (type, inf, " 0" );
1245+ runOpTest (type, -inf, " abc" );
1246+ runOpTest (type, -inf, " " );
1247+ runOpTest (type, -inf, " " );
1248+ runOpTest (type, -inf, " 0" );
1249+ runOpTest (type, nan, " abc" );
1250+ runOpTest (type, nan, " " );
1251+ runOpTest (type, nan, " " );
1252+ runOpTest (type, nan, " 0" );
1253+ }
1254+ }
1255+
10921256TEST_F (LLVMCodeBuilderTest, AndOr)
10931257{
10941258 std::vector<OpType> opTypes = { OpType::And, OpType::Or };
0 commit comments