From 73e6d1c53af504d046dcc2f277727b71f79d380d Mon Sep 17 00:00:00 2001 From: Eric Huss Date: Fri, 22 Jun 2018 12:19:35 -0700 Subject: [PATCH] Rearrange tests. Remove Rust test, stock rust syntax doesn't have correct comment types. --- tests/test_wrap.py | 69 +++++------------------------------ tests/wrap_tests/test.c | 28 ++++++++------ tests/wrap_tests/test.md | 1 + tests/wrap_tests/test.py | 1 + tests/wrap_tests/test.rs | 33 ----------------- tests/wrap_tests/test.tex | 1 + tests/wrap_tests/test.txt | 1 + tests/wrap_tests/test_tab.txt | 1 + 8 files changed, 31 insertions(+), 104 deletions(-) delete mode 100644 tests/wrap_tests/test.rs diff --git a/tests/test_wrap.py b/tests/test_wrap.py index 245c2ce..1cda4a2 100644 --- a/tests/test_wrap.py +++ b/tests/test_wrap.py @@ -1,9 +1,6 @@ import os -import queue import re import sublime -import threading -import time import unittest plugin_path = os.path.dirname(os.path.dirname(__file__)) @@ -30,14 +27,17 @@ class TestWrap(unittest.TestCase): def test_wrap(self): base = os.path.join(plugin_path, 'tests', 'wrap_tests') to_test = os.listdir(base) - for path in to_test: - # Open the file with Sublime (mainly to just get the correct - # syntax file). - self._with_open_file(os.path.join(base, path), self._test_wrap) + for filename in to_test: + abspath = os.path.join(base, filename) + contents = open(abspath, encoding='utf8').read() + contents = contents.replace('\r\n', '\n') + i = contents.find('\n') + syntax = contents[:i] + contents = contents[i + 1:] + assert contents.startswith('==='), 'bad file %r' % (filename,) + self._test_wrap(filename, contents, syntax) - def _test_wrap(self, view): - contents = view.substr(sublime.Region(0, view.size())) - syntax = view.settings().get('syntax') + def _test_wrap(self, filename, contents, syntax): # Split test file into separate tests. starts = re.finditer(r'^===((?:[A-Za-z0-9._-]+=[^,\n]+,?)+)?$', contents, flags=re.MULTILINE) @@ -59,7 +59,6 @@ def _test_wrap(self, view): key, value = setting.split('=') settings[key] = eval(value) # Open a new view to run the test in. - filename = os.path.basename(view.file_name()) self._wrap_with_scratch(filename, orig, expected, syntax, settings, self._test_wrap_individual) if not settings.get('WrapPlus.skip_range', False): @@ -129,51 +128,3 @@ def _wrap_with_scratch(self, filename, contents, expected, syntax, settings, f): filename, settings, actual, expected)) window.focus_view(view) window.run_command('close_file') - - def _with_open_file(self, filename, f, **kwargs): - """Opens filename (relative to the plugin) in a new view, calls - f(view) to perform the tests. - """ - window = sublime.active_window() - path = os.path.join(plugin_path, filename) - if not os.path.exists(path): - # Unfortunately there doesn't seem to be a good way to detect a - # failure to load. - raise ValueError('Can\'t find path %r' % path) - view = window.find_open_file(path) - if view: - window.focus_view(view) - f(view, **kwargs) - return - view = window.open_file(path) - q = queue.Queue() - - def async_test_view(): - try: - # Wait for view to finish loading. - for n in range(500): - if view.is_loading(): - time.sleep(0.01) - else: - break - else: - raise AssertionError('View never loaded.') - f(view, **kwargs) - except Exception as e: - q.put(e) - else: - q.put(None) - - try: - t = threading.Thread(target=async_test_view) - t.start() - t.join() - msg = q.get() - if msg: - raise msg - finally: - if view.window(): - window.focus_view(view) - if view.is_dirty(): - view.run_command('revert') - window.run_command('close_file') diff --git a/tests/wrap_tests/test.c b/tests/wrap_tests/test.c index 7e451d4..163d8e8 100644 --- a/tests/wrap_tests/test.c +++ b/tests/wrap_tests/test.c @@ -1,3 +1,4 @@ +Packages/C++/C.sublime-syntax === // Lorem ipsum dolor sit amet, consectetuer adipiscing elit. Aenean commodo ligula eget dolor. Aenean massa. Cum sociis natoque penatibus et magnis dis parturient montes, nascetur ridiculus mus. Donec quam felis, ultricies nec, pellentesque eu, pretium quis, sem. Nulla. // @@ -11,8 +12,9 @@ // - Gummies tart bonbon muffin. Jelly chupa chups jelly-o tart dessert // soufflé tiramisu. Apple pie pudding wafer. Sugar plum ice cream sesame // snaps tootsie roll. -=== +===WrapPlus.skip_range=True /* + * skip_range is needed for stock C syntax. It works with C improved. * Jelly beans wafer topping sweet brownie. Croissant dragée cake sugar plum tootsie roll. * Icing croissant cotton candy croissant cotton candy pie. * @@ -21,8 +23,9 @@ */ --- /* - * Jelly beans wafer topping sweet brownie. Croissant dragée cake sugar plum - * tootsie roll. Icing croissant cotton candy croissant cotton candy pie. + * skip_range is needed for stock C syntax. It works with C improved. Jelly + * beans wafer topping sweet brownie. Croissant dragée cake sugar plum tootsie + * roll. Icing croissant cotton candy croissant cotton candy pie. * * * Bullet list. Topping muffin cupcake cotton candy soufflé cake pie. * Topping jelly jelly-o. @@ -75,10 +78,11 @@ just writing stuff. */ === /* C comment style. -This probably shouldn't wrap with the opening tag, but it does. */ +This probably shouldn't wrap with the opening tag, but it does in the C improved syntax. */ --- -/* C comment style. This probably shouldn't wrap with the opening tag, but it -does. */ +/* +C comment style. This probably shouldn't wrap with the opening tag, but it +does in the C improved syntax.*/ === /* C comment style. @@ -86,21 +90,21 @@ Works better when wrapping within the comment. */ --- /* C comment style. Works better when wrapping within the comment.*/ -=== -/** +===WrapPlus.skip_range=True +/** * Comment with two stars. Cupcake ipsum dolor sit amet marzipan faworki. Wafer I love croissant. Tart carrot cake pastry applicake lollipop I love cotton brownie. - */ + */ --- /** * Comment with two stars. Cupcake ipsum dolor sit amet marzipan faworki. * Wafer I love croissant. Tart carrot cake pastry applicake lollipop I love * cotton brownie. */ -=== -/** +===WrapPlus.skip_range=True +/** * Sample function description. Just in case the description is very long. Cupcake ipsum dolor sit amet marzipan faworki. Wafer I love croissant. Tart * carrot cake pastry applicake lollipop I love cotton brownie. - * @param {string} paramname Multi-line parameter description (or any javadoc tag) should indent with 4 spaces. Cupcake ipsum dolor sit amet marzipan faworki. Wafer I love croissant. Tart carrot cake pastry applicake lollipop I love cotton brownie. + * @param {string} paramname Multi-line parameter description (or any javadoc tag) should indent with 4 spaces. Cupcake ipsum dolor sit amet marzipan faworki. Wafer I love croissant. Tart carrot cake pastry applicake lollipop I love cotton brownie. */ --- /** diff --git a/tests/wrap_tests/test.md b/tests/wrap_tests/test.md index 3bc93ad..1df07f2 100644 --- a/tests/wrap_tests/test.md +++ b/tests/wrap_tests/test.md @@ -1,3 +1,4 @@ +Packages/Markdown/Markdown.sublime-syntax === Lorem ipsum dolor sit amet, consectetuer adipiscing elit. Aenean commodo ligula eget dolor. Aenean massa. # Header diff --git a/tests/wrap_tests/test.py b/tests/wrap_tests/test.py index 8e5fcfd..36ab49b 100644 --- a/tests/wrap_tests/test.py +++ b/tests/wrap_tests/test.py @@ -1,3 +1,4 @@ +Packages/Python/Python.sublime-syntax === def foo(): """Lorem ipsum dolor sit amet, consectetuer adipiscing elit. Aenean commodo ligula eget dolor. Aenean massa. Cum sociis natoque penatibus et diff --git a/tests/wrap_tests/test.rs b/tests/wrap_tests/test.rs deleted file mode 100644 index 1e67781..0000000 --- a/tests/wrap_tests/test.rs +++ /dev/null @@ -1,33 +0,0 @@ -=== -/// Now it's beginning to make a little sense. Just take out whatever you don't want. It'll change your entire perspective. -/// -/// I'm a water fanatic. I love water. Be careful. You can always add more - but you can't take it away. ---- -/// Now it's beginning to make a little sense. Just take out whatever you -/// don't want. It'll change your entire perspective. -/// -/// I'm a water fanatic. I love water. Be careful. You can always add more - -/// but you can't take it away. -=== -//! Another comment type. -//! You create the dream - then you bring it into your world. Let's get wild today. A tree cannot be straight if it has a crooked trunk. -//! - asdf ---- -//! Another comment type. You create the dream - then you bring it into your -//! world. Let's get wild today. A tree cannot be straight if it has a crooked -//! trunk. -//! - asdf -=== -// This present moment is perfect simply due to the fact you're experiencing it. Trees grow however makes them happy. There it is. ---- -// This present moment is perfect simply due to the fact you're experiencing -// it. Trees grow however makes them happy. There it is. -=== -/* -Let's get crazy. You have to make those little noises or it won't work. Have fun with it. -*/ ---- -/* -Let's get crazy. You have to make those little noises or it won't work. Have -fun with it. -*/ diff --git a/tests/wrap_tests/test.tex b/tests/wrap_tests/test.tex index d7a6b87..b730274 100644 --- a/tests/wrap_tests/test.tex +++ b/tests/wrap_tests/test.tex @@ -1,3 +1,4 @@ +Packages/LaTeX/LaTeX.sublime-syntax === This is a test. This is a test. This is a test. This is a test. % This is a comment --- diff --git a/tests/wrap_tests/test.txt b/tests/wrap_tests/test.txt index 3aab5c7..1c46cdd 100644 --- a/tests/wrap_tests/test.txt +++ b/tests/wrap_tests/test.txt @@ -1,3 +1,4 @@ +Packages/Text/Plain text.tmLanguage === This line is exactly 78 characters long and should not be change when wrapped. --- diff --git a/tests/wrap_tests/test_tab.txt b/tests/wrap_tests/test_tab.txt index 432220b..99cb255 100644 --- a/tests/wrap_tests/test_tab.txt +++ b/tests/wrap_tests/test_tab.txt @@ -1,3 +1,4 @@ +Packages/Text/Plain text.tmLanguage ===tab_size=4 123456789 123456789 123456789 123456789 123456789 123456789 123456789 1234