Nasal: test for hash creation from kw args
This commit is contained in:
parent
3b36379c5c
commit
0fbe3547fb
2 changed files with 53 additions and 0 deletions
|
@ -241,3 +241,54 @@ void NasalSysTests::testRange()
|
||||||
)");
|
)");
|
||||||
CPPUNIT_ASSERT(ok);
|
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);
|
||||||
|
}
|
||||||
|
|
|
@ -37,6 +37,7 @@ class NasalSysTests : public CppUnit::TestFixture
|
||||||
CPPUNIT_TEST(testCompileLarge);
|
CPPUNIT_TEST(testCompileLarge);
|
||||||
CPPUNIT_TEST(testRoundFloor);
|
CPPUNIT_TEST(testRoundFloor);
|
||||||
CPPUNIT_TEST(testRange);
|
CPPUNIT_TEST(testRange);
|
||||||
|
CPPUNIT_TEST(testKeywordArgInHash);
|
||||||
CPPUNIT_TEST_SUITE_END();
|
CPPUNIT_TEST_SUITE_END();
|
||||||
|
|
||||||
public:
|
public:
|
||||||
|
@ -53,6 +54,7 @@ public:
|
||||||
void testCompileLarge();
|
void testCompileLarge();
|
||||||
void testRoundFloor();
|
void testRoundFloor();
|
||||||
void testRange();
|
void testRange();
|
||||||
|
void testKeywordArgInHash();
|
||||||
};
|
};
|
||||||
|
|
||||||
#endif // _FG_NASALSYS_UNIT_TESTS_HXX
|
#endif // _FG_NASALSYS_UNIT_TESTS_HXX
|
||||||
|
|
Loading…
Add table
Reference in a new issue