librustdoc: Unconfigure tests during normal build
This commit is contained in:
parent
e118eb6c79
commit
a332e224a3
|
@ -16,6 +16,9 @@ use syntax_pos::Span;
|
||||||
|
|
||||||
use crate::html::escape::Escape;
|
use crate::html::escape::Escape;
|
||||||
|
|
||||||
|
#[cfg(test)]
|
||||||
|
mod tests;
|
||||||
|
|
||||||
#[derive(Clone, Debug, PartialEq, Eq, Hash)]
|
#[derive(Clone, Debug, PartialEq, Eq, Hash)]
|
||||||
pub enum Cfg {
|
pub enum Cfg {
|
||||||
/// Accepts all configurations.
|
/// Accepts all configurations.
|
||||||
|
@ -408,420 +411,3 @@ impl<'a> fmt::Display for Html<'a> {
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
#[cfg(test)]
|
|
||||||
mod test {
|
|
||||||
use super::Cfg;
|
|
||||||
|
|
||||||
use syntax_pos::DUMMY_SP;
|
|
||||||
use syntax::ast::*;
|
|
||||||
use syntax::attr;
|
|
||||||
use syntax::source_map::dummy_spanned;
|
|
||||||
use syntax::symbol::Symbol;
|
|
||||||
use syntax::with_default_globals;
|
|
||||||
|
|
||||||
fn word_cfg(s: &str) -> Cfg {
|
|
||||||
Cfg::Cfg(Symbol::intern(s), None)
|
|
||||||
}
|
|
||||||
|
|
||||||
fn name_value_cfg(name: &str, value: &str) -> Cfg {
|
|
||||||
Cfg::Cfg(Symbol::intern(name), Some(Symbol::intern(value)))
|
|
||||||
}
|
|
||||||
|
|
||||||
fn dummy_meta_item_word(name: &str) -> MetaItem {
|
|
||||||
MetaItem {
|
|
||||||
path: Path::from_ident(Ident::from_str(name)),
|
|
||||||
node: MetaItemKind::Word,
|
|
||||||
span: DUMMY_SP,
|
|
||||||
}
|
|
||||||
}
|
|
||||||
|
|
||||||
macro_rules! dummy_meta_item_list {
|
|
||||||
($name:ident, [$($list:ident),* $(,)?]) => {
|
|
||||||
MetaItem {
|
|
||||||
path: Path::from_ident(Ident::from_str(stringify!($name))),
|
|
||||||
node: MetaItemKind::List(vec![
|
|
||||||
$(
|
|
||||||
NestedMetaItem::MetaItem(
|
|
||||||
dummy_meta_item_word(stringify!($list)),
|
|
||||||
),
|
|
||||||
)*
|
|
||||||
]),
|
|
||||||
span: DUMMY_SP,
|
|
||||||
}
|
|
||||||
};
|
|
||||||
|
|
||||||
($name:ident, [$($list:expr),* $(,)?]) => {
|
|
||||||
MetaItem {
|
|
||||||
path: Path::from_ident(Ident::from_str(stringify!($name))),
|
|
||||||
node: MetaItemKind::List(vec![
|
|
||||||
$(
|
|
||||||
NestedMetaItem::MetaItem($list),
|
|
||||||
)*
|
|
||||||
]),
|
|
||||||
span: DUMMY_SP,
|
|
||||||
}
|
|
||||||
};
|
|
||||||
}
|
|
||||||
|
|
||||||
#[test]
|
|
||||||
fn test_cfg_not() {
|
|
||||||
with_default_globals(|| {
|
|
||||||
assert_eq!(!Cfg::False, Cfg::True);
|
|
||||||
assert_eq!(!Cfg::True, Cfg::False);
|
|
||||||
assert_eq!(!word_cfg("test"), Cfg::Not(Box::new(word_cfg("test"))));
|
|
||||||
assert_eq!(
|
|
||||||
!Cfg::All(vec![word_cfg("a"), word_cfg("b")]),
|
|
||||||
Cfg::Not(Box::new(Cfg::All(vec![word_cfg("a"), word_cfg("b")])))
|
|
||||||
);
|
|
||||||
assert_eq!(
|
|
||||||
!Cfg::Any(vec![word_cfg("a"), word_cfg("b")]),
|
|
||||||
Cfg::Not(Box::new(Cfg::Any(vec![word_cfg("a"), word_cfg("b")])))
|
|
||||||
);
|
|
||||||
assert_eq!(!Cfg::Not(Box::new(word_cfg("test"))), word_cfg("test"));
|
|
||||||
})
|
|
||||||
}
|
|
||||||
|
|
||||||
#[test]
|
|
||||||
fn test_cfg_and() {
|
|
||||||
with_default_globals(|| {
|
|
||||||
let mut x = Cfg::False;
|
|
||||||
x &= Cfg::True;
|
|
||||||
assert_eq!(x, Cfg::False);
|
|
||||||
|
|
||||||
x = word_cfg("test");
|
|
||||||
x &= Cfg::False;
|
|
||||||
assert_eq!(x, Cfg::False);
|
|
||||||
|
|
||||||
x = word_cfg("test2");
|
|
||||||
x &= Cfg::True;
|
|
||||||
assert_eq!(x, word_cfg("test2"));
|
|
||||||
|
|
||||||
x = Cfg::True;
|
|
||||||
x &= word_cfg("test3");
|
|
||||||
assert_eq!(x, word_cfg("test3"));
|
|
||||||
|
|
||||||
x &= word_cfg("test4");
|
|
||||||
assert_eq!(x, Cfg::All(vec![word_cfg("test3"), word_cfg("test4")]));
|
|
||||||
|
|
||||||
x &= word_cfg("test5");
|
|
||||||
assert_eq!(x, Cfg::All(vec![word_cfg("test3"), word_cfg("test4"), word_cfg("test5")]));
|
|
||||||
|
|
||||||
x &= Cfg::All(vec![word_cfg("test6"), word_cfg("test7")]);
|
|
||||||
assert_eq!(x, Cfg::All(vec![
|
|
||||||
word_cfg("test3"),
|
|
||||||
word_cfg("test4"),
|
|
||||||
word_cfg("test5"),
|
|
||||||
word_cfg("test6"),
|
|
||||||
word_cfg("test7"),
|
|
||||||
]));
|
|
||||||
|
|
||||||
let mut y = Cfg::Any(vec![word_cfg("a"), word_cfg("b")]);
|
|
||||||
y &= x;
|
|
||||||
assert_eq!(y, Cfg::All(vec![
|
|
||||||
word_cfg("test3"),
|
|
||||||
word_cfg("test4"),
|
|
||||||
word_cfg("test5"),
|
|
||||||
word_cfg("test6"),
|
|
||||||
word_cfg("test7"),
|
|
||||||
Cfg::Any(vec![word_cfg("a"), word_cfg("b")]),
|
|
||||||
]));
|
|
||||||
|
|
||||||
assert_eq!(
|
|
||||||
word_cfg("a") & word_cfg("b") & word_cfg("c"),
|
|
||||||
Cfg::All(vec![word_cfg("a"), word_cfg("b"), word_cfg("c")])
|
|
||||||
);
|
|
||||||
})
|
|
||||||
}
|
|
||||||
|
|
||||||
#[test]
|
|
||||||
fn test_cfg_or() {
|
|
||||||
with_default_globals(|| {
|
|
||||||
let mut x = Cfg::True;
|
|
||||||
x |= Cfg::False;
|
|
||||||
assert_eq!(x, Cfg::True);
|
|
||||||
|
|
||||||
x = word_cfg("test");
|
|
||||||
x |= Cfg::True;
|
|
||||||
assert_eq!(x, Cfg::True);
|
|
||||||
|
|
||||||
x = word_cfg("test2");
|
|
||||||
x |= Cfg::False;
|
|
||||||
assert_eq!(x, word_cfg("test2"));
|
|
||||||
|
|
||||||
x = Cfg::False;
|
|
||||||
x |= word_cfg("test3");
|
|
||||||
assert_eq!(x, word_cfg("test3"));
|
|
||||||
|
|
||||||
x |= word_cfg("test4");
|
|
||||||
assert_eq!(x, Cfg::Any(vec![word_cfg("test3"), word_cfg("test4")]));
|
|
||||||
|
|
||||||
x |= word_cfg("test5");
|
|
||||||
assert_eq!(x, Cfg::Any(vec![word_cfg("test3"), word_cfg("test4"), word_cfg("test5")]));
|
|
||||||
|
|
||||||
x |= Cfg::Any(vec![word_cfg("test6"), word_cfg("test7")]);
|
|
||||||
assert_eq!(x, Cfg::Any(vec![
|
|
||||||
word_cfg("test3"),
|
|
||||||
word_cfg("test4"),
|
|
||||||
word_cfg("test5"),
|
|
||||||
word_cfg("test6"),
|
|
||||||
word_cfg("test7"),
|
|
||||||
]));
|
|
||||||
|
|
||||||
let mut y = Cfg::All(vec![word_cfg("a"), word_cfg("b")]);
|
|
||||||
y |= x;
|
|
||||||
assert_eq!(y, Cfg::Any(vec![
|
|
||||||
word_cfg("test3"),
|
|
||||||
word_cfg("test4"),
|
|
||||||
word_cfg("test5"),
|
|
||||||
word_cfg("test6"),
|
|
||||||
word_cfg("test7"),
|
|
||||||
Cfg::All(vec![word_cfg("a"), word_cfg("b")]),
|
|
||||||
]));
|
|
||||||
|
|
||||||
assert_eq!(
|
|
||||||
word_cfg("a") | word_cfg("b") | word_cfg("c"),
|
|
||||||
Cfg::Any(vec![word_cfg("a"), word_cfg("b"), word_cfg("c")])
|
|
||||||
);
|
|
||||||
})
|
|
||||||
}
|
|
||||||
|
|
||||||
#[test]
|
|
||||||
fn test_parse_ok() {
|
|
||||||
with_default_globals(|| {
|
|
||||||
let mi = dummy_meta_item_word("all");
|
|
||||||
assert_eq!(Cfg::parse(&mi), Ok(word_cfg("all")));
|
|
||||||
|
|
||||||
let mi = attr::mk_name_value_item_str(
|
|
||||||
Ident::from_str("all"),
|
|
||||||
dummy_spanned(Symbol::intern("done"))
|
|
||||||
);
|
|
||||||
assert_eq!(Cfg::parse(&mi), Ok(name_value_cfg("all", "done")));
|
|
||||||
|
|
||||||
let mi = dummy_meta_item_list!(all, [a, b]);
|
|
||||||
assert_eq!(Cfg::parse(&mi), Ok(word_cfg("a") & word_cfg("b")));
|
|
||||||
|
|
||||||
let mi = dummy_meta_item_list!(any, [a, b]);
|
|
||||||
assert_eq!(Cfg::parse(&mi), Ok(word_cfg("a") | word_cfg("b")));
|
|
||||||
|
|
||||||
let mi = dummy_meta_item_list!(not, [a]);
|
|
||||||
assert_eq!(Cfg::parse(&mi), Ok(!word_cfg("a")));
|
|
||||||
|
|
||||||
let mi = dummy_meta_item_list!(not, [
|
|
||||||
dummy_meta_item_list!(any, [
|
|
||||||
dummy_meta_item_word("a"),
|
|
||||||
dummy_meta_item_list!(all, [b, c]),
|
|
||||||
]),
|
|
||||||
]);
|
|
||||||
assert_eq!(Cfg::parse(&mi), Ok(!(word_cfg("a") | (word_cfg("b") & word_cfg("c")))));
|
|
||||||
|
|
||||||
let mi = dummy_meta_item_list!(all, [a, b, c]);
|
|
||||||
assert_eq!(Cfg::parse(&mi), Ok(word_cfg("a") & word_cfg("b") & word_cfg("c")));
|
|
||||||
})
|
|
||||||
}
|
|
||||||
|
|
||||||
#[test]
|
|
||||||
fn test_parse_err() {
|
|
||||||
with_default_globals(|| {
|
|
||||||
let mi = attr::mk_name_value_item(
|
|
||||||
DUMMY_SP,
|
|
||||||
Ident::from_str("foo"),
|
|
||||||
LitKind::Bool(false),
|
|
||||||
DUMMY_SP,
|
|
||||||
);
|
|
||||||
assert!(Cfg::parse(&mi).is_err());
|
|
||||||
|
|
||||||
let mi = dummy_meta_item_list!(not, [a, b]);
|
|
||||||
assert!(Cfg::parse(&mi).is_err());
|
|
||||||
|
|
||||||
let mi = dummy_meta_item_list!(not, []);
|
|
||||||
assert!(Cfg::parse(&mi).is_err());
|
|
||||||
|
|
||||||
let mi = dummy_meta_item_list!(foo, []);
|
|
||||||
assert!(Cfg::parse(&mi).is_err());
|
|
||||||
|
|
||||||
let mi = dummy_meta_item_list!(all, [
|
|
||||||
dummy_meta_item_list!(foo, []),
|
|
||||||
dummy_meta_item_word("b"),
|
|
||||||
]);
|
|
||||||
assert!(Cfg::parse(&mi).is_err());
|
|
||||||
|
|
||||||
let mi = dummy_meta_item_list!(any, [
|
|
||||||
dummy_meta_item_word("a"),
|
|
||||||
dummy_meta_item_list!(foo, []),
|
|
||||||
]);
|
|
||||||
assert!(Cfg::parse(&mi).is_err());
|
|
||||||
|
|
||||||
let mi = dummy_meta_item_list!(not, [
|
|
||||||
dummy_meta_item_list!(foo, []),
|
|
||||||
]);
|
|
||||||
assert!(Cfg::parse(&mi).is_err());
|
|
||||||
})
|
|
||||||
}
|
|
||||||
|
|
||||||
#[test]
|
|
||||||
fn test_render_short_html() {
|
|
||||||
with_default_globals(|| {
|
|
||||||
assert_eq!(
|
|
||||||
word_cfg("unix").render_short_html(),
|
|
||||||
"Unix"
|
|
||||||
);
|
|
||||||
assert_eq!(
|
|
||||||
name_value_cfg("target_os", "macos").render_short_html(),
|
|
||||||
"macOS"
|
|
||||||
);
|
|
||||||
assert_eq!(
|
|
||||||
name_value_cfg("target_pointer_width", "16").render_short_html(),
|
|
||||||
"16-bit"
|
|
||||||
);
|
|
||||||
assert_eq!(
|
|
||||||
name_value_cfg("target_endian", "little").render_short_html(),
|
|
||||||
"Little-endian"
|
|
||||||
);
|
|
||||||
assert_eq!(
|
|
||||||
(!word_cfg("windows")).render_short_html(),
|
|
||||||
"Non-Windows"
|
|
||||||
);
|
|
||||||
assert_eq!(
|
|
||||||
(word_cfg("unix") & word_cfg("windows")).render_short_html(),
|
|
||||||
"Unix and Windows"
|
|
||||||
);
|
|
||||||
assert_eq!(
|
|
||||||
(word_cfg("unix") | word_cfg("windows")).render_short_html(),
|
|
||||||
"Unix or Windows"
|
|
||||||
);
|
|
||||||
assert_eq!(
|
|
||||||
(
|
|
||||||
word_cfg("unix") & word_cfg("windows") & word_cfg("debug_assertions")
|
|
||||||
).render_short_html(),
|
|
||||||
"Unix and Windows and debug-assertions enabled"
|
|
||||||
);
|
|
||||||
assert_eq!(
|
|
||||||
(
|
|
||||||
word_cfg("unix") | word_cfg("windows") | word_cfg("debug_assertions")
|
|
||||||
).render_short_html(),
|
|
||||||
"Unix or Windows or debug-assertions enabled"
|
|
||||||
);
|
|
||||||
assert_eq!(
|
|
||||||
(
|
|
||||||
!(word_cfg("unix") | word_cfg("windows") | word_cfg("debug_assertions"))
|
|
||||||
).render_short_html(),
|
|
||||||
"Neither Unix nor Windows nor debug-assertions enabled"
|
|
||||||
);
|
|
||||||
assert_eq!(
|
|
||||||
(
|
|
||||||
(word_cfg("unix") & name_value_cfg("target_arch", "x86_64")) |
|
|
||||||
(word_cfg("windows") & name_value_cfg("target_pointer_width", "64"))
|
|
||||||
).render_short_html(),
|
|
||||||
"Unix and x86-64, or Windows and 64-bit"
|
|
||||||
);
|
|
||||||
assert_eq!(
|
|
||||||
(!(word_cfg("unix") & word_cfg("windows"))).render_short_html(),
|
|
||||||
"Not (Unix and Windows)"
|
|
||||||
);
|
|
||||||
assert_eq!(
|
|
||||||
(
|
|
||||||
(word_cfg("debug_assertions") | word_cfg("windows")) & word_cfg("unix")
|
|
||||||
).render_short_html(),
|
|
||||||
"(Debug-assertions enabled or Windows) and Unix"
|
|
||||||
);
|
|
||||||
assert_eq!(
|
|
||||||
name_value_cfg("target_feature", "sse2").render_short_html(),
|
|
||||||
"<code>sse2</code>"
|
|
||||||
);
|
|
||||||
assert_eq!(
|
|
||||||
(
|
|
||||||
name_value_cfg("target_arch", "x86_64") &
|
|
||||||
name_value_cfg("target_feature", "sse2")
|
|
||||||
).render_short_html(),
|
|
||||||
"x86-64 and <code>sse2</code>"
|
|
||||||
);
|
|
||||||
})
|
|
||||||
}
|
|
||||||
|
|
||||||
#[test]
|
|
||||||
fn test_render_long_html() {
|
|
||||||
with_default_globals(|| {
|
|
||||||
assert_eq!(
|
|
||||||
word_cfg("unix").render_long_html(),
|
|
||||||
"This is supported on <strong>Unix</strong> only."
|
|
||||||
);
|
|
||||||
assert_eq!(
|
|
||||||
name_value_cfg("target_os", "macos").render_long_html(),
|
|
||||||
"This is supported on <strong>macOS</strong> only."
|
|
||||||
);
|
|
||||||
assert_eq!(
|
|
||||||
name_value_cfg("target_pointer_width", "16").render_long_html(),
|
|
||||||
"This is supported on <strong>16-bit</strong> only."
|
|
||||||
);
|
|
||||||
assert_eq!(
|
|
||||||
name_value_cfg("target_endian", "little").render_long_html(),
|
|
||||||
"This is supported on <strong>little-endian</strong> only."
|
|
||||||
);
|
|
||||||
assert_eq!(
|
|
||||||
(!word_cfg("windows")).render_long_html(),
|
|
||||||
"This is supported on <strong>non-Windows</strong> only."
|
|
||||||
);
|
|
||||||
assert_eq!(
|
|
||||||
(word_cfg("unix") & word_cfg("windows")).render_long_html(),
|
|
||||||
"This is supported on <strong>Unix and Windows</strong> only."
|
|
||||||
);
|
|
||||||
assert_eq!(
|
|
||||||
(word_cfg("unix") | word_cfg("windows")).render_long_html(),
|
|
||||||
"This is supported on <strong>Unix or Windows</strong> only."
|
|
||||||
);
|
|
||||||
assert_eq!(
|
|
||||||
(
|
|
||||||
word_cfg("unix") & word_cfg("windows") & word_cfg("debug_assertions")
|
|
||||||
).render_long_html(),
|
|
||||||
"This is supported on <strong>Unix and Windows and debug-assertions enabled\
|
|
||||||
</strong> only."
|
|
||||||
);
|
|
||||||
assert_eq!(
|
|
||||||
(
|
|
||||||
word_cfg("unix") | word_cfg("windows") | word_cfg("debug_assertions")
|
|
||||||
).render_long_html(),
|
|
||||||
"This is supported on <strong>Unix or Windows or debug-assertions enabled\
|
|
||||||
</strong> only."
|
|
||||||
);
|
|
||||||
assert_eq!(
|
|
||||||
(
|
|
||||||
!(word_cfg("unix") | word_cfg("windows") | word_cfg("debug_assertions"))
|
|
||||||
).render_long_html(),
|
|
||||||
"This is supported on <strong>neither Unix nor Windows nor debug-assertions \
|
|
||||||
enabled</strong>."
|
|
||||||
);
|
|
||||||
assert_eq!(
|
|
||||||
(
|
|
||||||
(word_cfg("unix") & name_value_cfg("target_arch", "x86_64")) |
|
|
||||||
(word_cfg("windows") & name_value_cfg("target_pointer_width", "64"))
|
|
||||||
).render_long_html(),
|
|
||||||
"This is supported on <strong>Unix and x86-64, or Windows and 64-bit</strong> \
|
|
||||||
only."
|
|
||||||
);
|
|
||||||
assert_eq!(
|
|
||||||
(!(word_cfg("unix") & word_cfg("windows"))).render_long_html(),
|
|
||||||
"This is supported on <strong>not (Unix and Windows)</strong>."
|
|
||||||
);
|
|
||||||
assert_eq!(
|
|
||||||
(
|
|
||||||
(word_cfg("debug_assertions") | word_cfg("windows")) & word_cfg("unix")
|
|
||||||
).render_long_html(),
|
|
||||||
"This is supported on <strong>(debug-assertions enabled or Windows) and Unix\
|
|
||||||
</strong> only."
|
|
||||||
);
|
|
||||||
assert_eq!(
|
|
||||||
name_value_cfg("target_feature", "sse2").render_long_html(),
|
|
||||||
"This is supported with <strong>target feature <code>sse2</code></strong> only."
|
|
||||||
);
|
|
||||||
assert_eq!(
|
|
||||||
(
|
|
||||||
name_value_cfg("target_arch", "x86_64") &
|
|
||||||
name_value_cfg("target_feature", "sse2")
|
|
||||||
).render_long_html(),
|
|
||||||
"This is supported on <strong>x86-64 and target feature \
|
|
||||||
<code>sse2</code></strong> only."
|
|
||||||
);
|
|
||||||
})
|
|
||||||
}
|
|
||||||
}
|
|
||||||
|
|
|
@ -0,0 +1,413 @@
|
||||||
|
use super::*;
|
||||||
|
|
||||||
|
use syntax_pos::DUMMY_SP;
|
||||||
|
use syntax::ast::*;
|
||||||
|
use syntax::attr;
|
||||||
|
use syntax::source_map::dummy_spanned;
|
||||||
|
use syntax::symbol::Symbol;
|
||||||
|
use syntax::with_default_globals;
|
||||||
|
|
||||||
|
fn word_cfg(s: &str) -> Cfg {
|
||||||
|
Cfg::Cfg(Symbol::intern(s), None)
|
||||||
|
}
|
||||||
|
|
||||||
|
fn name_value_cfg(name: &str, value: &str) -> Cfg {
|
||||||
|
Cfg::Cfg(Symbol::intern(name), Some(Symbol::intern(value)))
|
||||||
|
}
|
||||||
|
|
||||||
|
fn dummy_meta_item_word(name: &str) -> MetaItem {
|
||||||
|
MetaItem {
|
||||||
|
path: Path::from_ident(Ident::from_str(name)),
|
||||||
|
node: MetaItemKind::Word,
|
||||||
|
span: DUMMY_SP,
|
||||||
|
}
|
||||||
|
}
|
||||||
|
|
||||||
|
macro_rules! dummy_meta_item_list {
|
||||||
|
($name:ident, [$($list:ident),* $(,)?]) => {
|
||||||
|
MetaItem {
|
||||||
|
path: Path::from_ident(Ident::from_str(stringify!($name))),
|
||||||
|
node: MetaItemKind::List(vec![
|
||||||
|
$(
|
||||||
|
NestedMetaItem::MetaItem(
|
||||||
|
dummy_meta_item_word(stringify!($list)),
|
||||||
|
),
|
||||||
|
)*
|
||||||
|
]),
|
||||||
|
span: DUMMY_SP,
|
||||||
|
}
|
||||||
|
};
|
||||||
|
|
||||||
|
($name:ident, [$($list:expr),* $(,)?]) => {
|
||||||
|
MetaItem {
|
||||||
|
path: Path::from_ident(Ident::from_str(stringify!($name))),
|
||||||
|
node: MetaItemKind::List(vec![
|
||||||
|
$(
|
||||||
|
NestedMetaItem::MetaItem($list),
|
||||||
|
)*
|
||||||
|
]),
|
||||||
|
span: DUMMY_SP,
|
||||||
|
}
|
||||||
|
};
|
||||||
|
}
|
||||||
|
|
||||||
|
#[test]
|
||||||
|
fn test_cfg_not() {
|
||||||
|
with_default_globals(|| {
|
||||||
|
assert_eq!(!Cfg::False, Cfg::True);
|
||||||
|
assert_eq!(!Cfg::True, Cfg::False);
|
||||||
|
assert_eq!(!word_cfg("test"), Cfg::Not(Box::new(word_cfg("test"))));
|
||||||
|
assert_eq!(
|
||||||
|
!Cfg::All(vec![word_cfg("a"), word_cfg("b")]),
|
||||||
|
Cfg::Not(Box::new(Cfg::All(vec![word_cfg("a"), word_cfg("b")])))
|
||||||
|
);
|
||||||
|
assert_eq!(
|
||||||
|
!Cfg::Any(vec![word_cfg("a"), word_cfg("b")]),
|
||||||
|
Cfg::Not(Box::new(Cfg::Any(vec![word_cfg("a"), word_cfg("b")])))
|
||||||
|
);
|
||||||
|
assert_eq!(!Cfg::Not(Box::new(word_cfg("test"))), word_cfg("test"));
|
||||||
|
})
|
||||||
|
}
|
||||||
|
|
||||||
|
#[test]
|
||||||
|
fn test_cfg_and() {
|
||||||
|
with_default_globals(|| {
|
||||||
|
let mut x = Cfg::False;
|
||||||
|
x &= Cfg::True;
|
||||||
|
assert_eq!(x, Cfg::False);
|
||||||
|
|
||||||
|
x = word_cfg("test");
|
||||||
|
x &= Cfg::False;
|
||||||
|
assert_eq!(x, Cfg::False);
|
||||||
|
|
||||||
|
x = word_cfg("test2");
|
||||||
|
x &= Cfg::True;
|
||||||
|
assert_eq!(x, word_cfg("test2"));
|
||||||
|
|
||||||
|
x = Cfg::True;
|
||||||
|
x &= word_cfg("test3");
|
||||||
|
assert_eq!(x, word_cfg("test3"));
|
||||||
|
|
||||||
|
x &= word_cfg("test4");
|
||||||
|
assert_eq!(x, Cfg::All(vec![word_cfg("test3"), word_cfg("test4")]));
|
||||||
|
|
||||||
|
x &= word_cfg("test5");
|
||||||
|
assert_eq!(x, Cfg::All(vec![word_cfg("test3"), word_cfg("test4"), word_cfg("test5")]));
|
||||||
|
|
||||||
|
x &= Cfg::All(vec![word_cfg("test6"), word_cfg("test7")]);
|
||||||
|
assert_eq!(x, Cfg::All(vec![
|
||||||
|
word_cfg("test3"),
|
||||||
|
word_cfg("test4"),
|
||||||
|
word_cfg("test5"),
|
||||||
|
word_cfg("test6"),
|
||||||
|
word_cfg("test7"),
|
||||||
|
]));
|
||||||
|
|
||||||
|
let mut y = Cfg::Any(vec![word_cfg("a"), word_cfg("b")]);
|
||||||
|
y &= x;
|
||||||
|
assert_eq!(y, Cfg::All(vec![
|
||||||
|
word_cfg("test3"),
|
||||||
|
word_cfg("test4"),
|
||||||
|
word_cfg("test5"),
|
||||||
|
word_cfg("test6"),
|
||||||
|
word_cfg("test7"),
|
||||||
|
Cfg::Any(vec![word_cfg("a"), word_cfg("b")]),
|
||||||
|
]));
|
||||||
|
|
||||||
|
assert_eq!(
|
||||||
|
word_cfg("a") & word_cfg("b") & word_cfg("c"),
|
||||||
|
Cfg::All(vec![word_cfg("a"), word_cfg("b"), word_cfg("c")])
|
||||||
|
);
|
||||||
|
})
|
||||||
|
}
|
||||||
|
|
||||||
|
#[test]
|
||||||
|
fn test_cfg_or() {
|
||||||
|
with_default_globals(|| {
|
||||||
|
let mut x = Cfg::True;
|
||||||
|
x |= Cfg::False;
|
||||||
|
assert_eq!(x, Cfg::True);
|
||||||
|
|
||||||
|
x = word_cfg("test");
|
||||||
|
x |= Cfg::True;
|
||||||
|
assert_eq!(x, Cfg::True);
|
||||||
|
|
||||||
|
x = word_cfg("test2");
|
||||||
|
x |= Cfg::False;
|
||||||
|
assert_eq!(x, word_cfg("test2"));
|
||||||
|
|
||||||
|
x = Cfg::False;
|
||||||
|
x |= word_cfg("test3");
|
||||||
|
assert_eq!(x, word_cfg("test3"));
|
||||||
|
|
||||||
|
x |= word_cfg("test4");
|
||||||
|
assert_eq!(x, Cfg::Any(vec![word_cfg("test3"), word_cfg("test4")]));
|
||||||
|
|
||||||
|
x |= word_cfg("test5");
|
||||||
|
assert_eq!(x, Cfg::Any(vec![word_cfg("test3"), word_cfg("test4"), word_cfg("test5")]));
|
||||||
|
|
||||||
|
x |= Cfg::Any(vec![word_cfg("test6"), word_cfg("test7")]);
|
||||||
|
assert_eq!(x, Cfg::Any(vec![
|
||||||
|
word_cfg("test3"),
|
||||||
|
word_cfg("test4"),
|
||||||
|
word_cfg("test5"),
|
||||||
|
word_cfg("test6"),
|
||||||
|
word_cfg("test7"),
|
||||||
|
]));
|
||||||
|
|
||||||
|
let mut y = Cfg::All(vec![word_cfg("a"), word_cfg("b")]);
|
||||||
|
y |= x;
|
||||||
|
assert_eq!(y, Cfg::Any(vec![
|
||||||
|
word_cfg("test3"),
|
||||||
|
word_cfg("test4"),
|
||||||
|
word_cfg("test5"),
|
||||||
|
word_cfg("test6"),
|
||||||
|
word_cfg("test7"),
|
||||||
|
Cfg::All(vec![word_cfg("a"), word_cfg("b")]),
|
||||||
|
]));
|
||||||
|
|
||||||
|
assert_eq!(
|
||||||
|
word_cfg("a") | word_cfg("b") | word_cfg("c"),
|
||||||
|
Cfg::Any(vec![word_cfg("a"), word_cfg("b"), word_cfg("c")])
|
||||||
|
);
|
||||||
|
})
|
||||||
|
}
|
||||||
|
|
||||||
|
#[test]
|
||||||
|
fn test_parse_ok() {
|
||||||
|
with_default_globals(|| {
|
||||||
|
let mi = dummy_meta_item_word("all");
|
||||||
|
assert_eq!(Cfg::parse(&mi), Ok(word_cfg("all")));
|
||||||
|
|
||||||
|
let mi = attr::mk_name_value_item_str(
|
||||||
|
Ident::from_str("all"),
|
||||||
|
dummy_spanned(Symbol::intern("done"))
|
||||||
|
);
|
||||||
|
assert_eq!(Cfg::parse(&mi), Ok(name_value_cfg("all", "done")));
|
||||||
|
|
||||||
|
let mi = dummy_meta_item_list!(all, [a, b]);
|
||||||
|
assert_eq!(Cfg::parse(&mi), Ok(word_cfg("a") & word_cfg("b")));
|
||||||
|
|
||||||
|
let mi = dummy_meta_item_list!(any, [a, b]);
|
||||||
|
assert_eq!(Cfg::parse(&mi), Ok(word_cfg("a") | word_cfg("b")));
|
||||||
|
|
||||||
|
let mi = dummy_meta_item_list!(not, [a]);
|
||||||
|
assert_eq!(Cfg::parse(&mi), Ok(!word_cfg("a")));
|
||||||
|
|
||||||
|
let mi = dummy_meta_item_list!(not, [
|
||||||
|
dummy_meta_item_list!(any, [
|
||||||
|
dummy_meta_item_word("a"),
|
||||||
|
dummy_meta_item_list!(all, [b, c]),
|
||||||
|
]),
|
||||||
|
]);
|
||||||
|
assert_eq!(Cfg::parse(&mi), Ok(!(word_cfg("a") | (word_cfg("b") & word_cfg("c")))));
|
||||||
|
|
||||||
|
let mi = dummy_meta_item_list!(all, [a, b, c]);
|
||||||
|
assert_eq!(Cfg::parse(&mi), Ok(word_cfg("a") & word_cfg("b") & word_cfg("c")));
|
||||||
|
})
|
||||||
|
}
|
||||||
|
|
||||||
|
#[test]
|
||||||
|
fn test_parse_err() {
|
||||||
|
with_default_globals(|| {
|
||||||
|
let mi = attr::mk_name_value_item(
|
||||||
|
DUMMY_SP,
|
||||||
|
Ident::from_str("foo"),
|
||||||
|
LitKind::Bool(false),
|
||||||
|
DUMMY_SP,
|
||||||
|
);
|
||||||
|
assert!(Cfg::parse(&mi).is_err());
|
||||||
|
|
||||||
|
let mi = dummy_meta_item_list!(not, [a, b]);
|
||||||
|
assert!(Cfg::parse(&mi).is_err());
|
||||||
|
|
||||||
|
let mi = dummy_meta_item_list!(not, []);
|
||||||
|
assert!(Cfg::parse(&mi).is_err());
|
||||||
|
|
||||||
|
let mi = dummy_meta_item_list!(foo, []);
|
||||||
|
assert!(Cfg::parse(&mi).is_err());
|
||||||
|
|
||||||
|
let mi = dummy_meta_item_list!(all, [
|
||||||
|
dummy_meta_item_list!(foo, []),
|
||||||
|
dummy_meta_item_word("b"),
|
||||||
|
]);
|
||||||
|
assert!(Cfg::parse(&mi).is_err());
|
||||||
|
|
||||||
|
let mi = dummy_meta_item_list!(any, [
|
||||||
|
dummy_meta_item_word("a"),
|
||||||
|
dummy_meta_item_list!(foo, []),
|
||||||
|
]);
|
||||||
|
assert!(Cfg::parse(&mi).is_err());
|
||||||
|
|
||||||
|
let mi = dummy_meta_item_list!(not, [
|
||||||
|
dummy_meta_item_list!(foo, []),
|
||||||
|
]);
|
||||||
|
assert!(Cfg::parse(&mi).is_err());
|
||||||
|
})
|
||||||
|
}
|
||||||
|
|
||||||
|
#[test]
|
||||||
|
fn test_render_short_html() {
|
||||||
|
with_default_globals(|| {
|
||||||
|
assert_eq!(
|
||||||
|
word_cfg("unix").render_short_html(),
|
||||||
|
"Unix"
|
||||||
|
);
|
||||||
|
assert_eq!(
|
||||||
|
name_value_cfg("target_os", "macos").render_short_html(),
|
||||||
|
"macOS"
|
||||||
|
);
|
||||||
|
assert_eq!(
|
||||||
|
name_value_cfg("target_pointer_width", "16").render_short_html(),
|
||||||
|
"16-bit"
|
||||||
|
);
|
||||||
|
assert_eq!(
|
||||||
|
name_value_cfg("target_endian", "little").render_short_html(),
|
||||||
|
"Little-endian"
|
||||||
|
);
|
||||||
|
assert_eq!(
|
||||||
|
(!word_cfg("windows")).render_short_html(),
|
||||||
|
"Non-Windows"
|
||||||
|
);
|
||||||
|
assert_eq!(
|
||||||
|
(word_cfg("unix") & word_cfg("windows")).render_short_html(),
|
||||||
|
"Unix and Windows"
|
||||||
|
);
|
||||||
|
assert_eq!(
|
||||||
|
(word_cfg("unix") | word_cfg("windows")).render_short_html(),
|
||||||
|
"Unix or Windows"
|
||||||
|
);
|
||||||
|
assert_eq!(
|
||||||
|
(
|
||||||
|
word_cfg("unix") & word_cfg("windows") & word_cfg("debug_assertions")
|
||||||
|
).render_short_html(),
|
||||||
|
"Unix and Windows and debug-assertions enabled"
|
||||||
|
);
|
||||||
|
assert_eq!(
|
||||||
|
(
|
||||||
|
word_cfg("unix") | word_cfg("windows") | word_cfg("debug_assertions")
|
||||||
|
).render_short_html(),
|
||||||
|
"Unix or Windows or debug-assertions enabled"
|
||||||
|
);
|
||||||
|
assert_eq!(
|
||||||
|
(
|
||||||
|
!(word_cfg("unix") | word_cfg("windows") | word_cfg("debug_assertions"))
|
||||||
|
).render_short_html(),
|
||||||
|
"Neither Unix nor Windows nor debug-assertions enabled"
|
||||||
|
);
|
||||||
|
assert_eq!(
|
||||||
|
(
|
||||||
|
(word_cfg("unix") & name_value_cfg("target_arch", "x86_64")) |
|
||||||
|
(word_cfg("windows") & name_value_cfg("target_pointer_width", "64"))
|
||||||
|
).render_short_html(),
|
||||||
|
"Unix and x86-64, or Windows and 64-bit"
|
||||||
|
);
|
||||||
|
assert_eq!(
|
||||||
|
(!(word_cfg("unix") & word_cfg("windows"))).render_short_html(),
|
||||||
|
"Not (Unix and Windows)"
|
||||||
|
);
|
||||||
|
assert_eq!(
|
||||||
|
(
|
||||||
|
(word_cfg("debug_assertions") | word_cfg("windows")) & word_cfg("unix")
|
||||||
|
).render_short_html(),
|
||||||
|
"(Debug-assertions enabled or Windows) and Unix"
|
||||||
|
);
|
||||||
|
assert_eq!(
|
||||||
|
name_value_cfg("target_feature", "sse2").render_short_html(),
|
||||||
|
"<code>sse2</code>"
|
||||||
|
);
|
||||||
|
assert_eq!(
|
||||||
|
(
|
||||||
|
name_value_cfg("target_arch", "x86_64") &
|
||||||
|
name_value_cfg("target_feature", "sse2")
|
||||||
|
).render_short_html(),
|
||||||
|
"x86-64 and <code>sse2</code>"
|
||||||
|
);
|
||||||
|
})
|
||||||
|
}
|
||||||
|
|
||||||
|
#[test]
|
||||||
|
fn test_render_long_html() {
|
||||||
|
with_default_globals(|| {
|
||||||
|
assert_eq!(
|
||||||
|
word_cfg("unix").render_long_html(),
|
||||||
|
"This is supported on <strong>Unix</strong> only."
|
||||||
|
);
|
||||||
|
assert_eq!(
|
||||||
|
name_value_cfg("target_os", "macos").render_long_html(),
|
||||||
|
"This is supported on <strong>macOS</strong> only."
|
||||||
|
);
|
||||||
|
assert_eq!(
|
||||||
|
name_value_cfg("target_pointer_width", "16").render_long_html(),
|
||||||
|
"This is supported on <strong>16-bit</strong> only."
|
||||||
|
);
|
||||||
|
assert_eq!(
|
||||||
|
name_value_cfg("target_endian", "little").render_long_html(),
|
||||||
|
"This is supported on <strong>little-endian</strong> only."
|
||||||
|
);
|
||||||
|
assert_eq!(
|
||||||
|
(!word_cfg("windows")).render_long_html(),
|
||||||
|
"This is supported on <strong>non-Windows</strong> only."
|
||||||
|
);
|
||||||
|
assert_eq!(
|
||||||
|
(word_cfg("unix") & word_cfg("windows")).render_long_html(),
|
||||||
|
"This is supported on <strong>Unix and Windows</strong> only."
|
||||||
|
);
|
||||||
|
assert_eq!(
|
||||||
|
(word_cfg("unix") | word_cfg("windows")).render_long_html(),
|
||||||
|
"This is supported on <strong>Unix or Windows</strong> only."
|
||||||
|
);
|
||||||
|
assert_eq!(
|
||||||
|
(
|
||||||
|
word_cfg("unix") & word_cfg("windows") & word_cfg("debug_assertions")
|
||||||
|
).render_long_html(),
|
||||||
|
"This is supported on <strong>Unix and Windows and debug-assertions enabled\
|
||||||
|
</strong> only."
|
||||||
|
);
|
||||||
|
assert_eq!(
|
||||||
|
(
|
||||||
|
word_cfg("unix") | word_cfg("windows") | word_cfg("debug_assertions")
|
||||||
|
).render_long_html(),
|
||||||
|
"This is supported on <strong>Unix or Windows or debug-assertions enabled\
|
||||||
|
</strong> only."
|
||||||
|
);
|
||||||
|
assert_eq!(
|
||||||
|
(
|
||||||
|
!(word_cfg("unix") | word_cfg("windows") | word_cfg("debug_assertions"))
|
||||||
|
).render_long_html(),
|
||||||
|
"This is supported on <strong>neither Unix nor Windows nor debug-assertions \
|
||||||
|
enabled</strong>."
|
||||||
|
);
|
||||||
|
assert_eq!(
|
||||||
|
(
|
||||||
|
(word_cfg("unix") & name_value_cfg("target_arch", "x86_64")) |
|
||||||
|
(word_cfg("windows") & name_value_cfg("target_pointer_width", "64"))
|
||||||
|
).render_long_html(),
|
||||||
|
"This is supported on <strong>Unix and x86-64, or Windows and 64-bit</strong> \
|
||||||
|
only."
|
||||||
|
);
|
||||||
|
assert_eq!(
|
||||||
|
(!(word_cfg("unix") & word_cfg("windows"))).render_long_html(),
|
||||||
|
"This is supported on <strong>not (Unix and Windows)</strong>."
|
||||||
|
);
|
||||||
|
assert_eq!(
|
||||||
|
(
|
||||||
|
(word_cfg("debug_assertions") | word_cfg("windows")) & word_cfg("unix")
|
||||||
|
).render_long_html(),
|
||||||
|
"This is supported on <strong>(debug-assertions enabled or Windows) and Unix\
|
||||||
|
</strong> only."
|
||||||
|
);
|
||||||
|
assert_eq!(
|
||||||
|
name_value_cfg("target_feature", "sse2").render_long_html(),
|
||||||
|
"This is supported with <strong>target feature <code>sse2</code></strong> only."
|
||||||
|
);
|
||||||
|
assert_eq!(
|
||||||
|
(
|
||||||
|
name_value_cfg("target_arch", "x86_64") &
|
||||||
|
name_value_cfg("target_feature", "sse2")
|
||||||
|
).render_long_html(),
|
||||||
|
"This is supported on <strong>x86-64 and target feature \
|
||||||
|
<code>sse2</code></strong> only."
|
||||||
|
);
|
||||||
|
})
|
||||||
|
}
|
|
@ -39,6 +39,9 @@ use crate::test;
|
||||||
|
|
||||||
use pulldown_cmark::{html, CowStr, Event, Options, Parser, Tag};
|
use pulldown_cmark::{html, CowStr, Event, Options, Parser, Tag};
|
||||||
|
|
||||||
|
#[cfg(test)]
|
||||||
|
mod tests;
|
||||||
|
|
||||||
fn opts() -> Options {
|
fn opts() -> Options {
|
||||||
Options::ENABLE_TABLES | Options::ENABLE_FOOTNOTES
|
Options::ENABLE_TABLES | Options::ENABLE_FOOTNOTES
|
||||||
}
|
}
|
||||||
|
@ -1032,27 +1035,3 @@ impl IdMap {
|
||||||
id
|
id
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
#[cfg(test)]
|
|
||||||
#[test]
|
|
||||||
fn test_unique_id() {
|
|
||||||
let input = ["foo", "examples", "examples", "method.into_iter","examples",
|
|
||||||
"method.into_iter", "foo", "main", "search", "methods",
|
|
||||||
"examples", "method.into_iter", "assoc_type.Item", "assoc_type.Item"];
|
|
||||||
let expected = ["foo", "examples", "examples-1", "method.into_iter", "examples-2",
|
|
||||||
"method.into_iter-1", "foo-1", "main", "search", "methods",
|
|
||||||
"examples-3", "method.into_iter-2", "assoc_type.Item", "assoc_type.Item-1"];
|
|
||||||
|
|
||||||
let map = RefCell::new(IdMap::new());
|
|
||||||
let test = || {
|
|
||||||
let mut map = map.borrow_mut();
|
|
||||||
let actual: Vec<String> = input.iter().map(|s| map.derive(s.to_string())).collect();
|
|
||||||
assert_eq!(&actual[..], expected);
|
|
||||||
};
|
|
||||||
test();
|
|
||||||
map.borrow_mut().reset();
|
|
||||||
test();
|
|
||||||
}
|
|
||||||
|
|
||||||
#[cfg(test)]
|
|
||||||
mod tests;
|
|
||||||
|
|
|
@ -3,6 +3,26 @@ use super::plain_summary_line;
|
||||||
use std::cell::RefCell;
|
use std::cell::RefCell;
|
||||||
use syntax::edition::{Edition, DEFAULT_EDITION};
|
use syntax::edition::{Edition, DEFAULT_EDITION};
|
||||||
|
|
||||||
|
#[test]
|
||||||
|
fn test_unique_id() {
|
||||||
|
let input = ["foo", "examples", "examples", "method.into_iter","examples",
|
||||||
|
"method.into_iter", "foo", "main", "search", "methods",
|
||||||
|
"examples", "method.into_iter", "assoc_type.Item", "assoc_type.Item"];
|
||||||
|
let expected = ["foo", "examples", "examples-1", "method.into_iter", "examples-2",
|
||||||
|
"method.into_iter-1", "foo-1", "main", "search", "methods",
|
||||||
|
"examples-3", "method.into_iter-2", "assoc_type.Item", "assoc_type.Item-1"];
|
||||||
|
|
||||||
|
let map = RefCell::new(IdMap::new());
|
||||||
|
let test = || {
|
||||||
|
let mut map = map.borrow_mut();
|
||||||
|
let actual: Vec<String> = input.iter().map(|s| map.derive(s.to_string())).collect();
|
||||||
|
assert_eq!(&actual[..], expected);
|
||||||
|
};
|
||||||
|
test();
|
||||||
|
map.borrow_mut().reset();
|
||||||
|
test();
|
||||||
|
}
|
||||||
|
|
||||||
#[test]
|
#[test]
|
||||||
fn test_lang_string_parse() {
|
fn test_lang_string_parse() {
|
||||||
fn t(s: &str,
|
fn t(s: &str,
|
||||||
|
|
|
@ -75,6 +75,9 @@ use crate::html::{highlight, layout, static_files};
|
||||||
|
|
||||||
use minifier;
|
use minifier;
|
||||||
|
|
||||||
|
#[cfg(test)]
|
||||||
|
mod tests;
|
||||||
|
|
||||||
/// A pair of name and its optional document.
|
/// A pair of name and its optional document.
|
||||||
pub type NameDoc = (String, Option<String>);
|
pub type NameDoc = (String, Option<String>);
|
||||||
|
|
||||||
|
@ -5238,33 +5241,3 @@ fn get_generics(clean_type: &clean::Type) -> Option<Vec<String>> {
|
||||||
pub fn cache() -> Arc<Cache> {
|
pub fn cache() -> Arc<Cache> {
|
||||||
CACHE_KEY.with(|c| c.borrow().clone())
|
CACHE_KEY.with(|c| c.borrow().clone())
|
||||||
}
|
}
|
||||||
|
|
||||||
#[cfg(test)]
|
|
||||||
#[test]
|
|
||||||
fn test_name_key() {
|
|
||||||
assert_eq!(name_key("0"), ("", 0, 1));
|
|
||||||
assert_eq!(name_key("123"), ("", 123, 0));
|
|
||||||
assert_eq!(name_key("Fruit"), ("Fruit", 0, 0));
|
|
||||||
assert_eq!(name_key("Fruit0"), ("Fruit", 0, 1));
|
|
||||||
assert_eq!(name_key("Fruit0000"), ("Fruit", 0, 4));
|
|
||||||
assert_eq!(name_key("Fruit01"), ("Fruit", 1, 1));
|
|
||||||
assert_eq!(name_key("Fruit10"), ("Fruit", 10, 0));
|
|
||||||
assert_eq!(name_key("Fruit123"), ("Fruit", 123, 0));
|
|
||||||
}
|
|
||||||
|
|
||||||
#[cfg(test)]
|
|
||||||
#[test]
|
|
||||||
fn test_name_sorting() {
|
|
||||||
let names = ["Apple",
|
|
||||||
"Banana",
|
|
||||||
"Fruit", "Fruit0", "Fruit00",
|
|
||||||
"Fruit1", "Fruit01",
|
|
||||||
"Fruit2", "Fruit02",
|
|
||||||
"Fruit20",
|
|
||||||
"Fruit30x",
|
|
||||||
"Fruit100",
|
|
||||||
"Pear"];
|
|
||||||
let mut sorted = names.to_owned();
|
|
||||||
sorted.sort_by_key(|&s| name_key(s));
|
|
||||||
assert_eq!(names, sorted);
|
|
||||||
}
|
|
||||||
|
|
|
@ -0,0 +1,29 @@
|
||||||
|
use super::*;
|
||||||
|
|
||||||
|
#[test]
|
||||||
|
fn test_name_key() {
|
||||||
|
assert_eq!(name_key("0"), ("", 0, 1));
|
||||||
|
assert_eq!(name_key("123"), ("", 123, 0));
|
||||||
|
assert_eq!(name_key("Fruit"), ("Fruit", 0, 0));
|
||||||
|
assert_eq!(name_key("Fruit0"), ("Fruit", 0, 1));
|
||||||
|
assert_eq!(name_key("Fruit0000"), ("Fruit", 0, 4));
|
||||||
|
assert_eq!(name_key("Fruit01"), ("Fruit", 1, 1));
|
||||||
|
assert_eq!(name_key("Fruit10"), ("Fruit", 10, 0));
|
||||||
|
assert_eq!(name_key("Fruit123"), ("Fruit", 123, 0));
|
||||||
|
}
|
||||||
|
|
||||||
|
#[test]
|
||||||
|
fn test_name_sorting() {
|
||||||
|
let names = ["Apple",
|
||||||
|
"Banana",
|
||||||
|
"Fruit", "Fruit0", "Fruit00",
|
||||||
|
"Fruit1", "Fruit01",
|
||||||
|
"Fruit2", "Fruit02",
|
||||||
|
"Fruit20",
|
||||||
|
"Fruit30x",
|
||||||
|
"Fruit100",
|
||||||
|
"Pear"];
|
||||||
|
let mut sorted = names.to_owned();
|
||||||
|
sorted.sort_by_key(|&s| name_key(s));
|
||||||
|
assert_eq!(names, sorted);
|
||||||
|
}
|
|
@ -7,6 +7,9 @@ use crate::core::DocContext;
|
||||||
use crate::fold::{self, DocFolder};
|
use crate::fold::{self, DocFolder};
|
||||||
use crate::passes::Pass;
|
use crate::passes::Pass;
|
||||||
|
|
||||||
|
#[cfg(test)]
|
||||||
|
mod tests;
|
||||||
|
|
||||||
pub const UNINDENT_COMMENTS: Pass = Pass {
|
pub const UNINDENT_COMMENTS: Pass = Pass {
|
||||||
name: "unindent-comments",
|
name: "unindent-comments",
|
||||||
pass: unindent_comments,
|
pass: unindent_comments,
|
||||||
|
@ -102,79 +105,3 @@ fn unindent(s: &str) -> String {
|
||||||
s.to_string()
|
s.to_string()
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
#[cfg(test)]
|
|
||||||
mod unindent_tests {
|
|
||||||
use super::unindent;
|
|
||||||
|
|
||||||
#[test]
|
|
||||||
fn should_unindent() {
|
|
||||||
let s = " line1\n line2".to_string();
|
|
||||||
let r = unindent(&s);
|
|
||||||
assert_eq!(r, "line1\nline2");
|
|
||||||
}
|
|
||||||
|
|
||||||
#[test]
|
|
||||||
fn should_unindent_multiple_paragraphs() {
|
|
||||||
let s = " line1\n\n line2".to_string();
|
|
||||||
let r = unindent(&s);
|
|
||||||
assert_eq!(r, "line1\n\nline2");
|
|
||||||
}
|
|
||||||
|
|
||||||
#[test]
|
|
||||||
fn should_leave_multiple_indent_levels() {
|
|
||||||
// Line 2 is indented another level beyond the
|
|
||||||
// base indentation and should be preserved
|
|
||||||
let s = " line1\n\n line2".to_string();
|
|
||||||
let r = unindent(&s);
|
|
||||||
assert_eq!(r, "line1\n\n line2");
|
|
||||||
}
|
|
||||||
|
|
||||||
#[test]
|
|
||||||
fn should_ignore_first_line_indent() {
|
|
||||||
// The first line of the first paragraph may not be indented as
|
|
||||||
// far due to the way the doc string was written:
|
|
||||||
//
|
|
||||||
// #[doc = "Start way over here
|
|
||||||
// and continue here"]
|
|
||||||
let s = "line1\n line2".to_string();
|
|
||||||
let r = unindent(&s);
|
|
||||||
assert_eq!(r, "line1\nline2");
|
|
||||||
}
|
|
||||||
|
|
||||||
#[test]
|
|
||||||
fn should_not_ignore_first_line_indent_in_a_single_line_para() {
|
|
||||||
let s = "line1\n\n line2".to_string();
|
|
||||||
let r = unindent(&s);
|
|
||||||
assert_eq!(r, "line1\n\n line2");
|
|
||||||
}
|
|
||||||
|
|
||||||
#[test]
|
|
||||||
fn should_unindent_tabs() {
|
|
||||||
let s = "\tline1\n\tline2".to_string();
|
|
||||||
let r = unindent(&s);
|
|
||||||
assert_eq!(r, "line1\nline2");
|
|
||||||
}
|
|
||||||
|
|
||||||
#[test]
|
|
||||||
fn should_trim_mixed_indentation() {
|
|
||||||
let s = "\t line1\n\t line2".to_string();
|
|
||||||
let r = unindent(&s);
|
|
||||||
assert_eq!(r, "line1\nline2");
|
|
||||||
|
|
||||||
let s = " \tline1\n \tline2".to_string();
|
|
||||||
let r = unindent(&s);
|
|
||||||
assert_eq!(r, "line1\nline2");
|
|
||||||
}
|
|
||||||
|
|
||||||
#[test]
|
|
||||||
fn should_not_trim() {
|
|
||||||
let s = "\t line1 \n\t line2".to_string();
|
|
||||||
let r = unindent(&s);
|
|
||||||
assert_eq!(r, "line1 \nline2");
|
|
||||||
|
|
||||||
let s = " \tline1 \n \tline2".to_string();
|
|
||||||
let r = unindent(&s);
|
|
||||||
assert_eq!(r, "line1 \nline2");
|
|
||||||
}
|
|
||||||
}
|
|
||||||
|
|
|
@ -0,0 +1,72 @@
|
||||||
|
use super::*;
|
||||||
|
|
||||||
|
#[test]
|
||||||
|
fn should_unindent() {
|
||||||
|
let s = " line1\n line2".to_string();
|
||||||
|
let r = unindent(&s);
|
||||||
|
assert_eq!(r, "line1\nline2");
|
||||||
|
}
|
||||||
|
|
||||||
|
#[test]
|
||||||
|
fn should_unindent_multiple_paragraphs() {
|
||||||
|
let s = " line1\n\n line2".to_string();
|
||||||
|
let r = unindent(&s);
|
||||||
|
assert_eq!(r, "line1\n\nline2");
|
||||||
|
}
|
||||||
|
|
||||||
|
#[test]
|
||||||
|
fn should_leave_multiple_indent_levels() {
|
||||||
|
// Line 2 is indented another level beyond the
|
||||||
|
// base indentation and should be preserved
|
||||||
|
let s = " line1\n\n line2".to_string();
|
||||||
|
let r = unindent(&s);
|
||||||
|
assert_eq!(r, "line1\n\n line2");
|
||||||
|
}
|
||||||
|
|
||||||
|
#[test]
|
||||||
|
fn should_ignore_first_line_indent() {
|
||||||
|
// The first line of the first paragraph may not be indented as
|
||||||
|
// far due to the way the doc string was written:
|
||||||
|
//
|
||||||
|
// #[doc = "Start way over here
|
||||||
|
// and continue here"]
|
||||||
|
let s = "line1\n line2".to_string();
|
||||||
|
let r = unindent(&s);
|
||||||
|
assert_eq!(r, "line1\nline2");
|
||||||
|
}
|
||||||
|
|
||||||
|
#[test]
|
||||||
|
fn should_not_ignore_first_line_indent_in_a_single_line_para() {
|
||||||
|
let s = "line1\n\n line2".to_string();
|
||||||
|
let r = unindent(&s);
|
||||||
|
assert_eq!(r, "line1\n\n line2");
|
||||||
|
}
|
||||||
|
|
||||||
|
#[test]
|
||||||
|
fn should_unindent_tabs() {
|
||||||
|
let s = "\tline1\n\tline2".to_string();
|
||||||
|
let r = unindent(&s);
|
||||||
|
assert_eq!(r, "line1\nline2");
|
||||||
|
}
|
||||||
|
|
||||||
|
#[test]
|
||||||
|
fn should_trim_mixed_indentation() {
|
||||||
|
let s = "\t line1\n\t line2".to_string();
|
||||||
|
let r = unindent(&s);
|
||||||
|
assert_eq!(r, "line1\nline2");
|
||||||
|
|
||||||
|
let s = " \tline1\n \tline2".to_string();
|
||||||
|
let r = unindent(&s);
|
||||||
|
assert_eq!(r, "line1\nline2");
|
||||||
|
}
|
||||||
|
|
||||||
|
#[test]
|
||||||
|
fn should_not_trim() {
|
||||||
|
let s = "\t line1 \n\t line2".to_string();
|
||||||
|
let r = unindent(&s);
|
||||||
|
assert_eq!(r, "line1 \nline2");
|
||||||
|
|
||||||
|
let s = " \tline1 \n \tline2".to_string();
|
||||||
|
let r = unindent(&s);
|
||||||
|
assert_eq!(r, "line1 \nline2");
|
||||||
|
}
|
|
@ -5,6 +5,9 @@ use std::path::Path;
|
||||||
|
|
||||||
use errors::Handler;
|
use errors::Handler;
|
||||||
|
|
||||||
|
#[cfg(test)]
|
||||||
|
mod tests;
|
||||||
|
|
||||||
macro_rules! try_something {
|
macro_rules! try_something {
|
||||||
($e:expr, $diag:expr, $out:expr) => ({
|
($e:expr, $diag:expr, $out:expr) => ({
|
||||||
match $e {
|
match $e {
|
||||||
|
@ -275,109 +278,3 @@ pub fn test_theme_against<P: AsRef<Path>>(
|
||||||
get_differences(against, &paths, &mut ret);
|
get_differences(against, &paths, &mut ret);
|
||||||
(true, ret)
|
(true, ret)
|
||||||
}
|
}
|
||||||
|
|
||||||
#[cfg(test)]
|
|
||||||
mod test {
|
|
||||||
use super::*;
|
|
||||||
|
|
||||||
#[test]
|
|
||||||
fn test_comments_in_rules() {
|
|
||||||
let text = r#"
|
|
||||||
rule a {}
|
|
||||||
|
|
||||||
rule b, c
|
|
||||||
// a line comment
|
|
||||||
{}
|
|
||||||
|
|
||||||
rule d
|
|
||||||
// another line comment
|
|
||||||
e {}
|
|
||||||
|
|
||||||
rule f/* a multine
|
|
||||||
|
|
||||||
comment*/{}
|
|
||||||
|
|
||||||
rule g/* another multine
|
|
||||||
|
|
||||||
comment*/h
|
|
||||||
|
|
||||||
i {}
|
|
||||||
|
|
||||||
rule j/*commeeeeent
|
|
||||||
|
|
||||||
you like things like "{}" in there? :)
|
|
||||||
*/
|
|
||||||
end {}"#;
|
|
||||||
|
|
||||||
let against = r#"
|
|
||||||
rule a {}
|
|
||||||
|
|
||||||
rule b, c {}
|
|
||||||
|
|
||||||
rule d e {}
|
|
||||||
|
|
||||||
rule f {}
|
|
||||||
|
|
||||||
rule gh i {}
|
|
||||||
|
|
||||||
rule j end {}
|
|
||||||
"#;
|
|
||||||
|
|
||||||
let mut ret = Vec::new();
|
|
||||||
get_differences(&load_css_paths(against.as_bytes()),
|
|
||||||
&load_css_paths(text.as_bytes()),
|
|
||||||
&mut ret);
|
|
||||||
assert!(ret.is_empty());
|
|
||||||
}
|
|
||||||
|
|
||||||
#[test]
|
|
||||||
fn test_text() {
|
|
||||||
let text = r#"
|
|
||||||
a
|
|
||||||
/* sdfs
|
|
||||||
*/ b
|
|
||||||
c // sdf
|
|
||||||
d {}
|
|
||||||
"#;
|
|
||||||
let paths = load_css_paths(text.as_bytes());
|
|
||||||
assert!(paths.children.contains(&CssPath::new("a b c d".to_owned())));
|
|
||||||
}
|
|
||||||
|
|
||||||
#[test]
|
|
||||||
fn test_comparison() {
|
|
||||||
let x = r#"
|
|
||||||
a {
|
|
||||||
b {
|
|
||||||
c {}
|
|
||||||
}
|
|
||||||
}
|
|
||||||
"#;
|
|
||||||
|
|
||||||
let y = r#"
|
|
||||||
a {
|
|
||||||
b {}
|
|
||||||
}
|
|
||||||
"#;
|
|
||||||
|
|
||||||
let against = load_css_paths(y.as_bytes());
|
|
||||||
let other = load_css_paths(x.as_bytes());
|
|
||||||
|
|
||||||
let mut ret = Vec::new();
|
|
||||||
get_differences(&against, &other, &mut ret);
|
|
||||||
assert!(ret.is_empty());
|
|
||||||
get_differences(&other, &against, &mut ret);
|
|
||||||
assert_eq!(ret, vec![" Missing \"c\" rule".to_owned()]);
|
|
||||||
}
|
|
||||||
|
|
||||||
#[test]
|
|
||||||
fn check_empty_css() {
|
|
||||||
let events = load_css_events(&[]);
|
|
||||||
assert_eq!(events.len(), 0);
|
|
||||||
}
|
|
||||||
|
|
||||||
#[test]
|
|
||||||
fn check_invalid_css() {
|
|
||||||
let events = load_css_events(b"*");
|
|
||||||
assert_eq!(events.len(), 0);
|
|
||||||
}
|
|
||||||
}
|
|
||||||
|
|
|
@ -0,0 +1,102 @@
|
||||||
|
use super::*;
|
||||||
|
|
||||||
|
#[test]
|
||||||
|
fn test_comments_in_rules() {
|
||||||
|
let text = r#"
|
||||||
|
rule a {}
|
||||||
|
|
||||||
|
rule b, c
|
||||||
|
// a line comment
|
||||||
|
{}
|
||||||
|
|
||||||
|
rule d
|
||||||
|
// another line comment
|
||||||
|
e {}
|
||||||
|
|
||||||
|
rule f/* a multine
|
||||||
|
|
||||||
|
comment*/{}
|
||||||
|
|
||||||
|
rule g/* another multine
|
||||||
|
|
||||||
|
comment*/h
|
||||||
|
|
||||||
|
i {}
|
||||||
|
|
||||||
|
rule j/*commeeeeent
|
||||||
|
|
||||||
|
you like things like "{}" in there? :)
|
||||||
|
*/
|
||||||
|
end {}"#;
|
||||||
|
|
||||||
|
let against = r#"
|
||||||
|
rule a {}
|
||||||
|
|
||||||
|
rule b, c {}
|
||||||
|
|
||||||
|
rule d e {}
|
||||||
|
|
||||||
|
rule f {}
|
||||||
|
|
||||||
|
rule gh i {}
|
||||||
|
|
||||||
|
rule j end {}
|
||||||
|
"#;
|
||||||
|
|
||||||
|
let mut ret = Vec::new();
|
||||||
|
get_differences(&load_css_paths(against.as_bytes()),
|
||||||
|
&load_css_paths(text.as_bytes()),
|
||||||
|
&mut ret);
|
||||||
|
assert!(ret.is_empty());
|
||||||
|
}
|
||||||
|
|
||||||
|
#[test]
|
||||||
|
fn test_text() {
|
||||||
|
let text = r#"
|
||||||
|
a
|
||||||
|
/* sdfs
|
||||||
|
*/ b
|
||||||
|
c // sdf
|
||||||
|
d {}
|
||||||
|
"#;
|
||||||
|
let paths = load_css_paths(text.as_bytes());
|
||||||
|
assert!(paths.children.contains(&CssPath::new("a b c d".to_owned())));
|
||||||
|
}
|
||||||
|
|
||||||
|
#[test]
|
||||||
|
fn test_comparison() {
|
||||||
|
let x = r#"
|
||||||
|
a {
|
||||||
|
b {
|
||||||
|
c {}
|
||||||
|
}
|
||||||
|
}
|
||||||
|
"#;
|
||||||
|
|
||||||
|
let y = r#"
|
||||||
|
a {
|
||||||
|
b {}
|
||||||
|
}
|
||||||
|
"#;
|
||||||
|
|
||||||
|
let against = load_css_paths(y.as_bytes());
|
||||||
|
let other = load_css_paths(x.as_bytes());
|
||||||
|
|
||||||
|
let mut ret = Vec::new();
|
||||||
|
get_differences(&against, &other, &mut ret);
|
||||||
|
assert!(ret.is_empty());
|
||||||
|
get_differences(&other, &against, &mut ret);
|
||||||
|
assert_eq!(ret, vec![" Missing \"c\" rule".to_owned()]);
|
||||||
|
}
|
||||||
|
|
||||||
|
#[test]
|
||||||
|
fn check_empty_css() {
|
||||||
|
let events = load_css_events(&[]);
|
||||||
|
assert_eq!(events.len(), 0);
|
||||||
|
}
|
||||||
|
|
||||||
|
#[test]
|
||||||
|
fn check_invalid_css() {
|
||||||
|
let events = load_css_events(b"*");
|
||||||
|
assert_eq!(events.len(), 0);
|
||||||
|
}
|
|
@ -27,7 +27,6 @@ pub fn check(root_path: &Path, bad: &mut bool) {
|
||||||
};
|
};
|
||||||
let fixme = [
|
let fixme = [
|
||||||
"liballoc",
|
"liballoc",
|
||||||
"librustdoc",
|
|
||||||
"libstd",
|
"libstd",
|
||||||
"libsyntax",
|
"libsyntax",
|
||||||
];
|
];
|
||||||
|
|
Loading…
Reference in New Issue