-
Notifications
You must be signed in to change notification settings - Fork 4
Expand file tree
/
Copy pathStringView.test.cpp
More file actions
48 lines (38 loc) · 1.21 KB
/
StringView.test.cpp
File metadata and controls
48 lines (38 loc) · 1.21 KB
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
#include "StringView.h"
#include "viewCString.h"
#include "viewLiteral.h"
#include <string_view>
#include <gtest/gtest.h>
using namespace string17;
TEST(StringView, fromLiteral) {
constexpr auto x = viewLiteral("Hello");
static_assert(x[0] == 'H');
static_assert(x.size() == 5u);
static_assert(!x.empty());
EXPECT_EQ(x[0], 'H');
// EXPECT_EQ(x.size(), 5); // MSVC seems to have a bug here
EXPECT_FALSE(x.empty());
auto y = viewLiteral("World");
EXPECT_EQ(y[0], 'W');
EXPECT_EQ(y.size(), 5u);
EXPECT_FALSE(y.empty());
static auto z = x;
EXPECT_EQ(z[0], 'H');
// EXPECT_EQ(z.size(), 5u); // MSVC seems to have a bug here
EXPECT_FALSE(z.empty());
}
TEST(StringView, fromCString) {
static constexpr auto* cstr = "Hello";
constexpr auto x = viewCString(cstr);
static_assert(x[0] == 'H');
static_assert(x.size() == 5u);
static_assert(!x.empty());
EXPECT_EQ(x[0], 'H');
// EXPECT_EQ(x.size(), 5u); // MSVC seems to have a bug here
EXPECT_FALSE(x.empty());
auto* ystr = "World";
auto y = viewCString(ystr);
EXPECT_EQ(y[0], 'W');
EXPECT_EQ(y.size(), 5u);
EXPECT_FALSE(y.empty());
}