2012-12-03 16:48:01 -08:00
|
|
|
// Copyright 2012 The Rust Project Developers. See the COPYRIGHT
|
|
|
|
// file at the top-level directory of this distribution and at
|
|
|
|
// http://rust-lang.org/COPYRIGHT.
|
|
|
|
//
|
|
|
|
// Licensed under the Apache License, Version 2.0 <LICENSE-APACHE or
|
|
|
|
// http://www.apache.org/licenses/LICENSE-2.0> or the MIT license
|
|
|
|
// <LICENSE-MIT or http://opensource.org/licenses/MIT>, at your
|
|
|
|
// option. This file may not be copied, modified, or distributed
|
|
|
|
// except according to those terms.
|
|
|
|
|
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-12-23 17:41:37 -05:00
|
|
|
use doc;
|
2013-01-08 19:37:25 -08:00
|
|
|
use pass::Pass;
|
2012-12-23 17:41:37 -05:00
|
|
|
use sort_pass;
|
2012-02-03 12:00:49 -08:00
|
|
|
|
2012-11-19 18:00:12 -08:00
|
|
|
pub fn mk_pass() -> Pass {
|
2013-03-22 11:10:53 -07:00
|
|
|
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() {
|
2013-02-28 11:57:33 -05:00
|
|
|
use astsrv;
|
|
|
|
use extract;
|
|
|
|
|
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| {
|
2013-01-31 20:24:03 -08:00
|
|
|
let doc = extract::from_srv(srv.clone(), ~"");
|
|
|
|
let doc = (mk_pass().f)(srv.clone(), doc);
|
2013-05-18 22:02:45 -04:00
|
|
|
assert_eq!(doc.cratemod().items[0].name(), ~"y");
|
|
|
|
assert_eq!(doc.cratemod().items[1].name(), ~"z");
|
2012-02-20 21:08:19 -08:00
|
|
|
}
|
2012-02-03 12:00:49 -08:00
|
|
|
}
|