Permalink
Browse files

Make fully qualified member names trigger direct results. Fix bug 766…

…122.

For some unknown reason, the % was at the front rather than at the back, where it's needed to eat the () or (params) which we jam into the qualname field along with the function name. (Type-signature overloading and all that jazz)

Also add a test for the other qualified-name direct-result case: types.
  • Loading branch information...
1 parent 40b1d91 commit 521ad0e5a12172822f8b0188025b8385a8b89295 @erikrose erikrose committed Mar 27, 2013
Showing with 40 additions and 1 deletion.
  1. +1 −1 dxr/query.py
  2. +39 −0 tests/test_direct.py
View
@@ -260,7 +260,7 @@ def direct_result(self):
(SELECT path FROM files WHERE files.id = functions.file_id) as path,
functions.file_line
FROM functions WHERE functions.qualname LIKE ? LIMIT 2
- """, ("%" + term,))
+ """, (term + '%',)) # Trailing % to eat "(int x)" etc.
rows = cur.fetchall()
if rows and len(rows) == 1:
return (rows[0]['path'], rows[0]['file_line'])
View
@@ -0,0 +1,39 @@
+import os.path
+
+from dxr.query import Query
+from dxr.server_utils import connect_db
+from dxr.testing import SingleFileTestCase, MINIMAL_MAIN
+
+from nose.tools import eq_
+
+
+class MemberFunctionTests(SingleFileTestCase):
+ source = """
+ class MemberFunction {
+ public:
+ void member_function(int a); // Don't assume the qualname
+ // field in the DB ends in just
+ // ().
+
+ class InnerClass {
+ };
+ };
+
+ void MemberFunction::member_function(int a) {
+ }
+ """ + MINIMAL_MAIN
+
+ def direct_result_eq(self, query_text, line_num):
+ conn = connect_db(
+ 'code', os.path.join(self._config_dir_path, 'target'))
+ eq_(Query(conn, query_text).direct_result(), ('main.cpp', line_num))
+
+ def test_qualified_function_name_prefix(self):
+ """A unique prefix match on fully qualified function name should take
+ you directly to the result."""
+ self.direct_result_eq('MemberFunction::member_function', 12)
+
+ def test_qualified_type_name(self):
+ """A unique prefix match on fully qualified type name should take you
+ directly to the result."""
+ self.direct_result_eq('MemberFunction::InnerClass', 8)

0 comments on commit 521ad0e

Please sign in to comment.