75 lines
2.1 KiB
C++
75 lines
2.1 KiB
C++
|
#include "KylinString.h"
|
|||
|
#include <boost/test/unit_test.hpp>
|
|||
|
|
|||
|
using namespace Kylin;
|
|||
|
|
|||
|
class StringTest {
|
|||
|
public:
|
|||
|
std::string utf8String = "我爱你";
|
|||
|
String str{"Hello World!"}; // length: 12
|
|||
|
String spaceStr{" Hello World! "};
|
|||
|
const size_t length = 12;
|
|||
|
};
|
|||
|
|
|||
|
BOOST_AUTO_TEST_SUITE(StringTestCase)
|
|||
|
BOOST_FIXTURE_TEST_CASE(Length, StringTest) {
|
|||
|
BOOST_CHECK_EQUAL(str.length(), length);
|
|||
|
}
|
|||
|
|
|||
|
BOOST_FIXTURE_TEST_CASE(Equal, StringTest) {
|
|||
|
BOOST_CHECK_EQUAL(str, "Hello World!");
|
|||
|
}
|
|||
|
|
|||
|
BOOST_FIXTURE_TEST_CASE(MoveConstructor, StringTest) {
|
|||
|
String str1(std::move(str));
|
|||
|
BOOST_CHECK_EQUAL(str.length(), 0);
|
|||
|
BOOST_CHECK_EQUAL(str1.length(), length);
|
|||
|
BOOST_CHECK_EQUAL(str1, "Hello World!");
|
|||
|
}
|
|||
|
|
|||
|
BOOST_FIXTURE_TEST_CASE(Add, StringTest) {
|
|||
|
BOOST_CHECK_EQUAL(str + "World", "Hello World!World");
|
|||
|
}
|
|||
|
|
|||
|
BOOST_FIXTURE_TEST_CASE(StartWith, StringTest) {
|
|||
|
BOOST_CHECK_EQUAL(str.startWith("Hell"), true);
|
|||
|
BOOST_CHECK_EQUAL(str.startWith("rld"), false);
|
|||
|
}
|
|||
|
|
|||
|
BOOST_FIXTURE_TEST_CASE(EndOf, StringTest) {
|
|||
|
BOOST_CHECK_EQUAL(str.endOf("rld!"), true);
|
|||
|
BOOST_CHECK_EQUAL(str.endOf("Hell"), false);
|
|||
|
}
|
|||
|
|
|||
|
BOOST_FIXTURE_TEST_CASE(Insert, StringTest) {
|
|||
|
BOOST_CHECK_EQUAL(str.insert(5, " kylin"), "Hello kylin World!");
|
|||
|
}
|
|||
|
|
|||
|
BOOST_FIXTURE_TEST_CASE(Trim, StringTest) {
|
|||
|
BOOST_CHECK_EQUAL(spaceStr.trim(), str);
|
|||
|
}
|
|||
|
|
|||
|
BOOST_FIXTURE_TEST_CASE(IndexOf, StringTest) {
|
|||
|
BOOST_CHECK_EQUAL(str.indexOf("llo"), 2);
|
|||
|
}
|
|||
|
|
|||
|
BOOST_FIXTURE_TEST_CASE(Remove, StringTest) {
|
|||
|
BOOST_CHECK_EQUAL(str.remove("llo"), "He World!");
|
|||
|
}
|
|||
|
|
|||
|
BOOST_FIXTURE_TEST_CASE(Replace, StringTest) {
|
|||
|
BOOST_CHECK_EQUAL(str.replace("llo", "kylin") == "Hekylin World!", true);
|
|||
|
}
|
|||
|
|
|||
|
BOOST_FIXTURE_TEST_CASE(Substr, StringTest) {
|
|||
|
BOOST_CHECK_EQUAL(str.substr(3, 4), "lo W");
|
|||
|
}
|
|||
|
|
|||
|
BOOST_FIXTURE_TEST_CASE(sunday, StringTest) {
|
|||
|
BOOST_CHECK_EQUAL(Kylin::String::sunday("Hello World", "Hello World"), 0);
|
|||
|
BOOST_CHECK_EQUAL(Kylin::String::sunday("Hello World", "o W"), 4);
|
|||
|
BOOST_CHECK_EQUAL(Kylin::String::sunday("Hello World", "o W1"), -1);
|
|||
|
}
|
|||
|
|
|||
|
BOOST_AUTO_TEST_SUITE_END()
|