2012-01-16 16:49:40 -06:00
|
|
|
export fold;
|
|
|
|
export default_seq_fold;
|
2012-03-02 20:33:25 -06:00
|
|
|
export default_seq_fold_doc;
|
2012-01-18 16:30:48 -06:00
|
|
|
export default_seq_fold_crate;
|
2012-02-17 17:51:58 -06:00
|
|
|
export default_seq_fold_item;
|
2012-01-18 20:51:04 -06:00
|
|
|
export default_seq_fold_mod;
|
2012-02-24 15:34:35 -06:00
|
|
|
export default_seq_fold_nmod;
|
2012-01-16 17:31:49 -06:00
|
|
|
export default_seq_fold_fn;
|
2012-01-24 02:44:47 -06:00
|
|
|
export default_seq_fold_const;
|
2012-01-25 20:40:47 -06:00
|
|
|
export default_seq_fold_enum;
|
2012-07-03 18:30:42 -05:00
|
|
|
export default_seq_fold_trait;
|
2012-01-31 17:28:09 -06:00
|
|
|
export default_seq_fold_impl;
|
2012-02-02 00:41:41 -06:00
|
|
|
export default_seq_fold_type;
|
2012-02-21 00:08:24 -06:00
|
|
|
export default_par_fold;
|
|
|
|
export default_par_fold_mod;
|
2012-02-27 00:58:24 -06:00
|
|
|
export default_par_fold_nmod;
|
2012-02-21 00:24:59 -06:00
|
|
|
export default_any_fold;
|
|
|
|
export default_any_fold_mod;
|
2012-02-27 00:58:24 -06:00
|
|
|
export default_any_fold_nmod;
|
2012-01-16 16:49:40 -06:00
|
|
|
|
2012-01-19 18:21:33 -06:00
|
|
|
enum fold<T> = t<T>;
|
2012-01-16 16:49:40 -06:00
|
|
|
|
2012-03-02 20:33:25 -06:00
|
|
|
type fold_doc<T> = fn~(fold: fold<T>, doc: doc::doc) -> doc::doc;
|
2012-01-19 02:14:41 -06:00
|
|
|
type fold_crate<T> = fn~(fold: fold<T>, doc: doc::cratedoc) -> doc::cratedoc;
|
2012-02-17 17:51:58 -06:00
|
|
|
type fold_item<T> = fn~(fold: fold<T>, doc: doc::itemdoc) -> doc::itemdoc;
|
2012-01-19 02:14:41 -06:00
|
|
|
type fold_mod<T> = fn~(fold: fold<T>, doc: doc::moddoc) -> doc::moddoc;
|
2012-02-24 15:34:35 -06:00
|
|
|
type fold_nmod<T> = fn~(fold: fold<T>, doc: doc::nmoddoc) -> doc::nmoddoc;
|
2012-01-19 02:14:41 -06:00
|
|
|
type fold_fn<T> = fn~(fold: fold<T>, doc: doc::fndoc) -> doc::fndoc;
|
2012-01-24 01:40:30 -06:00
|
|
|
type fold_const<T> = fn~(fold: fold<T>, doc: doc::constdoc) -> doc::constdoc;
|
2012-01-25 18:56:28 -06:00
|
|
|
type fold_enum<T> = fn~(fold: fold<T>, doc: doc::enumdoc) -> doc::enumdoc;
|
2012-07-03 18:30:42 -05:00
|
|
|
type fold_trait<T> = fn~(fold: fold<T>, doc: doc::traitdoc) -> doc::traitdoc;
|
2012-01-31 17:28:09 -06:00
|
|
|
type fold_impl<T> = fn~(fold: fold<T>, doc: doc::impldoc) -> doc::impldoc;
|
2012-02-02 00:41:41 -06:00
|
|
|
type fold_type<T> = fn~(fold: fold<T>, doc: doc::tydoc) -> doc::tydoc;
|
2012-01-16 16:49:40 -06:00
|
|
|
|
2012-01-16 17:31:49 -06:00
|
|
|
type t<T> = {
|
|
|
|
ctxt: T,
|
2012-03-02 20:33:25 -06:00
|
|
|
fold_doc: fold_doc<T>,
|
2012-01-16 17:31:49 -06:00
|
|
|
fold_crate: fold_crate<T>,
|
2012-02-17 17:51:58 -06:00
|
|
|
fold_item: fold_item<T>,
|
2012-01-16 17:31:49 -06:00
|
|
|
fold_mod: fold_mod<T>,
|
2012-02-24 15:34:35 -06:00
|
|
|
fold_nmod: fold_nmod<T>,
|
2012-01-16 17:31:49 -06:00
|
|
|
fold_fn: fold_fn<T>,
|
2012-01-24 01:40:30 -06:00
|
|
|
fold_const: fold_const<T>,
|
2012-01-25 18:56:28 -06:00
|
|
|
fold_enum: fold_enum<T>,
|
2012-07-03 18:30:42 -05:00
|
|
|
fold_trait: fold_trait<T>,
|
2012-02-02 00:41:41 -06:00
|
|
|
fold_impl: fold_impl<T>,
|
|
|
|
fold_type: fold_type<T>
|
2012-01-16 16:49:40 -06:00
|
|
|
};
|
|
|
|
|
|
|
|
|
|
|
|
// This exists because fn types don't infer correctly as record
|
|
|
|
// initializers, but they do as function arguments
|
2012-01-16 17:31:49 -06:00
|
|
|
fn mk_fold<T:copy>(
|
|
|
|
ctxt: T,
|
2012-05-24 16:49:39 -05:00
|
|
|
+fold_doc: fold_doc<T>,
|
|
|
|
+fold_crate: fold_crate<T>,
|
|
|
|
+fold_item: fold_item<T>,
|
|
|
|
+fold_mod: fold_mod<T>,
|
|
|
|
+fold_nmod: fold_nmod<T>,
|
|
|
|
+fold_fn: fold_fn<T>,
|
|
|
|
+fold_const: fold_const<T>,
|
|
|
|
+fold_enum: fold_enum<T>,
|
2012-07-03 18:30:42 -05:00
|
|
|
+fold_trait: fold_trait<T>,
|
2012-05-24 16:49:39 -05:00
|
|
|
+fold_impl: fold_impl<T>,
|
|
|
|
+fold_type: fold_type<T>
|
2012-01-16 17:31:49 -06:00
|
|
|
) -> fold<T> {
|
2012-01-16 16:49:40 -06:00
|
|
|
fold({
|
2012-01-16 17:31:49 -06:00
|
|
|
ctxt: ctxt,
|
2012-03-02 20:33:25 -06:00
|
|
|
fold_doc: fold_doc,
|
2012-01-16 16:49:40 -06:00
|
|
|
fold_crate: fold_crate,
|
2012-02-17 17:51:58 -06:00
|
|
|
fold_item: fold_item,
|
2012-01-16 16:49:40 -06:00
|
|
|
fold_mod: fold_mod,
|
2012-02-24 15:34:35 -06:00
|
|
|
fold_nmod: fold_nmod,
|
2012-01-16 16:49:40 -06:00
|
|
|
fold_fn: fold_fn,
|
2012-01-24 01:40:30 -06:00
|
|
|
fold_const: fold_const,
|
2012-01-25 18:56:28 -06:00
|
|
|
fold_enum: fold_enum,
|
2012-07-03 18:30:42 -05:00
|
|
|
fold_trait: fold_trait,
|
2012-02-02 00:41:41 -06:00
|
|
|
fold_impl: fold_impl,
|
|
|
|
fold_type: fold_type
|
2012-01-16 16:49:40 -06:00
|
|
|
})
|
|
|
|
}
|
|
|
|
|
2012-05-22 16:10:32 -05:00
|
|
|
fn default_any_fold<T:send copy>(ctxt: T) -> fold<T> {
|
2012-02-27 00:38:35 -06:00
|
|
|
mk_fold(
|
|
|
|
ctxt,
|
2012-06-30 18:19:07 -05:00
|
|
|
|f, d| default_seq_fold_doc(f, d),
|
|
|
|
|f, d| default_seq_fold_crate(f, d),
|
|
|
|
|f, d| default_seq_fold_item(f, d),
|
|
|
|
|f, d| default_any_fold_mod(f, d),
|
|
|
|
|f, d| default_any_fold_nmod(f, d),
|
|
|
|
|f, d| default_seq_fold_fn(f, d),
|
|
|
|
|f, d| default_seq_fold_const(f, d),
|
|
|
|
|f, d| default_seq_fold_enum(f, d),
|
2012-07-03 18:30:42 -05:00
|
|
|
|f, d| default_seq_fold_trait(f, d),
|
2012-06-30 18:19:07 -05:00
|
|
|
|f, d| default_seq_fold_impl(f, d),
|
|
|
|
|f, d| default_seq_fold_type(f, d)
|
2012-02-27 00:38:35 -06:00
|
|
|
)
|
|
|
|
}
|
|
|
|
|
2012-01-16 17:31:49 -06:00
|
|
|
fn default_seq_fold<T:copy>(ctxt: T) -> fold<T> {
|
2012-01-16 16:49:40 -06:00
|
|
|
mk_fold(
|
2012-01-16 17:31:49 -06:00
|
|
|
ctxt,
|
2012-06-30 18:19:07 -05:00
|
|
|
|f, d| default_seq_fold_doc(f, d),
|
|
|
|
|f, d| default_seq_fold_crate(f, d),
|
|
|
|
|f, d| default_seq_fold_item(f, d),
|
|
|
|
|f, d| default_seq_fold_mod(f, d),
|
|
|
|
|f, d| default_seq_fold_nmod(f, d),
|
|
|
|
|f, d| default_seq_fold_fn(f, d),
|
|
|
|
|f, d| default_seq_fold_const(f, d),
|
|
|
|
|f, d| default_seq_fold_enum(f, d),
|
2012-07-03 18:30:42 -05:00
|
|
|
|f, d| default_seq_fold_trait(f, d),
|
2012-06-30 18:19:07 -05:00
|
|
|
|f, d| default_seq_fold_impl(f, d),
|
|
|
|
|f, d| default_seq_fold_type(f, d)
|
2012-01-16 16:49:40 -06:00
|
|
|
)
|
|
|
|
}
|
|
|
|
|
2012-05-22 16:10:32 -05:00
|
|
|
fn default_par_fold<T:send copy>(ctxt: T) -> fold<T> {
|
2012-02-21 00:08:24 -06:00
|
|
|
mk_fold(
|
|
|
|
ctxt,
|
2012-06-30 18:19:07 -05:00
|
|
|
|f, d| default_seq_fold_doc(f, d),
|
|
|
|
|f, d| default_seq_fold_crate(f, d),
|
|
|
|
|f, d| default_seq_fold_item(f, d),
|
|
|
|
|f, d| default_par_fold_mod(f, d),
|
|
|
|
|f, d| default_par_fold_nmod(f, d),
|
|
|
|
|f, d| default_seq_fold_fn(f, d),
|
|
|
|
|f, d| default_seq_fold_const(f, d),
|
|
|
|
|f, d| default_seq_fold_enum(f, d),
|
2012-07-03 18:30:42 -05:00
|
|
|
|f, d| default_seq_fold_trait(f, d),
|
2012-06-30 18:19:07 -05:00
|
|
|
|f, d| default_seq_fold_impl(f, d),
|
|
|
|
|f, d| default_seq_fold_type(f, d)
|
2012-02-21 00:08:24 -06:00
|
|
|
)
|
|
|
|
}
|
|
|
|
|
2012-03-02 20:33:25 -06:00
|
|
|
fn default_seq_fold_doc<T>(fold: fold<T>, doc: doc::doc) -> doc::doc {
|
|
|
|
{
|
2012-06-30 18:19:07 -05:00
|
|
|
pages: do par::seqmap(doc.pages) |page| {
|
2012-03-02 20:33:25 -06:00
|
|
|
alt page {
|
|
|
|
doc::cratepage(doc) {
|
|
|
|
doc::cratepage(fold.fold_crate(fold, doc))
|
|
|
|
}
|
|
|
|
doc::itempage(doc) {
|
|
|
|
doc::itempage(fold_itemtag(fold, doc))
|
|
|
|
}
|
|
|
|
}
|
|
|
|
}
|
|
|
|
with doc
|
|
|
|
}
|
|
|
|
}
|
|
|
|
|
2012-01-16 17:31:49 -06:00
|
|
|
fn default_seq_fold_crate<T>(
|
|
|
|
fold: fold<T>,
|
2012-01-16 16:49:40 -06:00
|
|
|
doc: doc::cratedoc
|
|
|
|
) -> doc::cratedoc {
|
2012-01-30 15:05:25 -06:00
|
|
|
{
|
2012-01-16 16:49:40 -06:00
|
|
|
topmod: fold.fold_mod(fold, doc.topmod)
|
|
|
|
}
|
|
|
|
}
|
|
|
|
|
2012-02-17 17:51:58 -06:00
|
|
|
fn default_seq_fold_item<T>(
|
|
|
|
_fold: fold<T>,
|
|
|
|
doc: doc::itemdoc
|
|
|
|
) -> doc::itemdoc {
|
|
|
|
doc
|
|
|
|
}
|
|
|
|
|
2012-05-23 17:46:43 -05:00
|
|
|
fn default_any_fold_mod<T:send copy>(
|
2012-01-16 17:31:49 -06:00
|
|
|
fold: fold<T>,
|
2012-01-16 16:49:40 -06:00
|
|
|
doc: doc::moddoc
|
|
|
|
) -> doc::moddoc {
|
2012-01-30 15:05:25 -06:00
|
|
|
{
|
2012-02-17 17:51:58 -06:00
|
|
|
item: fold.fold_item(fold, doc.item),
|
2012-06-30 18:19:07 -05:00
|
|
|
items: par::anymap(doc.items, |itemtag, copy fold| {
|
2012-02-21 00:08:24 -06:00
|
|
|
fold_itemtag(fold, itemtag)
|
2012-06-26 15:55:56 -05:00
|
|
|
})
|
2012-02-21 00:08:24 -06:00
|
|
|
with doc
|
|
|
|
}
|
|
|
|
}
|
|
|
|
|
2012-02-27 00:38:35 -06:00
|
|
|
fn default_seq_fold_mod<T>(
|
2012-02-24 15:34:35 -06:00
|
|
|
fold: fold<T>,
|
2012-02-27 00:38:35 -06:00
|
|
|
doc: doc::moddoc
|
|
|
|
) -> doc::moddoc {
|
2012-02-24 15:34:35 -06:00
|
|
|
{
|
|
|
|
item: fold.fold_item(fold, doc.item),
|
2012-06-30 18:19:07 -05:00
|
|
|
items: par::seqmap(doc.items, |itemtag| {
|
2012-02-27 00:38:35 -06:00
|
|
|
fold_itemtag(fold, itemtag)
|
2012-06-26 15:55:56 -05:00
|
|
|
})
|
2012-02-24 15:34:35 -06:00
|
|
|
with doc
|
|
|
|
}
|
|
|
|
}
|
|
|
|
|
2012-05-23 17:46:43 -05:00
|
|
|
fn default_par_fold_mod<T:send copy>(
|
2012-02-21 00:08:24 -06:00
|
|
|
fold: fold<T>,
|
|
|
|
doc: doc::moddoc
|
|
|
|
) -> doc::moddoc {
|
|
|
|
{
|
|
|
|
item: fold.fold_item(fold, doc.item),
|
2012-06-30 18:19:07 -05:00
|
|
|
items: par::parmap(doc.items, |itemtag, copy fold| {
|
2012-02-21 00:08:24 -06:00
|
|
|
fold_itemtag(fold, itemtag)
|
2012-06-26 15:55:56 -05:00
|
|
|
})
|
2012-01-30 15:05:25 -06:00
|
|
|
with doc
|
2012-01-16 16:49:40 -06:00
|
|
|
}
|
|
|
|
}
|
|
|
|
|
2012-05-23 17:46:43 -05:00
|
|
|
fn default_any_fold_nmod<T:send copy>(
|
2012-02-27 00:58:24 -06:00
|
|
|
fold: fold<T>,
|
|
|
|
doc: doc::nmoddoc
|
|
|
|
) -> doc::nmoddoc {
|
|
|
|
{
|
|
|
|
item: fold.fold_item(fold, doc.item),
|
2012-06-30 18:19:07 -05:00
|
|
|
fns: par::anymap(doc.fns, |fndoc, copy fold| {
|
2012-02-27 00:58:24 -06:00
|
|
|
fold.fold_fn(fold, fndoc)
|
2012-06-26 15:55:56 -05:00
|
|
|
})
|
2012-02-27 00:58:24 -06:00
|
|
|
with doc
|
|
|
|
}
|
|
|
|
}
|
|
|
|
|
2012-02-27 00:38:35 -06:00
|
|
|
fn default_seq_fold_nmod<T>(
|
2012-02-21 00:24:59 -06:00
|
|
|
fold: fold<T>,
|
2012-02-27 00:38:35 -06:00
|
|
|
doc: doc::nmoddoc
|
|
|
|
) -> doc::nmoddoc {
|
|
|
|
{
|
|
|
|
item: fold.fold_item(fold, doc.item),
|
2012-06-30 18:19:07 -05:00
|
|
|
fns: par::seqmap(doc.fns, |fndoc| {
|
2012-02-27 00:58:24 -06:00
|
|
|
fold.fold_fn(fold, fndoc)
|
2012-06-26 15:55:56 -05:00
|
|
|
})
|
2012-02-27 00:58:24 -06:00
|
|
|
with doc
|
|
|
|
}
|
|
|
|
}
|
|
|
|
|
2012-05-23 17:46:43 -05:00
|
|
|
fn default_par_fold_nmod<T:send copy>(
|
2012-02-27 00:58:24 -06:00
|
|
|
fold: fold<T>,
|
|
|
|
doc: doc::nmoddoc
|
|
|
|
) -> doc::nmoddoc {
|
|
|
|
{
|
|
|
|
item: fold.fold_item(fold, doc.item),
|
2012-06-30 18:19:07 -05:00
|
|
|
fns: par::parmap(doc.fns, |fndoc, copy fold| {
|
2012-02-27 00:38:35 -06:00
|
|
|
fold.fold_fn(fold, fndoc)
|
2012-06-26 15:55:56 -05:00
|
|
|
})
|
2012-02-27 00:38:35 -06:00
|
|
|
with doc
|
|
|
|
}
|
2012-02-21 00:24:59 -06:00
|
|
|
}
|
|
|
|
|
2012-02-21 00:08:24 -06:00
|
|
|
fn fold_itemtag<T>(fold: fold<T>, doc: doc::itemtag) -> doc::itemtag {
|
|
|
|
alt doc {
|
|
|
|
doc::modtag(moddoc) {
|
|
|
|
doc::modtag(fold.fold_mod(fold, moddoc))
|
|
|
|
}
|
2012-02-24 15:34:35 -06:00
|
|
|
doc::nmodtag(nmoddoc) {
|
|
|
|
doc::nmodtag(fold.fold_nmod(fold, nmoddoc))
|
|
|
|
}
|
2012-02-21 00:08:24 -06:00
|
|
|
doc::fntag(fndoc) {
|
|
|
|
doc::fntag(fold.fold_fn(fold, fndoc))
|
|
|
|
}
|
|
|
|
doc::consttag(constdoc) {
|
|
|
|
doc::consttag(fold.fold_const(fold, constdoc))
|
|
|
|
}
|
|
|
|
doc::enumtag(enumdoc) {
|
|
|
|
doc::enumtag(fold.fold_enum(fold, enumdoc))
|
|
|
|
}
|
2012-07-03 18:30:42 -05:00
|
|
|
doc::traittag(traitdoc) {
|
|
|
|
doc::traittag(fold.fold_trait(fold, traitdoc))
|
2012-02-21 00:08:24 -06:00
|
|
|
}
|
|
|
|
doc::impltag(impldoc) {
|
|
|
|
doc::impltag(fold.fold_impl(fold, impldoc))
|
|
|
|
}
|
|
|
|
doc::tytag(tydoc) {
|
|
|
|
doc::tytag(fold.fold_type(fold, tydoc))
|
|
|
|
}
|
|
|
|
}
|
|
|
|
}
|
|
|
|
|
2012-01-16 17:31:49 -06:00
|
|
|
fn default_seq_fold_fn<T>(
|
2012-02-17 17:51:58 -06:00
|
|
|
fold: fold<T>,
|
2012-01-16 16:49:40 -06:00
|
|
|
doc: doc::fndoc
|
|
|
|
) -> doc::fndoc {
|
2012-02-17 17:51:58 -06:00
|
|
|
{
|
|
|
|
item: fold.fold_item(fold, doc.item)
|
|
|
|
with doc
|
|
|
|
}
|
2012-01-16 16:49:40 -06:00
|
|
|
}
|
|
|
|
|
2012-01-24 01:40:30 -06:00
|
|
|
fn default_seq_fold_const<T>(
|
2012-02-17 17:51:58 -06:00
|
|
|
fold: fold<T>,
|
2012-01-24 01:40:30 -06:00
|
|
|
doc: doc::constdoc
|
|
|
|
) -> doc::constdoc {
|
2012-02-17 17:51:58 -06:00
|
|
|
{
|
|
|
|
item: fold.fold_item(fold, doc.item)
|
|
|
|
with doc
|
|
|
|
}
|
2012-01-24 01:40:30 -06:00
|
|
|
}
|
|
|
|
|
2012-01-25 18:56:28 -06:00
|
|
|
fn default_seq_fold_enum<T>(
|
2012-02-17 17:51:58 -06:00
|
|
|
fold: fold<T>,
|
2012-01-25 18:56:28 -06:00
|
|
|
doc: doc::enumdoc
|
|
|
|
) -> doc::enumdoc {
|
2012-02-17 17:51:58 -06:00
|
|
|
{
|
|
|
|
item: fold.fold_item(fold, doc.item)
|
|
|
|
with doc
|
|
|
|
}
|
2012-01-25 18:56:28 -06:00
|
|
|
}
|
|
|
|
|
2012-07-03 18:30:42 -05:00
|
|
|
fn default_seq_fold_trait<T>(
|
2012-02-17 17:51:58 -06:00
|
|
|
fold: fold<T>,
|
2012-07-03 18:30:42 -05:00
|
|
|
doc: doc::traitdoc
|
|
|
|
) -> doc::traitdoc {
|
2012-02-17 17:51:58 -06:00
|
|
|
{
|
|
|
|
item: fold.fold_item(fold, doc.item)
|
|
|
|
with doc
|
|
|
|
}
|
2012-01-30 16:11:35 -06:00
|
|
|
}
|
|
|
|
|
2012-01-31 17:28:09 -06:00
|
|
|
fn default_seq_fold_impl<T>(
|
2012-02-17 17:51:58 -06:00
|
|
|
fold: fold<T>,
|
2012-01-31 17:28:09 -06:00
|
|
|
doc: doc::impldoc
|
|
|
|
) -> doc::impldoc {
|
2012-02-17 17:51:58 -06:00
|
|
|
{
|
|
|
|
item: fold.fold_item(fold, doc.item)
|
|
|
|
with doc
|
|
|
|
}
|
2012-01-31 17:28:09 -06:00
|
|
|
}
|
|
|
|
|
2012-02-02 00:41:41 -06:00
|
|
|
fn default_seq_fold_type<T>(
|
2012-02-17 17:51:58 -06:00
|
|
|
fold: fold<T>,
|
2012-02-02 00:41:41 -06:00
|
|
|
doc: doc::tydoc
|
|
|
|
) -> doc::tydoc {
|
2012-02-17 17:51:58 -06:00
|
|
|
{
|
|
|
|
item: fold.fold_item(fold, doc.item)
|
|
|
|
with doc
|
|
|
|
}
|
2012-02-02 00:41:41 -06:00
|
|
|
}
|
|
|
|
|
2012-01-24 01:40:30 -06:00
|
|
|
#[test]
|
|
|
|
fn default_fold_should_produce_same_doc() {
|
|
|
|
let source = "mod a { fn b() { } mod c { fn d() { } } }";
|
2012-04-30 13:52:07 -05:00
|
|
|
let ast = parse::from_str(source);
|
2012-01-24 01:40:30 -06:00
|
|
|
let doc = extract::extract(ast, "");
|
|
|
|
let fld = default_seq_fold(());
|
2012-03-02 20:33:25 -06:00
|
|
|
let folded = fld.fold_doc(fld, doc);
|
2012-01-24 01:40:30 -06:00
|
|
|
assert doc == folded;
|
|
|
|
}
|
|
|
|
|
|
|
|
#[test]
|
|
|
|
fn default_fold_should_produce_same_consts() {
|
|
|
|
let source = "const a: int = 0;";
|
2012-04-30 13:52:07 -05:00
|
|
|
let ast = parse::from_str(source);
|
2012-01-24 01:40:30 -06:00
|
|
|
let doc = extract::extract(ast, "");
|
|
|
|
let fld = default_seq_fold(());
|
2012-03-02 20:33:25 -06:00
|
|
|
let folded = fld.fold_doc(fld, doc);
|
2012-01-24 01:40:30 -06:00
|
|
|
assert doc == folded;
|
2012-01-25 18:56:28 -06:00
|
|
|
}
|
|
|
|
|
|
|
|
#[test]
|
|
|
|
fn default_fold_should_produce_same_enums() {
|
|
|
|
let source = "enum a { b }";
|
2012-04-30 13:52:07 -05:00
|
|
|
let ast = parse::from_str(source);
|
2012-01-25 18:56:28 -06:00
|
|
|
let doc = extract::extract(ast, "");
|
|
|
|
let fld = default_seq_fold(());
|
2012-03-02 20:33:25 -06:00
|
|
|
let folded = fld.fold_doc(fld, doc);
|
2012-01-25 18:56:28 -06:00
|
|
|
assert doc == folded;
|
2012-02-21 00:08:24 -06:00
|
|
|
}
|
|
|
|
|
|
|
|
#[test]
|
|
|
|
fn default_parallel_fold_should_produce_same_doc() {
|
|
|
|
let source = "mod a { fn b() { } mod c { fn d() { } } }";
|
2012-04-30 13:52:07 -05:00
|
|
|
let ast = parse::from_str(source);
|
2012-02-21 00:08:24 -06:00
|
|
|
let doc = extract::extract(ast, "");
|
|
|
|
let fld = default_par_fold(());
|
2012-03-02 20:33:25 -06:00
|
|
|
let folded = fld.fold_doc(fld, doc);
|
2012-02-21 00:08:24 -06:00
|
|
|
assert doc == folded;
|
|
|
|
}
|