mirror of
https://github.com/ToruNiina/toml11.git
synced 2025-09-17 17:58:09 +08:00
ci: add a patch to avoid nan comparison
This commit is contained in:
@@ -21,6 +21,30 @@ int main(int argc, char **argv)
|
|||||||
const auto serialized = toml::parse("tmp.toml");
|
const auto serialized = toml::parse("tmp.toml");
|
||||||
|
|
||||||
if(data != serialized)
|
if(data != serialized)
|
||||||
|
{
|
||||||
|
// this is really a ditry hack, but is the easiest way...
|
||||||
|
// TODO: cleanup by adding comparison function to check if a value is NaN or not
|
||||||
|
if(filename.substr(filename.size() - 22, 22) == "float-inf-and-nan.toml" &&
|
||||||
|
std::isnan (toml::find<double>(serialized, "nan")) &&
|
||||||
|
!std::signbit (toml::find<double>(serialized, "nan")) &&
|
||||||
|
std::isnan (toml::find<double>(serialized, "nan_plus")) &&
|
||||||
|
!std::signbit (toml::find<double>(serialized, "nan_plus")) &&
|
||||||
|
std::isnan (toml::find<double>(serialized, "nan_neg")) &&
|
||||||
|
std::signbit (toml::find<double>(serialized, "nan_neg")) &&
|
||||||
|
!std::isnan (toml::find<double>(serialized, "infinity")) &&
|
||||||
|
!std::isfinite(toml::find<double>(serialized, "infinity")) &&
|
||||||
|
!std::signbit (toml::find<double>(serialized, "infinity")) &&
|
||||||
|
!std::isnan (toml::find<double>(serialized, "infinity_plus")) &&
|
||||||
|
!std::isfinite(toml::find<double>(serialized, "infinity_plus")) &&
|
||||||
|
!std::signbit (toml::find<double>(serialized, "infinity_plus")) &&
|
||||||
|
!std::isnan (toml::find<double>(serialized, "infinity_neg")) &&
|
||||||
|
!std::isfinite(toml::find<double>(serialized, "infinity_neg")) &&
|
||||||
|
std::signbit (toml::find<double>(serialized, "infinity_neg")))
|
||||||
|
{
|
||||||
|
// then it is correctly serialized.
|
||||||
|
// Note that, the result of (nan == nan) is false. so `data == serialized` is false.
|
||||||
|
}
|
||||||
|
else
|
||||||
{
|
{
|
||||||
std::cerr << "============================================================\n";
|
std::cerr << "============================================================\n";
|
||||||
std::cerr << "result (w/o comment) different: " << filename << std::endl;
|
std::cerr << "result (w/o comment) different: " << filename << std::endl;
|
||||||
@@ -33,6 +57,7 @@ int main(int argc, char **argv)
|
|||||||
return 1;
|
return 1;
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
}
|
||||||
{
|
{
|
||||||
const auto data = toml::parse<toml::preserve_comments>(filename);
|
const auto data = toml::parse<toml::preserve_comments>(filename);
|
||||||
{
|
{
|
||||||
@@ -41,6 +66,36 @@ int main(int argc, char **argv)
|
|||||||
}
|
}
|
||||||
const auto serialized = toml::parse<toml::preserve_comments>("tmp.toml");
|
const auto serialized = toml::parse<toml::preserve_comments>("tmp.toml");
|
||||||
if(data != serialized)
|
if(data != serialized)
|
||||||
|
{
|
||||||
|
// this is really a ditry hack, but is the easiest way...
|
||||||
|
// TODO: cleanup by adding comparison function to check if a value is NaN or not
|
||||||
|
if(filename.substr(filename.size() - 22, 22) == "float-inf-and-nan.toml" &&
|
||||||
|
std::isnan (toml::find<double>(serialized, "nan")) &&
|
||||||
|
!std::signbit (toml::find<double>(serialized, "nan")) &&
|
||||||
|
std::isnan (toml::find<double>(serialized, "nan_plus")) &&
|
||||||
|
!std::signbit (toml::find<double>(serialized, "nan_plus")) &&
|
||||||
|
std::isnan (toml::find<double>(serialized, "nan_neg")) &&
|
||||||
|
std::signbit (toml::find<double>(serialized, "nan_neg")) &&
|
||||||
|
!std::isnan (toml::find<double>(serialized, "infinity")) &&
|
||||||
|
!std::isfinite(toml::find<double>(serialized, "infinity")) &&
|
||||||
|
!std::signbit (toml::find<double>(serialized, "infinity")) &&
|
||||||
|
!std::isnan (toml::find<double>(serialized, "infinity_plus")) &&
|
||||||
|
!std::isfinite(toml::find<double>(serialized, "infinity_plus")) &&
|
||||||
|
!std::signbit (toml::find<double>(serialized, "infinity_plus")) &&
|
||||||
|
!std::isnan (toml::find<double>(serialized, "infinity_neg")) &&
|
||||||
|
!std::isfinite(toml::find<double>(serialized, "infinity_neg")) &&
|
||||||
|
std::signbit (toml::find<double>(serialized, "infinity_neg")) &&
|
||||||
|
toml::find(data, "nan").comments() == toml::find(serialized, "nan").comments() &&
|
||||||
|
toml::find(data, "nan_plus").comments() == toml::find(serialized, "nan_plus").comments() &&
|
||||||
|
toml::find(data, "nan_neg").comments() == toml::find(serialized, "nan_neg").comments() &&
|
||||||
|
toml::find(data, "infinity").comments() == toml::find(serialized, "infinity").comments() &&
|
||||||
|
toml::find(data, "infinity_plus").comments() == toml::find(serialized, "infinity_plus").comments() &&
|
||||||
|
toml::find(data, "infinity_neg").comments() == toml::find(serialized, "infinity_neg").comments() )
|
||||||
|
{
|
||||||
|
// then it is correctly serialized.
|
||||||
|
// Note that, the result of (nan == nan) is false. so `data == serialized` is false.
|
||||||
|
}
|
||||||
|
else
|
||||||
{
|
{
|
||||||
std::cerr << "============================================================\n";
|
std::cerr << "============================================================\n";
|
||||||
std::cerr << "result (w/ comment) different: " << filename << std::endl;
|
std::cerr << "result (w/ comment) different: " << filename << std::endl;
|
||||||
@@ -53,5 +108,6 @@ int main(int argc, char **argv)
|
|||||||
return 1;
|
return 1;
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
}
|
||||||
return 0;
|
return 0;
|
||||||
}
|
}
|
||||||
|
Reference in New Issue
Block a user