forked from arduino/ArduinoCore-API
-
Notifications
You must be signed in to change notification settings - Fork 1
Expand file tree
/
Copy pathStringPrinter.h
More file actions
30 lines (27 loc) · 791 Bytes
/
StringPrinter.h
File metadata and controls
30 lines (27 loc) · 791 Bytes
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
/*
* Copyright (c) 2020 Arduino. All rights reserved.
*
* SPDX-License-Identifier: LGPL-2.1-or-later
*/
#pragma once
#include <catch2/catch_test_macros.hpp>
#include <api/String.h>
namespace Catch {
/**
* Template specialization that makes sure Catch can properly print
* Arduino Strings when used in comparisons directly.
*
* Note that without this, String objects are printed as 0 and 1,
* because they are implicitly convertible to StringIfHelperType,
* which is a dummy pointer.
*/
template<>
struct StringMaker<arduino::String> {
static std::string convert(const arduino::String& str) {
if (str)
return ::Catch::Detail::stringify(std::string(str.c_str(), str.length()));
else
return "{invalid String}";
}
};
} // namespace Catch