@@ -34,6 +34,7 @@ class TestLibrary : public TestFixture {
3434 TEST_CASE (function);
3535 TEST_CASE (function_match_scope);
3636 TEST_CASE (function_match_args);
37+ TEST_CASE (function_match_args_default);
3738 TEST_CASE (function_match_var);
3839 TEST_CASE (function_arg);
3940 TEST_CASE (function_arg_any);
@@ -126,13 +127,64 @@ class TestLibrary : public TestFixture {
126127 TokenList tokenList (nullptr );
127128 std::istringstream istr (" foo();" ); // <- too few arguments, not library function
128129 tokenList.createTokens (istr);
129- tokenList.front ()->next ()->astOperand1 (tokenList.front ());
130+ Token::createMutualLinks (tokenList.front ()->next (), tokenList.back ()->previous ());
131+ tokenList.createAst ();
130132
131133 Library library;
132134 readLibrary (library, xmldata);
133135 ASSERT (library.isNotLibraryFunction (tokenList.front ()));
134136 }
135137
138+ void function_match_args_default () const {
139+ const char xmldata[] = " <?xml version=\" 1.0\" ?>\n "
140+ " <def>\n "
141+ " <function name=\" foo\" >\n "
142+ " <arg nr=\" 1\" />"
143+ " <arg nr=\" 2\" default=\" 0\" />"
144+ " </function>\n "
145+ " </def>" ;
146+
147+ Library library;
148+ readLibrary (library, xmldata);
149+
150+ {
151+ TokenList tokenList (nullptr );
152+ std::istringstream istr (" foo();" ); // <- too few arguments, not library function
153+ tokenList.createTokens (istr);
154+ Token::createMutualLinks (tokenList.front ()->next (), tokenList.back ()->previous ());
155+ tokenList.createAst ();
156+
157+ ASSERT (library.isNotLibraryFunction (tokenList.front ()));
158+ }
159+ {
160+ TokenList tokenList (nullptr );
161+ std::istringstream istr (" foo(a);" ); // <- library function
162+ tokenList.createTokens (istr);
163+ Token::createMutualLinks (tokenList.front ()->next (), tokenList.back ()->previous ());
164+ tokenList.createAst ();
165+
166+ ASSERT (!library.isNotLibraryFunction (tokenList.front ()));
167+ }
168+ {
169+ TokenList tokenList (nullptr );
170+ std::istringstream istr (" foo(a, b);" ); // <- library function
171+ tokenList.createTokens (istr);
172+ Token::createMutualLinks (tokenList.front ()->next (), tokenList.back ()->previous ());
173+ tokenList.createAst ();
174+
175+ ASSERT (!library.isNotLibraryFunction (tokenList.front ()));
176+ }
177+ {
178+ TokenList tokenList (nullptr );
179+ std::istringstream istr (" foo(a, b, c);" ); // <- too much arguments, not library function
180+ tokenList.createTokens (istr);
181+ Token::createMutualLinks (tokenList.front ()->next (), tokenList.back ()->previous ());
182+ tokenList.createAst ();
183+
184+ ASSERT (library.isNotLibraryFunction (tokenList.front ()));
185+ }
186+ }
187+
136188 void function_match_var () const {
137189 const char xmldata[] = " <?xml version=\" 1.0\" ?>\n "
138190 " <def>\n "
@@ -160,7 +212,7 @@ class TestLibrary : public TestFixture {
160212 " <arg nr=\" 2\" ><not-null/></arg>\n "
161213 " <arg nr=\" 3\" ><formatstr/></arg>\n "
162214 " <arg nr=\" 4\" ><strz/></arg>\n "
163- " <arg nr=\" 5\" ><not-bool/></arg>\n "
215+ " <arg nr=\" 5\" default= \" 0 \" ><not-bool/></arg>\n "
164216 " </function>\n "
165217 " </def>" ;
166218
@@ -170,7 +222,9 @@ class TestLibrary : public TestFixture {
170222 ASSERT_EQUALS (true , library.argumentChecks [" foo" ][2 ].notnull );
171223 ASSERT_EQUALS (true , library.argumentChecks [" foo" ][3 ].formatstr );
172224 ASSERT_EQUALS (true , library.argumentChecks [" foo" ][4 ].strz );
225+ ASSERT_EQUALS (false , library.argumentChecks [" foo" ][4 ].optional );
173226 ASSERT_EQUALS (true , library.argumentChecks [" foo" ][5 ].notbool );
227+ ASSERT_EQUALS (true , library.argumentChecks [" foo" ][5 ].optional );
174228 }
175229
176230 void function_arg_any () const {
0 commit comments