#include <folly/portability/GTest.h>
#define FS(x) ::folly::makeFixedString(x)
-using namespace folly::StringLiterals;
+using namespace folly::string_literals;
TEST(FixedStringExamples, Examples) {
// Example from the docs:
TEST(FixedStringCtorTest, FromLiterals) {
constexpr folly::FixedString<42> s{"hello world"};
+ static_assert(s[0] == 'h', "");
constexpr folly::FixedString<11> s2{"hello world"};
static_assert(s2[0] == 'h', "");
static_assert(s2[10] == 'd', "");
}
TEST(FixedStringCtorTest, FromUDL) {
- using namespace folly::Literals;
+ using namespace folly::literals;
#if defined(__GNUC__)
constexpr auto x = "hello"_fs;
static_assert(
static_assert(tmp3 == "aaa", "");
}
+TEST(FixedStringCompareTest, CompareStdString) {
+ constexpr folly::FixedString<10> tmp1{"aaaaaaaaaa"};
+ std::string const tmp2{"aaaaaaaaaba"};
+ EXPECT_EQ(-1, tmp1.compare(tmp2));
+ // These are specifically testing the operators, and so we can't rely
+ // on whever the implementation details of EXPECT_<OP> might be.
+ EXPECT_FALSE(tmp1 == tmp2);
+ EXPECT_FALSE(tmp2 == tmp1);
+ EXPECT_TRUE(tmp1 != tmp2);
+ EXPECT_TRUE(tmp2 != tmp1);
+ EXPECT_TRUE(tmp1 < tmp2);
+ EXPECT_FALSE(tmp2 < tmp1);
+ EXPECT_TRUE(tmp1 <= tmp2);
+ EXPECT_FALSE(tmp2 <= tmp1);
+ EXPECT_FALSE(tmp1 > tmp2);
+ EXPECT_TRUE(tmp2 > tmp1);
+ EXPECT_FALSE(tmp1 >= tmp2);
+ EXPECT_TRUE(tmp2 >= tmp1);
+}
+
#if FOLLY_USE_CPP14_CONSTEXPR
constexpr folly::FixedString<20> constexpr_append_string_test() {
folly::FixedString<20> a{"hello"}, b{"X world!"};
std::size_t count = 0u;
auto i = s.rbegin();
for( ; i != s.rend(); ++i, --i, i++, i--, i+=1, i-=1, i+=1 ) {
- if (' ' == *i)
+ if (' ' == *i) {
++count;
+ }
}
return count;
}