Skip to content

Commit 39e19cc

Browse files
committed
tests: Tidy and allows multi-line htmldocck commands.
1 parent de6f520 commit 39e19cc

File tree

2 files changed

+43
-7
lines changed

2 files changed

+43
-7
lines changed

src/etc/htmldocck.py

Lines changed: 35 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -148,11 +148,43 @@ def close(self):
148148

149149
Command = namedtuple('Command', 'negated cmd args lineno')
150150

151-
LINE_PATTERN = re.compile(r'(?<=(?<!\S)@)(?P<negated>!?)(?P<cmd>[A-Za-z]+(?:-[A-Za-z]+)*)(?P<args>.*)$')
151+
# returns a generator out of the file object, which
152+
# - removes `\\` then `\n` then a shared prefix with the previous line then optional whitespace;
153+
# - keeps a line number (starting from 0) of the first line being concatenated.
154+
def concat_multi_lines(f):
155+
lastline = None # set to the last line when the last line has a backslash
156+
firstlineno = None
157+
catenated = ''
158+
for lineno, line in enumerate(f):
159+
line = line.rstrip('\r\n')
160+
161+
# strip the common prefix from the current line if needed
162+
if lastline is not None:
163+
maxprefix = 0
164+
for i in xrange(min(len(line), len(lastline))):
165+
if line[i] != lastline[i]: break
166+
maxprefix += 1
167+
line = line[maxprefix:].lstrip()
168+
169+
firstlineno = firstlineno or lineno
170+
if line.endswith('\\'):
171+
lastline = line[:-1]
172+
catenated += line[:-1]
173+
else:
174+
yield firstlineno, catenated + line
175+
lastline = None
176+
firstlineno = None
177+
catenated = ''
178+
179+
LINE_PATTERN = re.compile(r'''
180+
(?<=(?<!\S)@)(?P<negated>!?)
181+
(?P<cmd>[A-Za-z]+(?:-[A-Za-z]+)*)
182+
(?P<args>.*)$
183+
''', re.X)
152184
def get_commands(template):
153185
with open(template, 'rUb') as f:
154-
for lineno, line in enumerate(f):
155-
m = LINE_PATTERN.search(line.rstrip('\r\n'))
186+
for lineno, line in concat_multi_lines(f):
187+
m = LINE_PATTERN.search(line)
156188
if not m: continue
157189

158190
negated = (m.group('negated') == '!')

src/test/run-make/rustdoc-where/foo.rs

Lines changed: 8 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -24,11 +24,15 @@ impl<D> Delta<D> where D: MyTrait {
2424
}
2525

2626
pub struct Echo<E>;
27-
// @matches foo/struct.Echo.html '//*[@class="impl"]//code' "impl.*MyTrait.*for.*Echo.*where.*E:.*MyTrait"
28-
// @matches foo/trait.MyTrait.html '//*[@id="implementors-list"]//code' "impl.*MyTrait.*for.*Echo.*where.*E:.*MyTrait"
27+
// @matches foo/struct.Echo.html '//*[@class="impl"]//code' \
28+
// "impl.*MyTrait.*for.*Echo.*where.*E:.*MyTrait"
29+
// @matches foo/trait.MyTrait.html '//*[@id="implementors-list"]//code' \
30+
// "impl.*MyTrait.*for.*Echo.*where.*E:.*MyTrait"
2931
impl<E> MyTrait for Echo<E> where E: MyTrait {}
3032

3133
pub enum Foxtrot<F> {}
32-
// @matches foo/enum.Foxtrot.html '//*[@class="impl"]//code' "impl.*MyTrait.*for.*Foxtrot.*where.*F:.*MyTrait"
33-
// @matches foo/trait.MyTrait.html '//*[@id="implementors-list"]//code' "impl.*MyTrait.*for.*Foxtrot.*where.*F:.*MyTrait"
34+
// @matches foo/enum.Foxtrot.html '//*[@class="impl"]//code' \
35+
// "impl.*MyTrait.*for.*Foxtrot.*where.*F:.*MyTrait"
36+
// @matches foo/trait.MyTrait.html '//*[@id="implementors-list"]//code' \
37+
// "impl.*MyTrait.*for.*Foxtrot.*where.*F:.*MyTrait"
3438
impl<F> MyTrait for Foxtrot<F> where F: MyTrait {}

0 commit comments

Comments
 (0)