diff options
| author | Kang Seonghoon <public+git@mearie.org> | 2015-01-18 03:23:52 +0900 |
|---|---|---|
| committer | Kang Seonghoon <public+git@mearie.org> | 2015-01-18 03:23:52 +0900 |
| commit | 39e19ccdb6c89703a9c88eb88a26f61ec10d31f3 (patch) | |
| tree | a63f74b0a2b07262c538db4dceefc72f797540ad | |
| parent | de6f520192d76151bf99f2250afac75da3f040d5 (diff) | |
| download | rust-39e19ccdb6c89703a9c88eb88a26f61ec10d31f3.tar.gz rust-39e19ccdb6c89703a9c88eb88a26f61ec10d31f3.zip | |
tests: Tidy and allows multi-line htmldocck commands.
| -rw-r--r-- | src/etc/htmldocck.py | 38 | ||||
| -rw-r--r-- | src/test/run-make/rustdoc-where/foo.rs | 12 |
2 files changed, 43 insertions, 7 deletions
diff --git a/src/etc/htmldocck.py b/src/etc/htmldocck.py index 9693129db3b..25734217589 100644 --- a/src/etc/htmldocck.py +++ b/src/etc/htmldocck.py @@ -148,11 +148,43 @@ class CustomHTMLParser(HTMLParser): Command = namedtuple('Command', 'negated cmd args lineno') -LINE_PATTERN = re.compile(r'(?<=(?<!\S)@)(?P<negated>!?)(?P<cmd>[A-Za-z]+(?:-[A-Za-z]+)*)(?P<args>.*)$') +# returns a generator out of the file object, which +# - removes `\\` then `\n` then a shared prefix with the previous line then optional whitespace; +# - keeps a line number (starting from 0) of the first line being concatenated. +def concat_multi_lines(f): + lastline = None # set to the last line when the last line has a backslash + firstlineno = None + catenated = '' + for lineno, line in enumerate(f): + line = line.rstrip('\r\n') + + # strip the common prefix from the current line if needed + if lastline is not None: + maxprefix = 0 + for i in xrange(min(len(line), len(lastline))): + if line[i] != lastline[i]: break + maxprefix += 1 + line = line[maxprefix:].lstrip() + + firstlineno = firstlineno or lineno + if line.endswith('\\'): + lastline = line[:-1] + catenated += line[:-1] + else: + yield firstlineno, catenated + line + lastline = None + firstlineno = None + catenated = '' + +LINE_PATTERN = re.compile(r''' + (?<=(?<!\S)@)(?P<negated>!?) + (?P<cmd>[A-Za-z]+(?:-[A-Za-z]+)*) + (?P<args>.*)$ +''', re.X) def get_commands(template): with open(template, 'rUb') as f: - for lineno, line in enumerate(f): - m = LINE_PATTERN.search(line.rstrip('\r\n')) + for lineno, line in concat_multi_lines(f): + m = LINE_PATTERN.search(line) if not m: continue negated = (m.group('negated') == '!') diff --git a/src/test/run-make/rustdoc-where/foo.rs b/src/test/run-make/rustdoc-where/foo.rs index 286d101f164..9f38ff13805 100644 --- a/src/test/run-make/rustdoc-where/foo.rs +++ b/src/test/run-make/rustdoc-where/foo.rs @@ -24,11 +24,15 @@ impl<D> Delta<D> where D: MyTrait { } pub struct Echo<E>; -// @matches foo/struct.Echo.html '//*[@class="impl"]//code' "impl.*MyTrait.*for.*Echo.*where.*E:.*MyTrait" -// @matches foo/trait.MyTrait.html '//*[@id="implementors-list"]//code' "impl.*MyTrait.*for.*Echo.*where.*E:.*MyTrait" +// @matches foo/struct.Echo.html '//*[@class="impl"]//code' \ +// "impl.*MyTrait.*for.*Echo.*where.*E:.*MyTrait" +// @matches foo/trait.MyTrait.html '//*[@id="implementors-list"]//code' \ +// "impl.*MyTrait.*for.*Echo.*where.*E:.*MyTrait" impl<E> MyTrait for Echo<E> where E: MyTrait {} pub enum Foxtrot<F> {} -// @matches foo/enum.Foxtrot.html '//*[@class="impl"]//code' "impl.*MyTrait.*for.*Foxtrot.*where.*F:.*MyTrait" -// @matches foo/trait.MyTrait.html '//*[@id="implementors-list"]//code' "impl.*MyTrait.*for.*Foxtrot.*where.*F:.*MyTrait" +// @matches foo/enum.Foxtrot.html '//*[@class="impl"]//code' \ +// "impl.*MyTrait.*for.*Foxtrot.*where.*F:.*MyTrait" +// @matches foo/trait.MyTrait.html '//*[@id="implementors-list"]//code' \ +// "impl.*MyTrait.*for.*Foxtrot.*where.*F:.*MyTrait" impl<F> MyTrait for Foxtrot<F> where F: MyTrait {} |
