mirror of
https://github.com/wpilibsuite/allwpilib
synced 2026-06-20 00:51:42 +00:00
* Use explicit this capture required by C++20 * Use C++20 span * Replace wpi::numbers with std::numbers * Fix C++20 clang-tidy warning false positive in fmt * Remove ciso646 include since C++20 removed that header * Fix global-buffer-overflow asan warnings in ntcore tests * Add DIOSetProxy constructor to HAL * Upgrade MSVC compiler to 2022 * Bump native-utils to 2023.2.7 (changes to std=c++20) Co-authored-by: Peter Johnson <johnson.peter@gmail.com>
73 lines
2.0 KiB
C++
73 lines
2.0 KiB
C++
// Copyright (c) FIRST and other WPILib contributors.
|
|
// Open Source Software; you can modify and/or share it under the terms of
|
|
// the WPILib BSD license file in the root directory of this project.
|
|
|
|
#pragma once
|
|
|
|
#include <algorithm>
|
|
#include <initializer_list>
|
|
#include <memory>
|
|
#include <ostream>
|
|
#include <span>
|
|
#include <type_traits>
|
|
#include <utility>
|
|
#include <vector>
|
|
|
|
#include "TestPrinters.h"
|
|
#include "gmock/gmock.h"
|
|
|
|
namespace wpi {
|
|
|
|
template <typename T>
|
|
class SpanMatcher : public ::testing::MatcherInterface<std::span<T>> {
|
|
public:
|
|
explicit SpanMatcher(std::span<T> good_) : good{good_.begin(), good_.end()} {}
|
|
|
|
bool MatchAndExplain(std::span<T> val,
|
|
::testing::MatchResultListener* listener) const override;
|
|
void DescribeTo(::std::ostream* os) const override;
|
|
void DescribeNegationTo(::std::ostream* os) const override;
|
|
|
|
private:
|
|
std::vector<std::remove_cv_t<T>> good;
|
|
};
|
|
|
|
template <typename T>
|
|
inline ::testing::Matcher<std::span<const T>> SpanEq(std::span<const T> good) {
|
|
return ::testing::MakeMatcher(new SpanMatcher(good));
|
|
}
|
|
|
|
template <typename T>
|
|
inline ::testing::Matcher<std::span<const T>> SpanEq(
|
|
std::initializer_list<const T> good) {
|
|
return ::testing::MakeMatcher(
|
|
new SpanMatcher<const T>({good.begin(), good.end()}));
|
|
}
|
|
|
|
template <typename T>
|
|
bool SpanMatcher<T>::MatchAndExplain(
|
|
std::span<T> val, ::testing::MatchResultListener* listener) const {
|
|
if (val.size() != good.size() ||
|
|
!std::equal(val.begin(), val.end(), good.begin())) {
|
|
return false;
|
|
}
|
|
return true;
|
|
}
|
|
|
|
template <typename T>
|
|
void SpanMatcher<T>::DescribeTo(::std::ostream* os) const {
|
|
PrintTo(std::span<T>{good}, os);
|
|
}
|
|
|
|
template <typename T>
|
|
void SpanMatcher<T>::DescribeNegationTo(::std::ostream* os) const {
|
|
*os << "is not equal to ";
|
|
PrintTo(std::span<T>{good}, os);
|
|
}
|
|
|
|
} // namespace wpi
|
|
|
|
inline std::span<const uint8_t> operator"" _us(const char* str, size_t len) {
|
|
return {reinterpret_cast<const uint8_t*>(str), len};
|
|
}
|