blob: 8ecb1b252d681c7ec4509b6253f3b38ddfbe45d4 [file] [log] [blame]
Dominik Laskowskic74e9e22021-12-02 09:49:12 -08001/*
2 * Copyright 2021 The Android Open Source Project
3 *
4 * Licensed under the Apache License, Version 2.0 (the "License");
5 * you may not use this file except in compliance with the License.
6 * You may obtain a copy of the License at
7 *
8 * http://www.apache.org/licenses/LICENSE-2.0
9 *
10 * Unless required by applicable law or agreed to in writing, software
11 * distributed under the License is distributed on an "AS IS" BASIS,
12 * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
13 * See the License for the specific language governing permissions and
14 * limitations under the License.
15 */
16
17#include <ftl/concat.h>
18#include <gtest/gtest.h>
19
20namespace android::test {
21
22// Keep in sync with example usage in header file.
23TEST(Concat, Example) {
24 std::string_view name = "Volume";
25 ftl::Concat string(ftl::truncated<3>(name), ": ", -3, " dB");
26
27 EXPECT_EQ(string.str(), "Vol: -3 dB");
28 EXPECT_EQ(string.c_str()[string.size()], '\0');
29}
30
31namespace {
32
33static_assert(ftl::Concat{"foo"}.str() == "foo");
34static_assert(ftl::Concat{ftl::truncated<3>("foobar")}.str() == "foo");
35
36constexpr ftl::Concat kConcat{"po", "trz", "ebie"};
37
38static_assert(kConcat.size() == 9);
39static_assert(kConcat.max_size() == 9);
40static_assert(kConcat.str() == "potrzebie");
41static_assert(kConcat.str() == std::string_view(kConcat.c_str()));
42
43constexpr auto concat() {
44 return ftl::Concat{ftl::truncated<1>("v???"), ftl::truncated<2>("ee??"),
45 ftl::truncated<3>("ble?"), ftl::truncated<4>("fetz"),
46 ftl::truncated<90>("er")};
47}
48
49static_assert(concat().size() == 12);
50static_assert(concat().max_size() == 100);
51static_assert(concat().str() == "veeblefetzer");
52static_assert(concat().str() == std::string_view(concat().c_str()));
53
54} // namespace
55} // namespace android::test