winget-cli

Unnamed repository; edit this file 'description' to name the repository.
Log | Files | Refs | README | LICENSE

SFSExceptionMatcher.cpp (1961B)


      1 // Copyright (c) Microsoft Corporation.
      2 // Licensed under the MIT License.
      3 
      4 #include "SFSExceptionMatcher.h"
      5 
      6 #include <catch2/matchers/catch_matchers_string.hpp>
      7 
      8 using namespace SFS;
      9 using namespace SFS::details;
     10 using namespace SFS::test;
     11 
     12 SFSExceptionMatcher::SFSExceptionMatcher(const Result::Code& code) : m_code(code)
     13 {
     14 }
     15 
     16 SFSExceptionMatcher::SFSExceptionMatcher(const Result::Code& code, std::string message)
     17     : m_code(code)
     18     , m_message(std::move(message))
     19 {
     20 }
     21 
     22 bool SFSExceptionMatcher::match(const SFSException& other) const
     23 {
     24     if (m_message)
     25     {
     26         return other.GetResult() == m_code && other.what() == m_message;
     27     }
     28     return other.GetResult() == m_code;
     29 }
     30 
     31 std::string SFSExceptionMatcher::describe() const
     32 {
     33     return "Equals: " + std::string(ToString(m_code)) + (m_message ? " with message: " + *m_message : "");
     34 }
     35 
     36 template <typename Matcher>
     37 SFSExceptionGenericMatcher<Matcher>::SFSExceptionGenericMatcher(const Result::Code& code, Matcher messageMatcher)
     38     : m_code(code)
     39     , m_messageMatcher(std::move(messageMatcher))
     40 {
     41 }
     42 
     43 template <typename Matcher>
     44 bool SFSExceptionGenericMatcher<Matcher>::match(const SFSException& other) const
     45 {
     46     return other.GetResult() == m_code && m_messageMatcher.match(other.what());
     47 }
     48 
     49 template <typename Matcher>
     50 std::string SFSExceptionGenericMatcher<Matcher>::describe() const
     51 {
     52     return "Equals: " + std::string(ToString(m_code)) + m_messageMatcher.describe();
     53 }
     54 
     55 template struct SFS::test::SFSExceptionGenericMatcher<Catch::Matchers::StringEqualsMatcher>;
     56 template struct SFS::test::SFSExceptionGenericMatcher<Catch::Matchers::StringContainsMatcher>;
     57 template struct SFS::test::SFSExceptionGenericMatcher<Catch::Matchers::EndsWithMatcher>;
     58 template struct SFS::test::SFSExceptionGenericMatcher<Catch::Matchers::StartsWithMatcher>;
     59 template struct SFS::test::SFSExceptionGenericMatcher<Catch::Matchers::RegexMatcher>;