fix issue 859
This commit is contained in:
parent
4b98aedc16
commit
776743bb6c
@ -15,6 +15,7 @@
|
||||
#include <sstream>
|
||||
#include <type_traits>
|
||||
#include <vector>
|
||||
#include <typeinfo>
|
||||
|
||||
#include "yaml-cpp/binary.h"
|
||||
#include "yaml-cpp/node/impl.h"
|
||||
@ -133,6 +134,13 @@ inner_encode(const T& rhs, std::stringstream& stream){
|
||||
const std::string& input = node.Scalar(); \
|
||||
std::stringstream stream(input); \
|
||||
stream.unsetf(std::ios::dec); \
|
||||
if ((stream.peek() == '-') && \
|
||||
(typeid(rhs) == typeid(unsigned) || \
|
||||
typeid(rhs) == typeid(unsigned short) || \
|
||||
typeid(rhs) == typeid(unsigned long) || \
|
||||
typeid(rhs) == typeid(unsigned long long))) { \
|
||||
return false; \
|
||||
} \
|
||||
if ((stream >> std::noskipws >> rhs) && (stream >> std::ws).eof()) { \
|
||||
return true; \
|
||||
} \
|
||||
|
||||
@ -32,6 +32,11 @@ TEST(LoadNodeTest, NumericConversion) {
|
||||
EXPECT_EQ(-std::numeric_limits<float>::infinity(), node[4].as<float>());
|
||||
EXPECT_EQ(21, node[5].as<int>());
|
||||
EXPECT_EQ(13, node[6].as<int>());
|
||||
// Throw error: convert signed number to unsigned number.
|
||||
EXPECT_THROW(node[7].as<unsigned>(), TypedBadConversion<unsigned int>);
|
||||
EXPECT_THROW(node[7].as<unsigned short>(), TypedBadConversion<unsigned short>);
|
||||
EXPECT_THROW(node[7].as<unsigned long>(), TypedBadConversion<unsigned long>);
|
||||
EXPECT_THROW(node[7].as<unsigned long long>(), TypedBadConversion<unsigned long long>);
|
||||
}
|
||||
|
||||
TEST(LoadNodeTest, Binary) {
|
||||
|
||||
Loading…
Reference in New Issue
Block a user