Flutter Engine
The Flutter Engine
Functions
SkStringViewTest.cpp File Reference
#include "src/base/SkStringView.h"
#include "tests/Test.h"
#include <string>
#include <string_view>

Go to the source code of this file.

Functions

 DEF_TEST (SkStringViewStartsAndEnds, r)
 
 DEF_TEST (SkStringViewContains, r)
 

Function Documentation

◆ DEF_TEST() [1/2]

DEF_TEST ( SkStringViewContains  ,
 
)

Definition at line 53 of file SkStringViewTest.cpp.

53 {
54 REPORTER_ASSERT(r, skstd::contains("ttttest1tttest2tttest3", "test"));
55 REPORTER_ASSERT(r, skstd::contains("ttttest1tttest2tttest3", "test3"));
56 REPORTER_ASSERT(r, !skstd::contains("ttttest1tttest2tttest3", "test4"));
58 REPORTER_ASSERT(r, !skstd::contains("", "a"));
59 REPORTER_ASSERT(r, skstd::contains("abcabcd", "abcd"));
60 REPORTER_ASSERT(r, skstd::contains("abc", ""));
61 REPORTER_ASSERT(r, skstd::contains("abc", "a"));
62 REPORTER_ASSERT(r, skstd::contains("abc", "b"));
63 REPORTER_ASSERT(r, skstd::contains("abc", "c"));
64 REPORTER_ASSERT(r, skstd::contains("abc", "ab"));
65 REPORTER_ASSERT(r, skstd::contains("abc", "bc"));
66 REPORTER_ASSERT(r, !skstd::contains("abc", "ac"));
67 REPORTER_ASSERT(r, !skstd::contains("abc", "cb"));
68 REPORTER_ASSERT(r, !skstd::contains("abc", "abcd"));
69}
#define REPORTER_ASSERT(r, cond,...)
Definition: Test.h:286
constexpr bool contains(std::string_view str, std::string_view needle)
Definition: SkStringView.h:41

◆ DEF_TEST() [2/2]

DEF_TEST ( SkStringViewStartsAndEnds  ,
 
)

Definition at line 14 of file SkStringViewTest.cpp.

14 {
15 std::string_view empty("");
16 REPORTER_ASSERT(r, empty.empty());
23
24 std::string_view xyz("xyz");
25 REPORTER_ASSERT(r, !xyz.empty());
26 REPORTER_ASSERT(r, xyz.front() == 'x');
27 REPORTER_ASSERT(r, xyz.back() == 'z');
28 REPORTER_ASSERT(r, xyz.length() == 3);
29
33 REPORTER_ASSERT(r, !skstd::ends_with(xyz, 'y'));
34
39 REPORTER_ASSERT(r, !skstd::starts_with(xyz, "xa"));
40 REPORTER_ASSERT(r, !skstd::ends_with(xyz, "az"));
42 REPORTER_ASSERT(r, skstd::ends_with(xyz, "yz"));
43 REPORTER_ASSERT(r, skstd::starts_with(xyz, "xyz"));
44 REPORTER_ASSERT(r, skstd::ends_with(xyz, "xyz"));
45 REPORTER_ASSERT(r, !skstd::starts_with(xyz, "wxyz"));
46 REPORTER_ASSERT(r, !skstd::ends_with(xyz, "wxyz"));
47
48 xyz.swap(empty);
49 REPORTER_ASSERT(r, xyz == "");
50 REPORTER_ASSERT(r, empty == "xyz");
51}
EMSCRIPTEN_KEEPALIVE void empty()
constexpr bool starts_with(std::string_view str, std::string_view prefix)
Definition: SkStringView.h:17
constexpr bool ends_with(std::string_view str, std::string_view suffix)
Definition: SkStringView.h:28