extend testdata

This commit is contained in:
Michael Davidsaver
2021-04-18 18:45:51 -07:00
parent c09e940f45
commit d33672a859
+31 -1
View File
@@ -309,11 +309,40 @@ void testAssignSimilar()
}
}
void testExtract()
{
testShow()<<__func__;
auto top = nt::NTScalar{TypeCode::Int32}.create();
top["value"] = 42;
testEq(top["value"].as<int32_t>(), 42);
{
int32_t val = -1;
testTrue(top["value"].as(val));
testEq(val, 42);
}
{
std::string val("canary");
testTrue(top["value"].as(val));
testEq(val, "42");
}
{
bool ran = false;
top["value"].as<int32_t>([&ran](const int32_t& v) {
testEq(v, 42);
ran = true;
});
testTrue(ran);
}
}
} // namespace
MAIN(testdata)
{
testPlan(108);
testPlan(115);
testSetup();
testTraverse();
testAssign();
@@ -356,6 +385,7 @@ MAIN(testdata)
testConvertScalar2<int32_t, uint64_t, int64_t>(0, 0x100000000llu, -0);
testAssignSimilar();
testExtract();
cleanup_for_valgrind();
return testDone();
}