mirror of
https://github.com/microsoft/GSL.git
synced 2025-11-16 23:39:42 +01:00
gsl::at behavior change regarding gsl::span (#985)
* move span specialization of 'at' to <gsl/span> and update the parameter to be taken by reference * undid previous changes and acted upon decisions made in maintainer sync. Fixed tests failing in /kernel mode * ran clang-format on the include folder * ran clang-format on the test folder Co-authored-by: Jordan Maples <jordan.maples@microsoft.com>
This commit is contained in:
committed by
GitHub
parent
c1cbb41b42
commit
b26f6d5ec7
@@ -16,7 +16,7 @@
|
||||
|
||||
#include <gtest/gtest.h>
|
||||
|
||||
#include <gsl/assert> // for Expects, fail_fast (ptr only)
|
||||
#include <gsl/assert> // for Expects, fail_fast (ptr only)
|
||||
#include <gsl/pointers> // for owner
|
||||
#include <gsl/span> // for span, dynamic_extent
|
||||
#include <gsl/string_span> // for basic_string_span, operator==, ensure_z
|
||||
@@ -28,13 +28,11 @@
|
||||
#include <type_traits> // for remove_reference<>::type
|
||||
#include <vector> // for vector, allocator
|
||||
|
||||
#include "deathTestCommon.h"
|
||||
|
||||
using namespace std;
|
||||
using namespace gsl;
|
||||
|
||||
namespace
|
||||
{
|
||||
static constexpr char deathstring[] = "Expected Death";
|
||||
}
|
||||
// Generic string functions
|
||||
|
||||
namespace generic
|
||||
@@ -76,8 +74,7 @@ T create()
|
||||
|
||||
template <class T>
|
||||
void use(basic_string_span<T, gsl::dynamic_extent>)
|
||||
{
|
||||
}
|
||||
{}
|
||||
#endif
|
||||
|
||||
czstring_span<> CreateTempName(string_span<> span)
|
||||
@@ -85,7 +82,8 @@ czstring_span<> CreateTempName(string_span<> span)
|
||||
Expects(span.size() > 1);
|
||||
|
||||
std::size_t last = 0;
|
||||
if (span.size() > 4) {
|
||||
if (span.size() > 4)
|
||||
{
|
||||
span[0] = 't';
|
||||
span[1] = 'm';
|
||||
span[2] = 'p';
|
||||
@@ -102,7 +100,8 @@ cwzstring_span<> CreateTempNameW(wstring_span<> span)
|
||||
Expects(span.size() > 1);
|
||||
|
||||
std::size_t last = 0;
|
||||
if (span.size() > 4) {
|
||||
if (span.size() > 4)
|
||||
{
|
||||
span[0] = L't';
|
||||
span[1] = L'm';
|
||||
span[2] = L'p';
|
||||
@@ -119,7 +118,8 @@ cu16zstring_span<> CreateTempNameU16(u16string_span<> span)
|
||||
Expects(span.size() > 1);
|
||||
|
||||
std::size_t last = 0;
|
||||
if (span.size() > 4) {
|
||||
if (span.size() > 4)
|
||||
{
|
||||
span[0] = u't';
|
||||
span[1] = u'm';
|
||||
span[2] = u'p';
|
||||
@@ -136,7 +136,8 @@ cu32zstring_span<> CreateTempNameU32(u32string_span<> span)
|
||||
Expects(span.size() > 1);
|
||||
|
||||
std::size_t last = 0;
|
||||
if (span.size() > 4) {
|
||||
if (span.size() > 4)
|
||||
{
|
||||
span[0] = U't';
|
||||
span[1] = U'm';
|
||||
span[2] = U'p';
|
||||
@@ -950,10 +951,11 @@ TEST(string_span_tests, Conversion)
|
||||
|
||||
TEST(string_span_tests, zstring)
|
||||
{
|
||||
std::set_terminate([] {
|
||||
const auto terminateHandler = std::set_terminate([] {
|
||||
std::cerr << "Expected Death. zstring";
|
||||
std::abort();
|
||||
});
|
||||
const auto expected = GetExpectedDeathString(terminateHandler);
|
||||
|
||||
// create zspan from zero terminated string
|
||||
{
|
||||
@@ -973,7 +975,7 @@ TEST(string_span_tests, zstring)
|
||||
buf[0] = 'a';
|
||||
|
||||
auto workaround_macro = [&]() { const zstring_span<> zspan({buf, 1}); };
|
||||
EXPECT_DEATH(workaround_macro(), deathstring);
|
||||
EXPECT_DEATH(workaround_macro(), expected);
|
||||
}
|
||||
|
||||
// usage scenario: create zero-terminated temp file name and pass to a legacy API
|
||||
@@ -981,7 +983,8 @@ TEST(string_span_tests, zstring)
|
||||
char buf[10];
|
||||
|
||||
auto name = CreateTempName({buf, 10});
|
||||
if (!name.empty()) {
|
||||
if (!name.empty())
|
||||
{
|
||||
czstring<> str = name.assume_z();
|
||||
EXPECT_TRUE(generic::strlen(str) == 3);
|
||||
EXPECT_TRUE(*(str + 3) == '\0');
|
||||
@@ -991,10 +994,11 @@ TEST(string_span_tests, zstring)
|
||||
|
||||
TEST(string_span_tests, wzstring)
|
||||
{
|
||||
std::set_terminate([] {
|
||||
const auto terminateHandler = std::set_terminate([] {
|
||||
std::cerr << "Expected Death. wzstring";
|
||||
std::abort();
|
||||
});
|
||||
const auto expected = GetExpectedDeathString(terminateHandler);
|
||||
|
||||
// create zspan from zero terminated string
|
||||
{
|
||||
@@ -1014,7 +1018,7 @@ TEST(string_span_tests, wzstring)
|
||||
buf[0] = L'a';
|
||||
|
||||
const auto workaround_macro = [&]() { const wzstring_span<> zspan({buf, 1}); };
|
||||
EXPECT_DEATH(workaround_macro(), deathstring);
|
||||
EXPECT_DEATH(workaround_macro(), expected);
|
||||
}
|
||||
|
||||
// usage scenario: create zero-terminated temp file name and pass to a legacy API
|
||||
@@ -1022,7 +1026,8 @@ TEST(string_span_tests, wzstring)
|
||||
wchar_t buf[10];
|
||||
|
||||
const auto name = CreateTempNameW({buf, 10});
|
||||
if (!name.empty()) {
|
||||
if (!name.empty())
|
||||
{
|
||||
cwzstring<> str = name.assume_z();
|
||||
EXPECT_TRUE(generic::strnlen(str, 10) == 3);
|
||||
EXPECT_TRUE(*(str + 3) == L'\0');
|
||||
@@ -1032,10 +1037,11 @@ TEST(string_span_tests, wzstring)
|
||||
|
||||
TEST(string_span_tests, u16zstring)
|
||||
{
|
||||
std::set_terminate([] {
|
||||
const auto terminateHandler = std::set_terminate([] {
|
||||
std::cerr << "Expected Death. u16zstring";
|
||||
std::abort();
|
||||
});
|
||||
const auto expected = GetExpectedDeathString(terminateHandler);
|
||||
|
||||
// create zspan from zero terminated string
|
||||
{
|
||||
@@ -1055,7 +1061,7 @@ TEST(string_span_tests, u16zstring)
|
||||
buf[0] = u'a';
|
||||
|
||||
const auto workaround_macro = [&]() { const u16zstring_span<> zspan({buf, 1}); };
|
||||
EXPECT_DEATH(workaround_macro(), deathstring);
|
||||
EXPECT_DEATH(workaround_macro(), expected);
|
||||
}
|
||||
|
||||
// usage scenario: create zero-terminated temp file name and pass to a legacy API
|
||||
@@ -1063,7 +1069,8 @@ TEST(string_span_tests, u16zstring)
|
||||
char16_t buf[10];
|
||||
|
||||
const auto name = CreateTempNameU16({buf, 10});
|
||||
if (!name.empty()) {
|
||||
if (!name.empty())
|
||||
{
|
||||
cu16zstring<> str = name.assume_z();
|
||||
EXPECT_TRUE(generic::strnlen(str, 10) == 3);
|
||||
EXPECT_TRUE(*(str + 3) == L'\0');
|
||||
@@ -1073,10 +1080,11 @@ TEST(string_span_tests, u16zstring)
|
||||
|
||||
TEST(string_span_tests, u32zstring)
|
||||
{
|
||||
std::set_terminate([] {
|
||||
const auto terminateHandler = std::set_terminate([] {
|
||||
std::cerr << "Expected Death. u31zstring";
|
||||
std::abort();
|
||||
});
|
||||
const auto expected = GetExpectedDeathString(terminateHandler);
|
||||
|
||||
// create zspan from zero terminated string
|
||||
{
|
||||
@@ -1096,7 +1104,7 @@ TEST(string_span_tests, u32zstring)
|
||||
buf[0] = u'a';
|
||||
|
||||
const auto workaround_macro = [&]() { const u32zstring_span<> zspan({buf, 1}); };
|
||||
EXPECT_DEATH(workaround_macro(), deathstring);
|
||||
EXPECT_DEATH(workaround_macro(), expected);
|
||||
}
|
||||
|
||||
// usage scenario: create zero-terminated temp file name and pass to a legacy API
|
||||
@@ -1104,7 +1112,8 @@ TEST(string_span_tests, u32zstring)
|
||||
char32_t buf[10];
|
||||
|
||||
const auto name = CreateTempNameU32({buf, 10});
|
||||
if (!name.empty()) {
|
||||
if (!name.empty())
|
||||
{
|
||||
cu32zstring<> str = name.assume_z();
|
||||
EXPECT_TRUE(generic::strnlen(str, 10) == 3);
|
||||
EXPECT_TRUE(*(str + 3) == L'\0');
|
||||
|
||||
Reference in New Issue
Block a user