Skip to content

Commit 73e6d1c

Browse files
committed
Rearrange tests.
Remove Rust test, stock rust syntax doesn't have correct comment types.
1 parent 015ffce commit 73e6d1c

File tree

8 files changed

+31
-104
lines changed

8 files changed

+31
-104
lines changed

tests/test_wrap.py

Lines changed: 10 additions & 59 deletions
Original file line numberDiff line numberDiff line change
@@ -1,9 +1,6 @@
11
import os
2-
import queue
32
import re
43
import sublime
5-
import threading
6-
import time
74
import unittest
85

96
plugin_path = os.path.dirname(os.path.dirname(__file__))
@@ -30,14 +27,17 @@ class TestWrap(unittest.TestCase):
3027
def test_wrap(self):
3128
base = os.path.join(plugin_path, 'tests', 'wrap_tests')
3229
to_test = os.listdir(base)
33-
for path in to_test:
34-
# Open the file with Sublime (mainly to just get the correct
35-
# syntax file).
36-
self._with_open_file(os.path.join(base, path), self._test_wrap)
30+
for filename in to_test:
31+
abspath = os.path.join(base, filename)
32+
contents = open(abspath, encoding='utf8').read()
33+
contents = contents.replace('\r\n', '\n')
34+
i = contents.find('\n')
35+
syntax = contents[:i]
36+
contents = contents[i + 1:]
37+
assert contents.startswith('==='), 'bad file %r' % (filename,)
38+
self._test_wrap(filename, contents, syntax)
3739

38-
def _test_wrap(self, view):
39-
contents = view.substr(sublime.Region(0, view.size()))
40-
syntax = view.settings().get('syntax')
40+
def _test_wrap(self, filename, contents, syntax):
4141
# Split test file into separate tests.
4242
starts = re.finditer(r'^===((?:[A-Za-z0-9._-]+=[^,\n]+,?)+)?$',
4343
contents, flags=re.MULTILINE)
@@ -59,7 +59,6 @@ def _test_wrap(self, view):
5959
key, value = setting.split('=')
6060
settings[key] = eval(value)
6161
# Open a new view to run the test in.
62-
filename = os.path.basename(view.file_name())
6362
self._wrap_with_scratch(filename, orig, expected, syntax, settings,
6463
self._test_wrap_individual)
6564
if not settings.get('WrapPlus.skip_range', False):
@@ -129,51 +128,3 @@ def _wrap_with_scratch(self, filename, contents, expected, syntax, settings, f):
129128
filename, settings, actual, expected))
130129
window.focus_view(view)
131130
window.run_command('close_file')
132-
133-
def _with_open_file(self, filename, f, **kwargs):
134-
"""Opens filename (relative to the plugin) in a new view, calls
135-
f(view) to perform the tests.
136-
"""
137-
window = sublime.active_window()
138-
path = os.path.join(plugin_path, filename)
139-
if not os.path.exists(path):
140-
# Unfortunately there doesn't seem to be a good way to detect a
141-
# failure to load.
142-
raise ValueError('Can\'t find path %r' % path)
143-
view = window.find_open_file(path)
144-
if view:
145-
window.focus_view(view)
146-
f(view, **kwargs)
147-
return
148-
view = window.open_file(path)
149-
q = queue.Queue()
150-
151-
def async_test_view():
152-
try:
153-
# Wait for view to finish loading.
154-
for n in range(500):
155-
if view.is_loading():
156-
time.sleep(0.01)
157-
else:
158-
break
159-
else:
160-
raise AssertionError('View never loaded.')
161-
f(view, **kwargs)
162-
except Exception as e:
163-
q.put(e)
164-
else:
165-
q.put(None)
166-
167-
try:
168-
t = threading.Thread(target=async_test_view)
169-
t.start()
170-
t.join()
171-
msg = q.get()
172-
if msg:
173-
raise msg
174-
finally:
175-
if view.window():
176-
window.focus_view(view)
177-
if view.is_dirty():
178-
view.run_command('revert')
179-
window.run_command('close_file')

tests/wrap_tests/test.c

Lines changed: 16 additions & 12 deletions
Original file line numberDiff line numberDiff line change
@@ -1,3 +1,4 @@
1+
Packages/C++/C.sublime-syntax
12
===
23
// 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.
34
//
@@ -11,8 +12,9 @@
1112
// - Gummies tart bonbon muffin. Jelly chupa chups jelly-o tart dessert
1213
// soufflé tiramisu. Apple pie pudding wafer. Sugar plum ice cream sesame
1314
// snaps tootsie roll.
14-
===
15+
===WrapPlus.skip_range=True
1516
/*
17+
* skip_range is needed for stock C syntax. It works with C improved.
1618
* Jelly beans wafer topping sweet brownie. Croissant dragée cake sugar plum tootsie roll.
1719
* Icing croissant cotton candy croissant cotton candy pie.
1820
*
@@ -21,8 +23,9 @@
2123
*/
2224
---
2325
/*
24-
* Jelly beans wafer topping sweet brownie. Croissant dragée cake sugar plum
25-
* tootsie roll. Icing croissant cotton candy croissant cotton candy pie.
26+
* skip_range is needed for stock C syntax. It works with C improved. Jelly
27+
* beans wafer topping sweet brownie. Croissant dragée cake sugar plum tootsie
28+
* roll. Icing croissant cotton candy croissant cotton candy pie.
2629
*
2730
* * Bullet list. Topping muffin cupcake cotton candy soufflé cake pie.
2831
* Topping jelly jelly-o.
@@ -75,32 +78,33 @@ just writing stuff. */
7578
===
7679
/*
7780
C comment style.
78-
This probably shouldn't wrap with the opening tag, but it does. */
81+
This probably shouldn't wrap with the opening tag, but it does in the C improved syntax. */
7982
---
80-
/* C comment style. This probably shouldn't wrap with the opening tag, but it
81-
does. */
83+
/*
84+
C comment style. This probably shouldn't wrap with the opening tag, but it
85+
does in the C improved syntax.*/
8286
===
8387
/*
8488
<START>C comment style.
8589
Works better when wrapping within the comment.<END> */
8690
---
8791
/*
8892
C comment style. Works better when wrapping within the comment.*/
89-
===
90-
/**<START>
93+
===WrapPlus.skip_range=True
94+
/**
9195
* 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.
92-
<END>*/
96+
*/
9397
---
9498
/**
9599
* Comment with two stars. Cupcake ipsum dolor sit amet marzipan faworki.
96100
* Wafer I love croissant. Tart carrot cake pastry applicake lollipop I love
97101
* cotton brownie.
98102
*/
99-
===
100-
/**<START>
103+
===WrapPlus.skip_range=True
104+
/**
101105
* Sample function description. Just in case the description is very long. Cupcake ipsum dolor sit amet marzipan faworki. Wafer I love croissant. Tart
102106
* carrot cake pastry applicake lollipop I love cotton brownie.
103-
* @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>
107+
* @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.
104108
*/
105109
---
106110
/**

tests/wrap_tests/test.md

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -1,3 +1,4 @@
1+
Packages/Markdown/Markdown.sublime-syntax
12
===
23
Lorem ipsum dolor sit amet, consectetuer adipiscing elit. Aenean commodo ligula eget dolor. Aenean massa.
34
# Header

tests/wrap_tests/test.py

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -1,3 +1,4 @@
1+
Packages/Python/Python.sublime-syntax
12
===
23
def foo():
34
"""<START>Lorem ipsum dolor sit amet, consectetuer adipiscing elit. Aenean commodo ligula eget dolor. Aenean massa. Cum sociis natoque penatibus et

tests/wrap_tests/test.rs

Lines changed: 0 additions & 33 deletions
This file was deleted.

tests/wrap_tests/test.tex

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -1,3 +1,4 @@
1+
Packages/LaTeX/LaTeX.sublime-syntax
12
===
23
This is a test. This is a test. This is a test. This is a test. % This is a comment
34
---

tests/wrap_tests/test.txt

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -1,3 +1,4 @@
1+
Packages/Text/Plain text.tmLanguage
12
===
23
This line is exactly 78 characters long and should not be change when wrapped.
34
---

tests/wrap_tests/test_tab.txt

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -1,3 +1,4 @@
1+
Packages/Text/Plain text.tmLanguage
12
===tab_size=4
23
123456789 123456789 123456789 123456789 123456789 123456789 123456789 1234
34

0 commit comments

Comments
 (0)