Flutter Engine
The Flutter Engine
Loading...
Searching...
No Matches
SkStringViewTest.cpp
Go to the documentation of this file.
1/*
2 * Copyright 2021 Google LLC.
3 *
4 * Use of this source code is governed by a BSD-style license that can be
5 * found in the LICENSE file.
6 */
7
9#include "tests/Test.h"
10
11#include <string>
12#include <string_view>
13
14DEF_TEST(SkStringViewStartsAndEnds, r) {
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}
52
53DEF_TEST(SkStringViewContains, r) {
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 DEF_TEST(name, reporter)
Definition Test.h:312
#define REPORTER_ASSERT(r, cond,...)
Definition Test.h:286
EMSCRIPTEN_KEEPALIVE void empty()
constexpr bool starts_with(std::string_view str, std::string_view prefix)
constexpr bool ends_with(std::string_view str, std::string_view suffix)
constexpr bool contains(std::string_view str, std::string_view needle)