def co_routine(self, view): tag_file = find_tags_relative_to(view) with open(tag_file) as tf: tags = parse_tag_lines(tf, tag_class=Tag) print 'Starting Test' ex_failures = [] line_failures = [] for symbol, tag_list in tags.items(): for tag in tag_list: tag.root_dir = dirname(tag_file) def hook(av): test_context = av.sel()[0] if tag.ex_command.isdigit(): test_string = tag.symbol else: test_string = tag.ex_command test_context = av.line(test_context) if not ((av.substr(test_context) == test_string) #): or av.substr(test_context).startswith(test_string)): failure = 'FAILURE %s' % pprint.pformat(tag) failure += av.file_name() if setting('debug') and not sublime.question_box( '%s\n\n\n' % failure): self.routine = None return sublime.set_clipboard(failure) ex_failures.append(tag) sublime.set_timeout(self.next, 5) scroll_to_tag(view, tag, hook) yield failures = line_failures + ex_failures tags_tested = sum(len(v) for v in tags.values()) - len(failures) view = sublime.active_window().new_file() edit = view.begin_edit() view.insert(edit, view.size(), '%s Tags Tested OK\n' % tags_tested) view.insert(edit, view.size(), '%s Tags Failed' % len(failures)) view.end_edit(edit) view.set_scratch(True) view.set_name('CTags Test Results') if failures: sublime.set_clipboard(pprint.pformat(failures)) ################################################################################
def co_routine(self, view): tag_file = find_tags_relative_to(view) with open(tag_file) as tf: tags = parse_tag_lines(tf, tag_class=Tag) print 'Starting Test' ex_failures = [] line_failures = [] for symbol, tag_list in tags.items(): for tag in tag_list: tag.root_dir = dirname(tag_file) def hook(av): test_context = av.sel()[0] if tag.ex_command.isdigit(): test_string = tag.symbol else: test_string = tag.ex_command test_context = av.line(test_context) if not ((av.substr(test_context) == test_string) #): or av.substr(test_context).startswith(test_string) ): failure = 'FAILURE %s' % pprint.pformat(tag) failure += av.file_name() if setting('debug') and not sublime.question_box('%s\n\n\n' % failure): self.routine = None return sublime.set_clipboard(failure) ex_failures.append(tag) sublime.set_timeout( self.next, 5 ) scroll_to_tag(view, tag, hook) yield failures = line_failures + ex_failures tags_tested = sum(len(v) for v in tags.values()) - len(failures) view = sublime.active_window().new_file() edit = view.begin_edit() view.insert(edit, view.size(), '%s Tags Tested OK\n' % tags_tested) view.insert(edit, view.size(), '%s Tags Failed' % len(failures)) view.end_edit(edit) view.set_scratch(True) view.set_name('CTags Test Results') if failures: sublime.set_clipboard(pprint.pformat(failures)) ################################################################################
def test_parse_tag_lines__c(self): """ Test ``parse_tag_lines`` with a sample C file. """ path = self.build_c_file() tag_file = ctags.build_ctags(path=path) with codecs.open(tag_file, encoding='utf-8') as output: try: content = output.readlines() filename = os.path.basename(path) except IOError: self.fail("Setup of files for test failed") finally: output.close() os.remove(path) # clean up os.remove(tag_file) expected_outputs = { 'bar': [{ 'symbol': 'bar', 'filename': filename, 'ex_command': 'void bar()', 'tag_path': (filename, 'bar'), 'type': 'f', 'fields': None }], 'foo': [{ 'symbol': 'foo', 'filename': filename, 'ex_command': '1', 'tag_path': (filename, 'foo'), 'type': 'd', 'fields': 'file:', 'field_keys': ['file'], 'file': '' }], 'foobar': [{ 'symbol': 'foobar', 'filename': filename, 'ex_command': '2', 'tag_path': (filename, 'foobar'), 'type': 'd', 'fields': 'file:', 'field_keys': ['file'], 'file': '' }] } result = ctags.parse_tag_lines(content) for key in expected_outputs: self.assertEqual(result[key], expected_outputs[key]) for key in result: # don't forget - we might have missed something! self.assertEqual(expected_outputs[key], result[key])
def test_parse_tag_lines__c(self): """ Test ``parse_tag_lines`` with a sample C file. """ path = self.build_c_file() tag_file = ctags.build_ctags(path=path) with codecs.open(tag_file, encoding='utf-8') as output: try: content = output.readlines() filename = os.path.basename(path) except IOError: self.fail("Setup of files for test failed") finally: output.close() os.remove(path) # clean up os.remove(tag_file) expected_outputs = { 'bar': [{ 'symbol': 'bar', 'filename': filename, 'ex_command': 'void bar()', 'tag_path': (filename, 'bar'), 'type': 'f', 'fields': None}], 'foo': [{ 'symbol': 'foo', 'filename': filename, 'ex_command': '1', 'tag_path': (filename, 'foo'), 'type': 'd', 'fields': 'file:', 'field_keys': ['file'], 'file': ''}], 'foobar': [{ 'symbol': 'foobar', 'filename': filename, 'ex_command': '2', 'tag_path': (filename, 'foobar'), 'type': 'd', 'fields': 'file:', 'field_keys': ['file'], 'file': ''}] } result = ctags.parse_tag_lines(content) for key in expected_outputs: self.assertEqual(result[key], expected_outputs[key]) for key in result: # don't forget - we might have missed something! self.assertEqual(expected_outputs[key], result[key])
def co_routine(self, view): tag_file = find_tags_relative_to(view.file_name(), setting('tag_file')) with codecs.open(tag_file, encoding='utf-8') as tf: tags = parse_tag_lines(tf, tag_class=TagElements) print('Starting Test') ex_failures = [] line_failures = [] for symbol, tag_list in list(tags.items()): for tag in tag_list: tag.root_dir = os.path.dirname(tag_file) def hook(av): test_context = av.sel()[0] if tag.ex_command.isdigit(): test_string = tag.symbol else: test_string = tag.ex_command test_context = av.line(test_context) if not av.substr(test_context).startswith(test_string): failure = 'FAILURE %s' % pprint.pformat(tag) failure += av.file_name() if setting('debug'): if not sublime.question_box('%s\n\n\n' % failure): self.routine = None return sublime.set_clipboard(failure) ex_failures.append(tag) sublime.set_timeout(self.__next__, 5) scroll_to_tag(view, tag, hook) yield failures = line_failures + ex_failures tags_tested = sum(len(v) for v in list(tags.values())) - len(failures) view = sublime.active_window().new_file() with Edit(view) as edit: edit.insert(view.size(), '%s Tags Tested OK\n' % tags_tested) edit.insert(view.size(), '%s Tags Failed' % len(failures)) view.set_scratch(True) view.set_name('CTags Test Results') if failures: sublime.set_clipboard(pprint.pformat(failures))
def co_routine(self, view): tag_file = find_tags_relative_to( view.file_name(), setting('tag_file')) with codecs.open(tag_file, encoding='utf-8') as tf: tags = parse_tag_lines(tf, tag_class=TagElements) print('Starting Test') ex_failures = [] line_failures = [] for symbol, tag_list in list(tags.items()): for tag in tag_list: tag.root_dir = os.path.dirname(tag_file) def hook(av): test_context = av.sel()[0] if tag.ex_command.isdigit(): test_string = tag.symbol else: test_string = tag.ex_command test_context = av.line(test_context) if not av.substr(test_context).startswith(test_string): failure = 'FAILURE %s' % pprint.pformat(tag) failure += av.file_name() if setting('debug'): if not sublime.question_box('%s\n\n\n' % failure): self.routine = None return sublime.set_clipboard(failure) ex_failures.append(tag) sublime.set_timeout(self.__next__, 5) scroll_to_tag(view, tag, hook) yield failures = line_failures + ex_failures tags_tested = sum(len(v) for v in list(tags.values())) - len(failures) view = sublime.active_window().new_file() with Edit(view) as edit: edit.insert(view.size(), '%s Tags Tested OK\n' % tags_tested) edit.insert(view.size(), '%s Tags Failed' % len(failures)) view.set_scratch(True) view.set_name('CTags Test Results') if failures: sublime.set_clipboard(pprint.pformat(failures))
def run(self, view, args, tags_file, tags): if not tags_file: return multi = args.get('type') =='multi' files = files_to_search(view, tags_file, multi) if not files: return tags_file = tags_file + '_sorted_by_file' if not multi: tags = (TagFile(tags_file, FILENAME) .get_tags_dict(*files, filters=compile_filters(view))) else: with open(tags_file, 'r+') as tf: lines = [] for l in tf: try: dl = l.decode('utf8') fields = dl.split('\t') if len(fields) >= 4 and fields[-1].strip() in ('v', 'i', 'p'): continue lines.append(l) except (UnicodeDecodeError, UnicodeEncodeError): continue tag_class = type('Tag', (Tag,), dict(root_dir = dirname(tags_file))) # start = time.time() tags = parse_tag_lines(lines, tag_class=tag_class, filters=compile_filters(view)) # print 'took %.4f seconds' % (time.time() - start) if not tags: if multi: view.run_command('show_symbols', {'type':'multi'}) else: sublime.status_message( 'No symbols found **FOR CURRENT FILE**; Try Rebuild?' ) # path_cols = (0, ) if len(files) > 1 else () path_cols = multi formatting = functools.partial( format_tag_for_quickopen, file = bool(path_cols) ) @prepared_4_quickpanel(formatting, path_cols=()) def sorted_tags(): return sorted ( chain.from_iterable(tags.itervalues()), key=iget('tag_path')) return sorted_tags
def test_parse_tag_lines__python(self): """Test ``parse_tag_lines`` with a sample Python file""" path = self.build_python_file__extended() tag_file = ctags.build_ctags(path=path, opts=['--python-kinds=-i']) with codecs.open(tag_file, encoding='utf-8') as output: try: content = output.readlines() filename = os.path.basename(path) except: self.fail("Setup of files for test failed") finally: output.close() os.remove(path) # clean up os.remove(tag_file) expected_outputs = { 'MyClass': [{ 'symbol': 'MyClass', 'filename': filename, 'ex_command': 'class MyClass(object):', 'tag_path': (filename, 'MyClass'), 'type': 'c', 'fields': None}], 'address': [{ 'symbol': 'address', 'filename': filename, 'ex_command': '\taddress = None\t# comment preceded by a tab', 'tag_path': (filename, 'MyClass', 'address'), 'type': 'v', 'fields': 'class:MyClass', 'field_keys': ['class'], 'class': 'MyClass'}], 'last_name': [{ 'symbol': 'last_name', 'filename': filename, 'ex_command': '\tlast_name = None', 'tag_path': (filename, 'MyClass', 'last_name'), 'type': 'v', 'fields': 'class:MyClass', 'field_keys': ['class'], 'class': 'MyClass'}], 'my_function': [{ 'symbol': 'my_function', 'filename': filename, 'ex_command': 'def my_function(first_name):', 'tag_path': (filename, 'my_function'), 'type': 'f', 'fields': None}], 'my_method': [{ 'symbol': 'my_method', 'filename': filename, 'ex_command': '\tdef my_method(self, last_name):', 'tag_path': (filename, 'MyClass', 'my_method'), 'type': 'm', 'fields': 'class:MyClass', 'field_keys': ['class'], 'class': 'MyClass'}], 'COLOR_RED': [{ 'symbol': 'COLOR_RED', 'filename': filename, 'ex_command': 'COLOR_RED = "\\c800080FF;"\t#red', 'tag_path': (filename, 'COLOR_RED'), 'type': 'v', 'fields': None}], } result = ctags.parse_tag_lines(content) for key in expected_outputs: self.assertEqual(result[key], expected_outputs[key]) for key in result: # don't forget - we might have missed something! self.assertEqual(expected_outputs[key], result[key])
def test_parse_tag_lines__python(self): """Test ``parse_tag_lines`` with a sample Python file""" path = self.build_python_file__extended() tag_file = ctags.build_ctags(path=path, opts=['--python-kinds=-i']) with codecs.open(tag_file, encoding='utf-8') as output: try: content = output.readlines() filename = os.path.basename(path) except: self.fail("Setup of files for test failed") finally: output.close() os.remove(path) # clean up os.remove(tag_file) expected_outputs = { 'MyClass': [{ 'symbol': 'MyClass', 'filename': filename, 'ex_command': 'class MyClass(object):', 'tag_path': (filename, 'MyClass'), 'type': 'c', 'fields': None }], 'address': [{ 'symbol': 'address', 'filename': filename, 'ex_command': '\taddress = None\t# comment preceded by a tab', 'tag_path': (filename, 'MyClass', 'address'), 'type': 'v', 'fields': 'class:MyClass', 'field_keys': ['class'], 'class': 'MyClass' }], 'last_name': [{ 'symbol': 'last_name', 'filename': filename, 'ex_command': '\tlast_name = None', 'tag_path': (filename, 'MyClass', 'last_name'), 'type': 'v', 'fields': 'class:MyClass', 'field_keys': ['class'], 'class': 'MyClass' }], 'my_function': [{ 'symbol': 'my_function', 'filename': filename, 'ex_command': 'def my_function(first_name):', 'tag_path': (filename, 'my_function'), 'type': 'f', 'fields': None }], 'my_method': [{ 'symbol': 'my_method', 'filename': filename, 'ex_command': '\tdef my_method(self, last_name):', 'tag_path': (filename, 'MyClass', 'my_method'), 'type': 'm', 'fields': 'class:MyClass', 'field_keys': ['class'], 'class': 'MyClass' }], 'COLOR_RED': [{ 'symbol': 'COLOR_RED', 'filename': filename, 'ex_command': 'COLOR_RED = "\\c800080FF;"\t#red', 'tag_path': (filename, 'COLOR_RED'), 'type': 'v', 'fields': None }], } result = ctags.parse_tag_lines(content) for key in expected_outputs: self.assertEqual(result[key], expected_outputs[key]) for key in result: # don't forget - we might have missed something! self.assertEqual(expected_outputs[key], result[key])