Skip to content

Commit fefb074

Browse files
committed
---
yaml --- r: 7666 b: refs/heads/master c: ef94199 h: refs/heads/master v: v3
1 parent 6f2603f commit fefb074

File tree

2 files changed

+33
-5
lines changed

2 files changed

+33
-5
lines changed

[refs]

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -1,2 +1,2 @@
11
---
2-
refs/heads/master: 17ac98ba22011c08289de98e16c84220f031f5eb
2+
refs/heads/master: ef941998bea47c601adbb4af03beda98412aee6d

trunk/src/rustdoc/gen.rs

Lines changed: 32 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -117,13 +117,19 @@ fn write_fn(
117117
fn write_sig(ctxt: ctxt, sig: option<str>) {
118118
alt sig {
119119
some(sig) {
120-
ctxt.w.write_line(#fmt(" %s", sig));
120+
ctxt.w.write_line(code_block_indent(sig));
121121
ctxt.w.write_line("");
122122
}
123123
none { fail "unimplemented" }
124124
}
125125
}
126126

127+
fn code_block_indent(s: str) -> str {
128+
let lines = str::lines_any(s);
129+
let indented = vec::map(lines, { |line| #fmt(" %s", line) });
130+
str::connect(indented, "\n")
131+
}
132+
127133
#[test]
128134
fn should_write_the_function_signature() {
129135
let markdown = test::render("#[doc = \"f\"] fn a() { }");
@@ -136,6 +142,23 @@ fn should_insert_blank_line_after_fn_signature() {
136142
assert str::contains(markdown, "fn a()\n\n");
137143
}
138144

145+
#[test]
146+
fn should_correctly_indent_fn_signature() {
147+
let doc = test::create_doc("fn a() { }");
148+
let doc = ~{
149+
topmod: ~{
150+
fns: doc::fnlist([~{
151+
sig: some("line 1\nline 2")
152+
with *doc.topmod.fns[0]
153+
}])
154+
with *doc.topmod
155+
}
156+
with *doc
157+
};
158+
let markdown = test::write_markdown_str(doc);
159+
assert str::contains(markdown, " line 1\n line 2");
160+
}
161+
139162
fn write_brief(
140163
ctxt: ctxt,
141164
brief: option<str>
@@ -280,6 +303,13 @@ fn should_write_return_description_on_same_line_as_type() {
280303
#[cfg(test)]
281304
mod test {
282305
fn render(source: str) -> str {
306+
let doc = create_doc(source);
307+
let markdown = write_markdown_str(doc);
308+
#debug("markdown: %s", markdown);
309+
markdown
310+
}
311+
312+
fn create_doc(source: str) -> doc::cratedoc {
283313
let srv = astsrv::mk_srv_from_str(source);
284314
let doc = extract::from_srv(srv, "");
285315
#debug("doc (extract): %?", doc);
@@ -289,9 +319,7 @@ mod test {
289319
#debug("doc (path): %?", doc);
290320
let doc = attr_pass::mk_pass()(srv, doc);
291321
#debug("doc (attr): %?", doc);
292-
let markdown = write_markdown_str(doc);
293-
#debug("markdown: %s", markdown);
294-
markdown
322+
doc
295323
}
296324

297325
fn write_markdown_str(

0 commit comments

Comments
 (0)