@@ -1367,6 +1367,128 @@ TYPED_TEST(StringBaseTest, ReplaceFunctions)
13671367 }
13681368}
13691369
1370+ /* insert functions */
1371+ TYPED_TEST (StringBaseTest, InsertFunctions)
1372+ {
1373+ using StringType = TypeParam; // gtest specific
1374+ using StorageType = typename StringType::storage_type;
1375+ using CharType = typename StorageType::char_type;
1376+ using Traits = typename StorageType::traits_type;
1377+ const TestData<CharType> data{};
1378+
1379+ using RefType = std::basic_string<CharType>;
1380+
1381+ // this_type& insert(size_type index, size_type count, char_type ch)
1382+ {
1383+ StringType s1 (data.hello_world );
1384+ RefType s2 (data.hello_world );
1385+
1386+ s1.insert (3 , 13 , data.hello_world [0 ]);
1387+ s2.insert (3 , 13 , data.hello_world [0 ]);
1388+ ASSERT_EQ (s1.size (), s2.size ());
1389+ ASSERT_TRUE (Traits::compare (s1.data (), s2.data (), s1.size ()) == 0 );
1390+ }
1391+ // this_type& insert(size_type index, const char_type* s)
1392+ {
1393+ StringType s1 (data.hello_world );
1394+ RefType s2 (data.hello_world );
1395+
1396+ s1.insert (0 , data.blablabla );
1397+ s2.insert (0 , data.blablabla );
1398+ ASSERT_EQ (s1.size (), s2.size ());
1399+ ASSERT_TRUE (Traits::compare (s1.data (), s2.data (), s1.size ()) == 0 );
1400+ }
1401+ // this_type& insert(size_type index, const char_type* s, size_type count)
1402+ {
1403+ StringType s1 (data.hello_world );
1404+ RefType s2 (data.hello_world );
1405+
1406+ s1.insert (s1.size () - 2 , data.blablabla , data.blablabla_len - 1 );
1407+ s2.insert (s2.size () - 2 , data.blablabla , data.blablabla_len - 1 );
1408+ ASSERT_EQ (s1.size (), s2.size ());
1409+ ASSERT_TRUE (Traits::compare (s1.data (), s2.data (), s1.size ()) == 0 );
1410+ }
1411+ // this_type& insert(size_type index, const StringClass& s)
1412+ {
1413+ StringType s1 (data.hello_world );
1414+ RefType s2 (data.hello_world );
1415+ // we use basic_string here
1416+ const RefType ins (data.blablabla );
1417+
1418+ s1.insert (1 , ins);
1419+ s2.insert (1 , ins);
1420+ ASSERT_EQ (s1.size (), s2.size ());
1421+ ASSERT_TRUE (Traits::compare (s1.data (), s2.data (), s1.size ()) == 0 );
1422+ }
1423+ // this_type& insert(size_type, const StringClass&, size_type, size_type count)
1424+ {
1425+ StringType s1 (data.hello_world );
1426+ RefType s2 (data.hello_world );
1427+ // we use basic_string here
1428+ const RefType ins (data.blablabla );
1429+
1430+ s1.insert (1 , ins, 3 , StringType::npos);
1431+ s2.insert (1 , ins, 3 , RefType::npos);
1432+ ASSERT_EQ (s1.size (), s2.size ());
1433+ ASSERT_TRUE (Traits::compare (s1.data (), s2.data (), s1.size ()) == 0 );
1434+ }
1435+
1436+ // iterator insert(const_iterator pos, char_type ch)
1437+ {
1438+ StringType s1 (data.hello_world );
1439+ RefType s2 (data.hello_world );
1440+
1441+ s1.insert (s1.begin () + 5 , data.hello_world [0 ]);
1442+ s2.insert (s2.begin () + 5 , data.hello_world [0 ]);
1443+ ASSERT_EQ (s1.size (), s2.size ());
1444+ ASSERT_TRUE (Traits::compare (s1.data (), s2.data (), s1.size ()) == 0 );
1445+ }
1446+ // iterator insert(const_iterator pos, size_type count, char_type ch)
1447+ {
1448+ StringType s1 (data.hello_world );
1449+ RefType s2 (data.hello_world );
1450+
1451+ s1.insert (s1.begin (), 9 , data.hello_world [0 ]);
1452+ s2.insert (s2.begin (), 9 , data.hello_world [0 ]);
1453+ ASSERT_EQ (s1.size (), s2.size ());
1454+ ASSERT_TRUE (Traits::compare (s1.data (), s2.data (), s1.size ()) == 0 );
1455+ }
1456+ // iterator insert(const_iterator pos, InputIt first, InputIt last)
1457+ {
1458+ StringType s1 (data.hello_world );
1459+ RefType s2 (data.hello_world );
1460+ RefType ins (data.blablabla );
1461+
1462+ // "normal" iterator
1463+ s1.insert (s1.begin () + 2 , ins.begin (), ins.end ());
1464+ s2.insert (s2.begin () + 2 , ins.begin (), ins.end ());
1465+ ASSERT_EQ (s1.size (), s2.size ());
1466+ ASSERT_TRUE (Traits::compare (s1.data (), s2.data (), s1.size ()) == 0 );
1467+
1468+ // const_iterator
1469+ s1.insert (s1.begin () + 2 , ins.cbegin (), ins.cbegin () + 6 );
1470+ s2.insert (s2.begin () + 2 , ins.cbegin (), ins.cbegin () + 6 );
1471+ ASSERT_EQ (s1.size (), s2.size ());
1472+ ASSERT_TRUE (Traits::compare (s1.data (), s2.data (), s1.size ()) == 0 );
1473+
1474+ // reverse_iterator
1475+ s1.insert (s1.begin () + 2 , ins.rbegin (), ins.rend ());
1476+ s2.insert (s2.begin () + 2 , ins.rbegin (), ins.rend ());
1477+ ASSERT_EQ (s1.size (), s2.size ());
1478+ ASSERT_TRUE (Traits::compare (s1.data (), s2.data (), s1.size ()) == 0 );
1479+ }
1480+ // iterator insert(const_iterator pos, std::initializer_list<char_type> ilist)
1481+ {
1482+ StringType s1 (data.hello_world );
1483+ RefType s2 (data.hello_world );
1484+
1485+ s1.insert (s1.begin (), data.initializerList2 ());
1486+ s2.insert (s2.begin (), data.initializerList2 ());
1487+ ASSERT_EQ (s1.size (), s2.size ());
1488+ ASSERT_TRUE (Traits::compare (s1.data (), s2.data (), s1.size ()) == 0 );
1489+ }
1490+ }
1491+
13701492/* operator<< */
13711493TYPED_TEST (StringBaseTest, OutputStream)
13721494{
0 commit comments