Debian Codegraph @

tests/core/templates/test_span.h

raw symbols SCIP
1 /**************************************************************************/
2 /* test_span.h */
3 /**************************************************************************/
4 /* This file is part of: */
5 /* GODOT ENGINE */
6 /* https://godotengine.org */
7 /**************************************************************************/
8 /* Copyright (c) 2014-present Godot Engine contributors (see AUTHORS.md). */
9 /* Copyright (c) 2007-2014 Juan Linietsky, Ariel Manzur. */
10 /* */
11 /* Permission is hereby granted, free of charge, to any person obtaining */
12 /* a copy of this software and associated documentation files (the */
13 /* "Software"), to deal in the Software without restriction, including */
14 /* without limitation the rights to use, copy, modify, merge, publish, */
15 /* distribute, sublicense, and/or sell copies of the Software, and to */
16 /* permit persons to whom the Software is furnished to do so, subject to */
17 /* the following conditions: */
18 /* */
19 /* The above copyright notice and this permission notice shall be */
20 /* included in all copies or substantial portions of the Software. */
21 /* */
22 /* THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, */
23 /* EXPRESS OR IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF */
24 /* MERCHANTABILITY, FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. */
25 /* IN NO EVENT SHALL THE AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY */
26 /* CLAIM, DAMAGES OR OTHER LIABILITY, WHETHER IN AN ACTION OF CONTRACT, */
27 /* TORT OR OTHERWISE, ARISING FROM, OUT OF OR IN CONNECTION WITH THE */
28 /* SOFTWARE OR THE USE OR OTHER DEALINGS IN THE SOFTWARE. */
29 /**************************************************************************/
30
31 #pragma once
32
33 #include "core/templates/span.h"
34
35 #include "tests/test_macros.h"
36
37 namespace TestSpan {
38
39 TEST_CASE("[Span] Constexpr Validators") {
40 constexpr Span<uint16_t> span_empty;
41 static_assert(span_empty.ptr() == nullptr);
42 static_assert(span_empty.size() == 0);
43 static_assert(span_empty.is_empty());
44
45 constexpr static uint16_t value = 5;
46 Span<uint16_t> span_value(&value, 1);
47 CHECK(span_value.ptr() == &value);
48 CHECK(span_value.size() == 1);
49 CHECK(!span_value.is_empty());
50
51 static constexpr int ints[] = { 0, 1, 2, 3, 4, 5 };
52 constexpr Span<int> span_array = ints;
53 static_assert(span_array.size() == 6);
54 static_assert(!span_array.is_empty());
55 static_assert(span_array[0] == 0);
56 static_assert(span_array[span_array.size() - 1] == 5);
57
58 constexpr Span<char32_t> span_string = U"122345";
59 static_assert(span_string.size() == 6);
60 static_assert(!span_string.is_empty());
61 static_assert(span_string[0] == U'1');
62 static_assert(span_string[span_string.size() - 1] == U'5');
63
64 CHECK_EQ(span_string, span_string); // Same identity / ptr.
65 CHECK_EQ(span_string, Span(U"1223456", 6)); // Different ptr.
66 CHECK_EQ(span_string, Span("122345").reinterpret<uint8_t>()); // Different type.
67
68 int idx = 0;
69 for (const char32_t &chr : span_string) {
70 CHECK_EQ(chr, span_string[idx++]);
71 }
72 }
73
74 } // namespace TestSpan