William A. Kennington III | be79c1e | 2021-01-25 16:06:31 -0800 | [diff] [blame] | 1 | #include <array> |
William A. Kennington III | e099038 | 2019-10-18 02:10:25 -0700 | [diff] [blame] | 2 | #include <endian.h> |
William A. Kennington III | 6c15d9a | 2022-08-24 13:45:42 -0700 | [diff] [blame^] | 3 | #include <gmock/gmock.h> |
| 4 | #include <gtest/gtest.h> |
William A. Kennington III | 615b82a | 2022-08-24 13:47:17 -0700 | [diff] [blame] | 5 | #include <span> |
William A. Kennington III | e099038 | 2019-10-18 02:10:25 -0700 | [diff] [blame] | 6 | #include <stdexcept> |
| 7 | #include <stdplus/raw.hpp> |
| 8 | #include <string_view> |
| 9 | #include <vector> |
| 10 | |
| 11 | namespace stdplus |
| 12 | { |
| 13 | namespace raw |
| 14 | { |
| 15 | namespace |
| 16 | { |
| 17 | |
William A. Kennington III | 6c15d9a | 2022-08-24 13:45:42 -0700 | [diff] [blame^] | 18 | TEST(Equal, Equal) |
William A. Kennington III | 3b35fcf | 2020-06-13 18:42:39 -0700 | [diff] [blame] | 19 | { |
| 20 | int a = 4; |
| 21 | unsigned b = 4; |
William A. Kennington III | 6c15d9a | 2022-08-24 13:45:42 -0700 | [diff] [blame^] | 22 | EXPECT_TRUE(equal(a, b)); |
William A. Kennington III | 3b35fcf | 2020-06-13 18:42:39 -0700 | [diff] [blame] | 23 | b = 5; |
William A. Kennington III | 6c15d9a | 2022-08-24 13:45:42 -0700 | [diff] [blame^] | 24 | EXPECT_FALSE(equal(a, b)); |
William A. Kennington III | 3b35fcf | 2020-06-13 18:42:39 -0700 | [diff] [blame] | 25 | } |
| 26 | |
William A. Kennington III | 6c15d9a | 2022-08-24 13:45:42 -0700 | [diff] [blame^] | 27 | TEST(CopyFrom, Empty) |
William A. Kennington III | e099038 | 2019-10-18 02:10:25 -0700 | [diff] [blame] | 28 | { |
William A. Kennington III | 5c99ff4 | 2020-07-19 02:29:26 -0700 | [diff] [blame] | 29 | const std::string_view cs; |
William A. Kennington III | 6c15d9a | 2022-08-24 13:45:42 -0700 | [diff] [blame^] | 30 | EXPECT_THROW(copyFrom<int>(cs), std::runtime_error); |
William A. Kennington III | 5c99ff4 | 2020-07-19 02:29:26 -0700 | [diff] [blame] | 31 | std::string_view s; |
William A. Kennington III | 6c15d9a | 2022-08-24 13:45:42 -0700 | [diff] [blame^] | 32 | EXPECT_THROW(copyFrom<int>(s), std::runtime_error); |
William A. Kennington III | e099038 | 2019-10-18 02:10:25 -0700 | [diff] [blame] | 33 | } |
| 34 | |
William A. Kennington III | 6c15d9a | 2022-08-24 13:45:42 -0700 | [diff] [blame^] | 35 | TEST(CopyFrom, Basic) |
William A. Kennington III | e099038 | 2019-10-18 02:10:25 -0700 | [diff] [blame] | 36 | { |
| 37 | int a = 4; |
| 38 | const std::string_view s(reinterpret_cast<char*>(&a), sizeof(a)); |
William A. Kennington III | 6c15d9a | 2022-08-24 13:45:42 -0700 | [diff] [blame^] | 39 | EXPECT_EQ(a, copyFrom<int>(s)); |
William A. Kennington III | e099038 | 2019-10-18 02:10:25 -0700 | [diff] [blame] | 40 | } |
| 41 | |
William A. Kennington III | 6c15d9a | 2022-08-24 13:45:42 -0700 | [diff] [blame^] | 42 | TEST(CopyFrom, Partial) |
William A. Kennington III | e099038 | 2019-10-18 02:10:25 -0700 | [diff] [blame] | 43 | { |
| 44 | const std::vector<char> s = {'a', 'b', 'c'}; |
William A. Kennington III | 6c15d9a | 2022-08-24 13:45:42 -0700 | [diff] [blame^] | 45 | EXPECT_EQ('a', copyFrom<char>(s)); |
William A. Kennington III | e099038 | 2019-10-18 02:10:25 -0700 | [diff] [blame] | 46 | const char s2[] = "def"; |
William A. Kennington III | 6c15d9a | 2022-08-24 13:45:42 -0700 | [diff] [blame^] | 47 | EXPECT_EQ('d', copyFrom<char>(s2)); |
William A. Kennington III | e099038 | 2019-10-18 02:10:25 -0700 | [diff] [blame] | 48 | } |
| 49 | |
William A. Kennington III | 5c99ff4 | 2020-07-19 02:29:26 -0700 | [diff] [blame] | 50 | struct Int |
| 51 | { |
| 52 | uint8_t data[sizeof(int)]; |
| 53 | |
| 54 | inline bool operator==(const Int& other) const |
| 55 | { |
| 56 | return memcmp(data, other.data, sizeof(data)) == 0; |
| 57 | } |
| 58 | }; |
| 59 | |
William A. Kennington III | 6c15d9a | 2022-08-24 13:45:42 -0700 | [diff] [blame^] | 60 | TEST(RefFrom, Empty) |
William A. Kennington III | 5c99ff4 | 2020-07-19 02:29:26 -0700 | [diff] [blame] | 61 | { |
| 62 | const std::string_view cs; |
William A. Kennington III | 6c15d9a | 2022-08-24 13:45:42 -0700 | [diff] [blame^] | 63 | EXPECT_THROW(refFrom<Int>(cs), std::runtime_error); |
William A. Kennington III | 5c99ff4 | 2020-07-19 02:29:26 -0700 | [diff] [blame] | 64 | std::string_view s; |
William A. Kennington III | 6c15d9a | 2022-08-24 13:45:42 -0700 | [diff] [blame^] | 65 | EXPECT_THROW(refFrom<Int>(s), std::runtime_error); |
William A. Kennington III | 5c99ff4 | 2020-07-19 02:29:26 -0700 | [diff] [blame] | 66 | } |
| 67 | |
William A. Kennington III | 6c15d9a | 2022-08-24 13:45:42 -0700 | [diff] [blame^] | 68 | TEST(RefFrom, Basic) |
William A. Kennington III | 5c99ff4 | 2020-07-19 02:29:26 -0700 | [diff] [blame] | 69 | { |
| 70 | Int a = {4, 0, 0, 4}; |
| 71 | const std::string_view s(reinterpret_cast<char*>(&a), sizeof(a)); |
William A. Kennington III | 6c15d9a | 2022-08-24 13:45:42 -0700 | [diff] [blame^] | 72 | EXPECT_EQ(a, refFrom<Int>(s)); |
William A. Kennington III | 5c99ff4 | 2020-07-19 02:29:26 -0700 | [diff] [blame] | 73 | } |
| 74 | |
William A. Kennington III | 6c15d9a | 2022-08-24 13:45:42 -0700 | [diff] [blame^] | 75 | TEST(RefFrom, Partial) |
William A. Kennington III | 5c99ff4 | 2020-07-19 02:29:26 -0700 | [diff] [blame] | 76 | { |
| 77 | const std::vector<char> s = {'a', 'b', 'c'}; |
William A. Kennington III | 6c15d9a | 2022-08-24 13:45:42 -0700 | [diff] [blame^] | 78 | EXPECT_EQ('a', refFrom<char>(s)); |
William A. Kennington III | 5c99ff4 | 2020-07-19 02:29:26 -0700 | [diff] [blame] | 79 | const char s2[] = "def"; |
William A. Kennington III | 6c15d9a | 2022-08-24 13:45:42 -0700 | [diff] [blame^] | 80 | EXPECT_EQ('d', refFrom<char>(s2)); |
William A. Kennington III | 5c99ff4 | 2020-07-19 02:29:26 -0700 | [diff] [blame] | 81 | } |
| 82 | |
William A. Kennington III | 6c15d9a | 2022-08-24 13:45:42 -0700 | [diff] [blame^] | 83 | TEST(Extract, TooSmall) |
William A. Kennington III | e099038 | 2019-10-18 02:10:25 -0700 | [diff] [blame] | 84 | { |
| 85 | std::string_view s("a"); |
William A. Kennington III | 6c15d9a | 2022-08-24 13:45:42 -0700 | [diff] [blame^] | 86 | EXPECT_THROW(extract<int>(s), std::runtime_error); |
| 87 | EXPECT_EQ("a", s); |
William A. Kennington III | e099038 | 2019-10-18 02:10:25 -0700 | [diff] [blame] | 88 | } |
| 89 | |
William A. Kennington III | 6c15d9a | 2022-08-24 13:45:42 -0700 | [diff] [blame^] | 90 | TEST(Extract, Basic) |
William A. Kennington III | e099038 | 2019-10-18 02:10:25 -0700 | [diff] [blame] | 91 | { |
| 92 | int a = 4; |
| 93 | std::string_view s(reinterpret_cast<char*>(&a), sizeof(a)); |
William A. Kennington III | 6c15d9a | 2022-08-24 13:45:42 -0700 | [diff] [blame^] | 94 | EXPECT_EQ(a, extract<int>(s)); |
| 95 | EXPECT_TRUE(s.empty()); |
William A. Kennington III | e099038 | 2019-10-18 02:10:25 -0700 | [diff] [blame] | 96 | } |
| 97 | |
William A. Kennington III | 6c15d9a | 2022-08-24 13:45:42 -0700 | [diff] [blame^] | 98 | TEST(Extract, Partial) |
William A. Kennington III | e099038 | 2019-10-18 02:10:25 -0700 | [diff] [blame] | 99 | { |
| 100 | std::string_view s("abc"); |
William A. Kennington III | 6c15d9a | 2022-08-24 13:45:42 -0700 | [diff] [blame^] | 101 | EXPECT_EQ('a', extract<char>(s)); |
| 102 | EXPECT_EQ("bc", s); |
William A. Kennington III | e099038 | 2019-10-18 02:10:25 -0700 | [diff] [blame] | 103 | } |
| 104 | |
William A. Kennington III | 6c15d9a | 2022-08-24 13:45:42 -0700 | [diff] [blame^] | 105 | TEST(ExtractRef, TooSmall) |
William A. Kennington III | 5c99ff4 | 2020-07-19 02:29:26 -0700 | [diff] [blame] | 106 | { |
| 107 | std::string_view s("a"); |
William A. Kennington III | 6c15d9a | 2022-08-24 13:45:42 -0700 | [diff] [blame^] | 108 | EXPECT_THROW(extractRef<Int>(s), std::runtime_error); |
| 109 | EXPECT_EQ("a", s); |
William A. Kennington III | 5c99ff4 | 2020-07-19 02:29:26 -0700 | [diff] [blame] | 110 | } |
| 111 | |
William A. Kennington III | 6c15d9a | 2022-08-24 13:45:42 -0700 | [diff] [blame^] | 112 | TEST(ExtractRef, Basic) |
William A. Kennington III | 5c99ff4 | 2020-07-19 02:29:26 -0700 | [diff] [blame] | 113 | { |
| 114 | Int a = {4, 0, 0, 4}; |
| 115 | std::string_view s(reinterpret_cast<char*>(&a), sizeof(a)); |
William A. Kennington III | 6c15d9a | 2022-08-24 13:45:42 -0700 | [diff] [blame^] | 116 | EXPECT_EQ(a, extractRef<Int>(s)); |
| 117 | EXPECT_TRUE(s.empty()); |
William A. Kennington III | 5c99ff4 | 2020-07-19 02:29:26 -0700 | [diff] [blame] | 118 | } |
| 119 | |
William A. Kennington III | 6c15d9a | 2022-08-24 13:45:42 -0700 | [diff] [blame^] | 120 | TEST(ExtractRef, Partial) |
William A. Kennington III | 5c99ff4 | 2020-07-19 02:29:26 -0700 | [diff] [blame] | 121 | { |
| 122 | std::string_view s("abc"); |
William A. Kennington III | 6c15d9a | 2022-08-24 13:45:42 -0700 | [diff] [blame^] | 123 | EXPECT_EQ('a', extractRef<char>(s)); |
| 124 | EXPECT_EQ("bc", s); |
William A. Kennington III | 5c99ff4 | 2020-07-19 02:29:26 -0700 | [diff] [blame] | 125 | } |
| 126 | |
William A. Kennington III | 6c15d9a | 2022-08-24 13:45:42 -0700 | [diff] [blame^] | 127 | TEST(AsView, Byte) |
William A. Kennington III | e099038 | 2019-10-18 02:10:25 -0700 | [diff] [blame] | 128 | { |
| 129 | int32_t a = 4; |
| 130 | auto s = asView<uint8_t>(a); |
William A. Kennington III | 6c15d9a | 2022-08-24 13:45:42 -0700 | [diff] [blame^] | 131 | EXPECT_EQ(a, copyFrom<int>(s)); |
William A. Kennington III | e099038 | 2019-10-18 02:10:25 -0700 | [diff] [blame] | 132 | } |
| 133 | |
William A. Kennington III | 6c15d9a | 2022-08-24 13:45:42 -0700 | [diff] [blame^] | 134 | TEST(AsView, Int) |
William A. Kennington III | e099038 | 2019-10-18 02:10:25 -0700 | [diff] [blame] | 135 | { |
| 136 | int32_t a = 4; |
| 137 | auto s = asView<char16_t>(a); |
William A. Kennington III | 6c15d9a | 2022-08-24 13:45:42 -0700 | [diff] [blame^] | 138 | EXPECT_EQ(a, copyFrom<int>(s)); |
William A. Kennington III | e099038 | 2019-10-18 02:10:25 -0700 | [diff] [blame] | 139 | } |
| 140 | |
William A. Kennington III | 6c15d9a | 2022-08-24 13:45:42 -0700 | [diff] [blame^] | 141 | using testing::ElementsAre; |
| 142 | using testing::ElementsAreArray; |
| 143 | |
| 144 | TEST(AsView, Array) |
William A. Kennington III | e099038 | 2019-10-18 02:10:25 -0700 | [diff] [blame] | 145 | { |
| 146 | std::vector<uint32_t> arr = {htole32(1), htole32(2)}; |
| 147 | auto s = asView<char16_t>(arr); |
William A. Kennington III | 6c15d9a | 2022-08-24 13:45:42 -0700 | [diff] [blame^] | 148 | EXPECT_THAT(s, ElementsAre(htole16(1), htole16(0), htole16(2), htole16(0))); |
William A. Kennington III | e099038 | 2019-10-18 02:10:25 -0700 | [diff] [blame] | 149 | } |
| 150 | |
William A. Kennington III | 6c15d9a | 2022-08-24 13:45:42 -0700 | [diff] [blame^] | 151 | TEST(AsView, StringView) |
William A. Kennington III | ba7d754 | 2020-07-19 20:04:44 -0700 | [diff] [blame] | 152 | { |
| 153 | std::string_view sv = "ab"; |
| 154 | auto s = asView<uint8_t>(sv); |
William A. Kennington III | 6c15d9a | 2022-08-24 13:45:42 -0700 | [diff] [blame^] | 155 | EXPECT_THAT(s, ElementsAreArray(sv)); |
William A. Kennington III | ba7d754 | 2020-07-19 20:04:44 -0700 | [diff] [blame] | 156 | } |
| 157 | |
William A. Kennington III | 6c15d9a | 2022-08-24 13:45:42 -0700 | [diff] [blame^] | 158 | TEST(SpanExtract, TooSmall) |
William A. Kennington III | e099038 | 2019-10-18 02:10:25 -0700 | [diff] [blame] | 159 | { |
| 160 | const std::vector<char> v = {'c'}; |
Patrick Williams | 68975b9 | 2022-04-27 16:00:26 -0500 | [diff] [blame] | 161 | std::span<const char> s = v; |
William A. Kennington III | 6c15d9a | 2022-08-24 13:45:42 -0700 | [diff] [blame^] | 162 | EXPECT_THROW(extract<int>(s), std::runtime_error); |
| 163 | EXPECT_THAT(s, ElementsAreArray(v)); |
William A. Kennington III | e099038 | 2019-10-18 02:10:25 -0700 | [diff] [blame] | 164 | } |
| 165 | |
William A. Kennington III | 6c15d9a | 2022-08-24 13:45:42 -0700 | [diff] [blame^] | 166 | TEST(SpanExtract, Basic) |
William A. Kennington III | e099038 | 2019-10-18 02:10:25 -0700 | [diff] [blame] | 167 | { |
| 168 | const std::vector<int> v = {4}; |
Patrick Williams | 68975b9 | 2022-04-27 16:00:26 -0500 | [diff] [blame] | 169 | std::span<const int> s = v; |
William A. Kennington III | 6c15d9a | 2022-08-24 13:45:42 -0700 | [diff] [blame^] | 170 | EXPECT_EQ(v[0], extract<int>(s)); |
| 171 | EXPECT_TRUE(s.empty()); |
William A. Kennington III | e099038 | 2019-10-18 02:10:25 -0700 | [diff] [blame] | 172 | } |
| 173 | |
William A. Kennington III | 6c15d9a | 2022-08-24 13:45:42 -0700 | [diff] [blame^] | 174 | TEST(SpanExtract, Larger) |
William A. Kennington III | e099038 | 2019-10-18 02:10:25 -0700 | [diff] [blame] | 175 | { |
| 176 | const std::vector<int> v{3, 4, 5}; |
Patrick Williams | 68975b9 | 2022-04-27 16:00:26 -0500 | [diff] [blame] | 177 | std::span<const int> s = v; |
William A. Kennington III | 6c15d9a | 2022-08-24 13:45:42 -0700 | [diff] [blame^] | 178 | EXPECT_EQ(v[0], extract<int>(s)); |
| 179 | EXPECT_THAT(s, ElementsAre(v[1], v[2])); |
William A. Kennington III | e099038 | 2019-10-18 02:10:25 -0700 | [diff] [blame] | 180 | } |
| 181 | |
William A. Kennington III | 6c15d9a | 2022-08-24 13:45:42 -0700 | [diff] [blame^] | 182 | TEST(SpanExtractRef, TooSmall) |
William A. Kennington III | 5c99ff4 | 2020-07-19 02:29:26 -0700 | [diff] [blame] | 183 | { |
| 184 | const std::vector<char> v = {'c'}; |
Patrick Williams | 68975b9 | 2022-04-27 16:00:26 -0500 | [diff] [blame] | 185 | std::span<const char> s = v; |
William A. Kennington III | 6c15d9a | 2022-08-24 13:45:42 -0700 | [diff] [blame^] | 186 | EXPECT_THROW(extractRef<Int>(s), std::runtime_error); |
| 187 | EXPECT_THAT(s, ElementsAreArray(v)); |
William A. Kennington III | 5c99ff4 | 2020-07-19 02:29:26 -0700 | [diff] [blame] | 188 | } |
| 189 | |
William A. Kennington III | 6c15d9a | 2022-08-24 13:45:42 -0700 | [diff] [blame^] | 190 | TEST(SpanExtractRef, Basic) |
William A. Kennington III | 5c99ff4 | 2020-07-19 02:29:26 -0700 | [diff] [blame] | 191 | { |
| 192 | const std::vector<Int> v = {{4, 0, 0, 4}}; |
Patrick Williams | 68975b9 | 2022-04-27 16:00:26 -0500 | [diff] [blame] | 193 | std::span<const Int> s = v; |
William A. Kennington III | 6c15d9a | 2022-08-24 13:45:42 -0700 | [diff] [blame^] | 194 | EXPECT_EQ(v[0], extractRef<Int>(s)); |
| 195 | EXPECT_TRUE(s.empty()); |
William A. Kennington III | 5c99ff4 | 2020-07-19 02:29:26 -0700 | [diff] [blame] | 196 | } |
| 197 | |
William A. Kennington III | 6c15d9a | 2022-08-24 13:45:42 -0700 | [diff] [blame^] | 198 | TEST(SpanExtractRef, Larger) |
William A. Kennington III | 5c99ff4 | 2020-07-19 02:29:26 -0700 | [diff] [blame] | 199 | { |
| 200 | const std::vector<Int> v{{3}, {4}, {5}}; |
Patrick Williams | 68975b9 | 2022-04-27 16:00:26 -0500 | [diff] [blame] | 201 | std::span<const Int> s = v; |
William A. Kennington III | 6c15d9a | 2022-08-24 13:45:42 -0700 | [diff] [blame^] | 202 | EXPECT_EQ(v[0], extractRef<Int>(s)); |
| 203 | EXPECT_THAT(s, ElementsAre(v[1], v[2])); |
William A. Kennington III | 5c99ff4 | 2020-07-19 02:29:26 -0700 | [diff] [blame] | 204 | } |
| 205 | |
William A. Kennington III | 6c15d9a | 2022-08-24 13:45:42 -0700 | [diff] [blame^] | 206 | TEST(AsSpan, ConstInt) |
William A. Kennington III | e099038 | 2019-10-18 02:10:25 -0700 | [diff] [blame] | 207 | { |
| 208 | const uint64_t data = htole64(0xffff0000); |
| 209 | auto s = asSpan<uint32_t>(data); |
William A. Kennington III | 6c15d9a | 2022-08-24 13:45:42 -0700 | [diff] [blame^] | 210 | EXPECT_THAT(s, ElementsAre(htole32(0xffff0000), htole32(0x00000000))); |
William A. Kennington III | e099038 | 2019-10-18 02:10:25 -0700 | [diff] [blame] | 211 | } |
| 212 | |
William A. Kennington III | 6c15d9a | 2022-08-24 13:45:42 -0700 | [diff] [blame^] | 213 | TEST(AsSpan, ConstArray) |
William A. Kennington III | e099038 | 2019-10-18 02:10:25 -0700 | [diff] [blame] | 214 | { |
| 215 | const std::vector<uint32_t> arr = {htole32(1), htole32(2)}; |
| 216 | auto s = asSpan<uint16_t>(arr); |
William A. Kennington III | 6c15d9a | 2022-08-24 13:45:42 -0700 | [diff] [blame^] | 217 | EXPECT_THAT(s, ElementsAre(htole16(1), htole16(0), htole16(2), htole16(0))); |
William A. Kennington III | e099038 | 2019-10-18 02:10:25 -0700 | [diff] [blame] | 218 | } |
| 219 | |
William A. Kennington III | 6c15d9a | 2022-08-24 13:45:42 -0700 | [diff] [blame^] | 220 | TEST(AsSpan, Int) |
William A. Kennington III | e099038 | 2019-10-18 02:10:25 -0700 | [diff] [blame] | 221 | { |
William A. Kennington III | a9cf86f | 2021-08-03 11:42:11 -0700 | [diff] [blame] | 222 | struct |
| 223 | { |
| 224 | uint64_t a; |
| 225 | uint64_t* data() |
| 226 | { |
| 227 | return &a; |
| 228 | } |
| 229 | } data = {htole64(0xffff0000)}; |
William A. Kennington III | e099038 | 2019-10-18 02:10:25 -0700 | [diff] [blame] | 230 | auto s = asSpan<uint16_t>(data); |
William A. Kennington III | 6c15d9a | 2022-08-24 13:45:42 -0700 | [diff] [blame^] | 231 | EXPECT_THAT(s, ElementsAre(htole16(0x0000), htole16(0xffff), |
| 232 | htole16(0x0000), htole16(0x0000))); |
William A. Kennington III | e099038 | 2019-10-18 02:10:25 -0700 | [diff] [blame] | 233 | s[2] = 0xfefe; |
William A. Kennington III | 6c15d9a | 2022-08-24 13:45:42 -0700 | [diff] [blame^] | 234 | EXPECT_THAT(s, ElementsAre(htole16(0x0000), htole16(0xffff), |
| 235 | htole16(0xfefe), htole16(0x0000))); |
William A. Kennington III | e099038 | 2019-10-18 02:10:25 -0700 | [diff] [blame] | 236 | } |
| 237 | |
William A. Kennington III | 6c15d9a | 2022-08-24 13:45:42 -0700 | [diff] [blame^] | 238 | TEST(AsSpan, Array) |
William A. Kennington III | e099038 | 2019-10-18 02:10:25 -0700 | [diff] [blame] | 239 | { |
| 240 | std::vector<uint32_t> arr = {htole32(1), htole32(2)}; |
| 241 | auto s = asSpan<uint16_t>(arr); |
William A. Kennington III | 6c15d9a | 2022-08-24 13:45:42 -0700 | [diff] [blame^] | 242 | EXPECT_THAT(s, ElementsAre(htole16(1), htole16(0), htole16(2), htole16(0))); |
William A. Kennington III | e099038 | 2019-10-18 02:10:25 -0700 | [diff] [blame] | 243 | } |
| 244 | |
William A. Kennington III | 6c15d9a | 2022-08-24 13:45:42 -0700 | [diff] [blame^] | 245 | TEST(AsSpan, Span) |
William A. Kennington III | ba7d754 | 2020-07-19 20:04:44 -0700 | [diff] [blame] | 246 | { |
| 247 | std::array<char, 2> arr = {'a', 'b'}; |
Patrick Williams | 68975b9 | 2022-04-27 16:00:26 -0500 | [diff] [blame] | 248 | auto sp1 = std::span<const char>(arr); |
William A. Kennington III | ba7d754 | 2020-07-19 20:04:44 -0700 | [diff] [blame] | 249 | auto s1 = asSpan<uint8_t>(sp1); |
William A. Kennington III | 6c15d9a | 2022-08-24 13:45:42 -0700 | [diff] [blame^] | 250 | EXPECT_THAT(s1, ElementsAreArray(arr)); |
Patrick Williams | 68975b9 | 2022-04-27 16:00:26 -0500 | [diff] [blame] | 251 | auto sp2 = std::span<char>(arr); |
William A. Kennington III | ba7d754 | 2020-07-19 20:04:44 -0700 | [diff] [blame] | 252 | auto s2 = asSpan<uint8_t>(sp2); |
William A. Kennington III | 6c15d9a | 2022-08-24 13:45:42 -0700 | [diff] [blame^] | 253 | EXPECT_THAT(s2, ElementsAreArray(arr)); |
William A. Kennington III | ba7d754 | 2020-07-19 20:04:44 -0700 | [diff] [blame] | 254 | } |
| 255 | |
William A. Kennington III | e099038 | 2019-10-18 02:10:25 -0700 | [diff] [blame] | 256 | } // namespace |
| 257 | } // namespace raw |
| 258 | } // namespace stdplus |