2012-07-04 22:53:12 +01:00
|
|
|
//! Sorts items by name
|
2012-02-03 12:00:49 -08:00
|
|
|
|
2012-09-18 16:48:40 -07:00
|
|
|
use doc::ItemUtils;
|
2012-02-03 12:00:49 -08:00
|
|
|
export mk_pass;
|
|
|
|
|
2012-09-18 16:48:40 -07:00
|
|
|
fn mk_pass() -> Pass {
|
|
|
|
pure fn by_item_name(item1: &doc::ItemTag, item2: &doc::ItemTag) -> bool {
|
2012-08-02 15:42:56 -07:00
|
|
|
(*item1).name() <= (*item2).name()
|
|
|
|
}
|
|
|
|
sort_pass::mk_pass(~"sort_item_name", by_item_name)
|
2012-02-03 12:00:49 -08:00
|
|
|
}
|
|
|
|
|
|
|
|
#[test]
|
|
|
|
fn test() {
|
2012-07-13 22:57:48 -07:00
|
|
|
let source = ~"mod z { } fn y() { }";
|
2012-06-30 16:19:07 -07:00
|
|
|
do astsrv::from_str(source) |srv| {
|
2012-07-13 22:57:48 -07:00
|
|
|
let doc = extract::from_srv(srv, ~"");
|
2012-02-27 18:07:16 -08:00
|
|
|
let doc = mk_pass().f(srv, doc);
|
2012-07-13 22:57:48 -07:00
|
|
|
assert doc.cratemod().items[0].name() == ~"y";
|
|
|
|
assert doc.cratemod().items[1].name() == ~"z";
|
2012-02-20 21:08:19 -08:00
|
|
|
}
|
2012-02-03 12:00:49 -08:00
|
|
|
}
|