rustdoc: Add a pass type and a run_passes function
This commit is contained in:
parent
74d4989876
commit
447f1fd4af
@ -5,6 +5,53 @@
|
||||
use std;
|
||||
use rustc;
|
||||
|
||||
type pass = fn~(srv: astsrv::seq_srv, doc: doc::cratedoc) -> doc::cratedoc;
|
||||
|
||||
fn run_passes(
|
||||
srv: astsrv::seq_srv,
|
||||
doc: doc::cratedoc,
|
||||
passes: [pass]
|
||||
) -> doc::cratedoc {
|
||||
vec::foldl(doc, passes) {|doc, pass|
|
||||
pass(srv, doc)
|
||||
}
|
||||
}
|
||||
|
||||
#[test]
|
||||
fn test_run_passes() {
|
||||
import astsrv::seq_srv;
|
||||
fn pass1(
|
||||
_srv: astsrv::seq_srv,
|
||||
doc: doc::cratedoc
|
||||
) -> doc::cratedoc {
|
||||
~{
|
||||
topmod: ~{
|
||||
name: doc.topmod.name + "two",
|
||||
mods: doc::modlist([]),
|
||||
fns: doc::fnlist([])
|
||||
}
|
||||
}
|
||||
}
|
||||
fn pass2(
|
||||
_srv: astsrv::seq_srv,
|
||||
doc: doc::cratedoc
|
||||
) -> doc::cratedoc {
|
||||
~{
|
||||
topmod: ~{
|
||||
name: doc.topmod.name + "three",
|
||||
mods: doc::modlist([]),
|
||||
fns: doc::fnlist([])
|
||||
}
|
||||
}
|
||||
}
|
||||
let source = "";
|
||||
let srv = astsrv::mk_seq_srv_from_str(source);
|
||||
let passes = [pass1, pass2];
|
||||
let doc = extract::from_srv(srv, "one");
|
||||
let doc = run_passes(srv, doc, passes);
|
||||
assert doc.topmod.name == "onetwothree";
|
||||
}
|
||||
|
||||
#[doc(
|
||||
brief = "Main function.",
|
||||
desc = "Command-line arguments:
|
||||
|
Loading…
Reference in New Issue
Block a user