|
24 | 24 | DEALINGS IN THE SOFTWARE.
|
25 | 25 | */
|
26 | 26 |
|
| 27 | +/* Deliberately including first to make sure it works without ArrayView being |
| 28 | + included first */ |
| 29 | +#include "Corrade/Containers/StringView.h" |
| 30 | + |
27 | 31 | #include <sstream>
|
28 | 32 |
|
29 | 33 | #include "Corrade/Cpu.h"
|
30 | 34 | #include "Corrade/Containers/Array.h"
|
31 | 35 | #include "Corrade/Containers/StaticArray.h"
|
32 |
| -#include "Corrade/Containers/StringView.h" |
33 | 36 | #include "Corrade/TestSuite/Tester.h"
|
34 | 37 | #include "Corrade/TestSuite/Compare/Container.h"
|
35 | 38 | #include "Corrade/TestSuite/Compare/Numeric.h"
|
@@ -122,6 +125,7 @@ struct StringViewTest: TestSuite::Tester {
|
122 | 125 | void constructNullptrNullTerminated();
|
123 | 126 |
|
124 | 127 | template<class T> void convertArrayView();
|
| 128 | + void convertArrayViewConstexpr(); |
125 | 129 | template<class T> void convertVoidArrayView();
|
126 | 130 | void convertConstFromArrayView();
|
127 | 131 | void convertToConstArrayView();
|
@@ -263,6 +267,7 @@ StringViewTest::StringViewTest() {
|
263 | 267 |
|
264 | 268 | &StringViewTest::convertArrayView<const char>,
|
265 | 269 | &StringViewTest::convertArrayView<char>,
|
| 270 | + &StringViewTest::convertArrayViewConstexpr, |
266 | 271 | &StringViewTest::convertConstFromArrayView,
|
267 | 272 | &StringViewTest::convertToConstArrayView,
|
268 | 273 | &StringViewTest::convertConstFromArray,
|
@@ -664,6 +669,18 @@ template<class T> void StringViewTest::convertArrayView() {
|
664 | 669 | CORRADE_COMPARE(static_cast<const void*>(array2.data()), &data[0]);
|
665 | 670 | }
|
666 | 671 |
|
| 672 | +constexpr const char String[] = "hell\0!!"; /* 7 chars + \0 at the end */ |
| 673 | + |
| 674 | +void StringViewTest::convertArrayViewConstexpr() { |
| 675 | + constexpr StringView view = {arrayView(String).exceptSuffix(1), StringViewFlag::Global|StringViewFlag::NullTerminated}; |
| 676 | + constexpr std::size_t size = view.size(); |
| 677 | + constexpr StringViewFlags flags = view.flags(); |
| 678 | + constexpr const void* data = view.data(); |
| 679 | + CORRADE_COMPARE(size, 7); |
| 680 | + CORRADE_COMPARE(flags, StringViewFlag::Global|StringViewFlag::NullTerminated); |
| 681 | + CORRADE_COMPARE(data, String); |
| 682 | +} |
| 683 | + |
667 | 684 | void StringViewTest::convertConstFromArrayView() {
|
668 | 685 | char data[] = "hello!";
|
669 | 686 | ArrayView<char> array = data;
|
|
0 commit comments