// 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 #include #include #include #include #include #include #include #include "TestPrinters.h" #include "gmock/gmock.h" namespace wpi { template class SpanMatcher : public ::testing::MatcherInterface> { public: explicit SpanMatcher(std::span good_) : good{good_.begin(), good_.end()} {} bool MatchAndExplain(std::span val, ::testing::MatchResultListener* listener) const override; void DescribeTo(::std::ostream* os) const override; void DescribeNegationTo(::std::ostream* os) const override; private: std::vector> good; }; template inline ::testing::Matcher> SpanEq(std::span good) { return ::testing::MakeMatcher(new SpanMatcher(good)); } template inline ::testing::Matcher> SpanEq( std::initializer_list good) { return ::testing::MakeMatcher( new SpanMatcher({good.begin(), good.end()})); } template bool SpanMatcher::MatchAndExplain( std::span val, ::testing::MatchResultListener* listener) const { if (val.size() != good.size() || !std::equal(val.begin(), val.end(), good.begin())) { return false; } return true; } template void SpanMatcher::DescribeTo(::std::ostream* os) const { PrintTo(std::span{good}, os); } template void SpanMatcher::DescribeNegationTo(::std::ostream* os) const { *os << "is not equal to "; PrintTo(std::span{good}, os); } } // namespace wpi inline std::span operator"" _us(const char* str, size_t len) { return {reinterpret_cast(str), len}; }