1
0
Fork 0

Nasal: test for hash creation from kw args

This commit is contained in:
James Turner 2023-01-06 12:28:58 +00:00
parent 3b36379c5c
commit 0fbe3547fb
2 changed files with 53 additions and 0 deletions

View file

@ -241,3 +241,54 @@ void NasalSysTests::testRange()
)");
CPPUNIT_ASSERT(ok);
}
void NasalSysTests::testKeywordArgInHash()
{
auto nasalSys = globals->get_subsystem<FGNasalSys>();
nasalSys->getAndClearErrorList();
bool ok = FGTestApi::executeNasal(R"(
var foo = func(arg1, kw1 = "", kw2 = nil)
{
return {'a':kw1, 'b':kw2};
}
var d = foo(arg1:42, kw2:'apples', kw1:'pears');
unitTest.assert_equal(d.a, 'pears');
unitTest.assert_equal(d.b, 'apples');
)");
CPPUNIT_ASSERT(ok);
ok = FGTestApi::executeNasal(R"(
var bar = func(h) {
return h;
}
var foo = func(arg1, kw1 = "", kw2 = nil)
{
return bar({'a':kw1, 'b':kw2});
}
var d = foo(arg1:42, kw2:'apples', kw1:'pears');
unitTest.assert_equal(d.a, 'pears');
unitTest.assert_equal(d.b, 'apples');
)");
CPPUNIT_ASSERT(ok);
ok = FGTestApi::executeNasal(R"(
var bar = func(h) {
unitTest.assert_equal(h.a, 'pears');
unitTest.assert_equal(h.b, 'apples');
}
var foo = func(arg1, kw1 = "", kw2 = nil)
{
return bar({'a':kw1, 'b':kw2});
}
var d = foo(arg1:42, kw2:'apples', kw1:'pears');
)");
CPPUNIT_ASSERT(ok);
}

View file

@ -37,6 +37,7 @@ class NasalSysTests : public CppUnit::TestFixture
CPPUNIT_TEST(testCompileLarge);
CPPUNIT_TEST(testRoundFloor);
CPPUNIT_TEST(testRange);
CPPUNIT_TEST(testKeywordArgInHash);
CPPUNIT_TEST_SUITE_END();
public:
@ -53,6 +54,7 @@ public:
void testCompileLarge();
void testRoundFloor();
void testRange();
void testKeywordArgInHash();
};
#endif // _FG_NASALSYS_UNIT_TESTS_HXX