From d33672a85995c5b71c0a79eecf9d090425df68c5 Mon Sep 17 00:00:00 2001 From: Michael Davidsaver Date: Sun, 18 Apr 2021 18:45:51 -0700 Subject: [PATCH] extend testdata --- test/testdata.cpp | 32 +++++++++++++++++++++++++++++++- 1 file changed, 31 insertions(+), 1 deletion(-) diff --git a/test/testdata.cpp b/test/testdata.cpp index 5ba2e78..345b8d9 100644 --- a/test/testdata.cpp +++ b/test/testdata.cpp @@ -309,11 +309,40 @@ void testAssignSimilar() } } +void testExtract() +{ + testShow()<<__func__; + + auto top = nt::NTScalar{TypeCode::Int32}.create(); + + top["value"] = 42; + + testEq(top["value"].as(), 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([&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(0, 0x100000000llu, -0); testAssignSimilar(); + testExtract(); cleanup_for_valgrind(); return testDone(); }