Skip to content

Commit

Permalink
Rearrange tests.
Browse files Browse the repository at this point in the history
Remove Rust test, stock rust syntax doesn't have correct comment types.
  • Loading branch information
ehuss committed Jun 22, 2018
1 parent 015ffce commit df643ca
Show file tree
Hide file tree
Showing 8 changed files with 32 additions and 104 deletions.
70 changes: 11 additions & 59 deletions tests/test_wrap.py
Original file line number Diff line number Diff line change
@@ -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__))
Expand All @@ -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)
Expand All @@ -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):
Expand Down Expand Up @@ -111,6 +110,7 @@ def _wrap_with_scratch(self, filename, contents, expected, syntax, settings, f):
view = window.new_file()
view.set_scratch(True)
view.set_syntax_file(syntax)
print('set syntax to %r' % (syntax,))
# Update settings.
view_settings = view.settings()
bad_keys = set(settings.keys()) - set(DEFAULT_SETTINGS.keys())
Expand All @@ -129,51 +129,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')
28 changes: 16 additions & 12 deletions tests/wrap_tests/test.c
Original file line number Diff line number Diff line change
@@ -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.
//
Expand All @@ -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.
*
Expand All @@ -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.
Expand Down Expand Up @@ -75,32 +78,33 @@ 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.*/
===
/*
<START>C comment style.
Works better when wrapping within the comment.<END> */
---
/*
C comment style. Works better when wrapping within the comment.*/
===
/**<START>
===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.
<END>*/
*/
---
/**
* 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.
*/
===
/**<START>
===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.<END>
* @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.
*/
---
/**
Expand Down
1 change: 1 addition & 0 deletions tests/wrap_tests/test.md
Original file line number Diff line number Diff line change
@@ -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
Expand Down
1 change: 1 addition & 0 deletions tests/wrap_tests/test.py
Original file line number Diff line number Diff line change
@@ -1,3 +1,4 @@
Packages/Python/Python.sublime-syntax
===
def foo():
"""<START>Lorem ipsum dolor sit amet, consectetuer adipiscing elit. Aenean commodo ligula eget dolor. Aenean massa. Cum sociis natoque penatibus et
Expand Down
33 changes: 0 additions & 33 deletions tests/wrap_tests/test.rs

This file was deleted.

1 change: 1 addition & 0 deletions tests/wrap_tests/test.tex
Original file line number Diff line number Diff line change
@@ -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
---
Expand Down
1 change: 1 addition & 0 deletions tests/wrap_tests/test.txt
Original file line number Diff line number Diff line change
@@ -1,3 +1,4 @@
Packages/Text/Plain text.tmLanguage
===
This line is exactly 78 characters long and should not be change when wrapped.
---
Expand Down
1 change: 1 addition & 0 deletions tests/wrap_tests/test_tab.txt
Original file line number Diff line number Diff line change
@@ -1,3 +1,4 @@
Packages/Text/Plain text.tmLanguage
===tab_size=4
123456789 123456789 123456789 123456789 123456789 123456789 123456789 1234

Expand Down

0 comments on commit df643ca

Please sign in to comment.