Changeset d7f0b3f7 in mainline


Ignore:
Timestamp:
2018-07-05T21:41:18Z (6 years ago)
Author:
Dzejrou <dzejrou@…>
Branches:
lfn, master, serial, ticket/834-toolchain-update, topic/msim-upgrade, topic/simplify-dev-export
Children:
2d302d6
Parents:
27473fb8
git-author:
Jaroslav Jindrak <dzejrou@…> (2017-10-31 22:31:05)
git-committer:
Dzejrou <dzejrou@…> (2018-07-05 21:41:18)
Message:

cpp: implemented some basic std::string::insert tests

Location:
uspace/lib/cpp
Files:
2 edited

Legend:

Unmodified
Added
Removed
  • uspace/lib/cpp/include/internal/test/tests.hpp

    r27473fb8 rd7f0b3f7  
    6868            void test_construction_and_assignment();
    6969            void test_append();
     70            void test_insert();
    7071    };
    7172}
  • uspace/lib/cpp/src/internal/test/string.cpp

    r27473fb8 rd7f0b3f7  
    3838        test_construction_and_assignment();
    3939        test_append();
     40        test_insert();
    4041
    4142        return true;
     
    154155        );
    155156    }
     157
     158    void string_test::test_insert()
     159    {
     160        std::string check{"hello, world"};
     161
     162        std::string str1{", world"};
     163        str1.insert(0, "hello");
     164        test_eq(
     165            "insert at the beggining",
     166            str1.begin(), str1.end(),
     167            check.begin(), check.end()
     168        );
     169
     170        std::string str2{"hello,world"};
     171        str2.insert(str2.begin() + 6, ' ');
     172        test_eq(
     173            "insert char in the middle",
     174            str2.begin(), str2.end(),
     175            check.begin(), check.end()
     176        );
     177
     178        std::string str3{"heo, world"};
     179        str3.insert(str3.begin() + 2, 2ul, 'l');
     180        test_eq(
     181            "insert n chars",
     182            str3.begin(), str3.end(),
     183            check.begin(), check.end()
     184        );
     185
     186        std::string str4{"h, world"};
     187        std::string insertee{"ello"};
     188        str4.insert(str4.begin() + 1, insertee.begin(),
     189                    insertee.end() - 1);
     190        test_eq(
     191            "insert iterator range",
     192            str4.begin(), str4.end(),
     193            check.begin(), check.end()
     194        );
     195        /* std::printf("|%s|\n", str4.c_str()); */
     196    }
    156197}
Note: See TracChangeset for help on using the changeset viewer.