Unnamed repository; edit this file 'description' to name the repository.
Diffstat (limited to 'crates/cfg/src/tests.rs')
-rw-r--r--crates/cfg/src/tests.rs56
1 files changed, 34 insertions, 22 deletions
diff --git a/crates/cfg/src/tests.rs b/crates/cfg/src/tests.rs
index dddaf2cce1..597023a792 100644
--- a/crates/cfg/src/tests.rs
+++ b/crates/cfg/src/tests.rs
@@ -1,5 +1,6 @@
use arbitrary::{Arbitrary, Unstructured};
use expect_test::{expect, Expect};
+use intern::Symbol;
use mbe::{syntax_node_to_token_tree, DocCommentDesugarMode, DummyTestSpanMap, DUMMY};
use syntax::{ast, AstNode, Edition};
@@ -28,7 +29,7 @@ fn check_dnf(input: &str, expect: Expect) {
DocCommentDesugarMode::ProcMacro,
);
let cfg = CfgExpr::parse(&tt);
- let actual = format!("#![cfg({})]", DnfExpr::new(cfg));
+ let actual = format!("#![cfg({})]", DnfExpr::new(&cfg));
expect.assert_eq(&actual);
}
@@ -42,7 +43,7 @@ fn check_why_inactive(input: &str, opts: &CfgOptions, expect: Expect) {
DocCommentDesugarMode::ProcMacro,
);
let cfg = CfgExpr::parse(&tt);
- let dnf = DnfExpr::new(cfg);
+ let dnf = DnfExpr::new(&cfg);
let why_inactive = dnf.why_inactive(opts).unwrap().to_string();
expect.assert_eq(&why_inactive);
}
@@ -58,40 +59,51 @@ fn check_enable_hints(input: &str, opts: &CfgOptions, expected_hints: &[&str]) {
DocCommentDesugarMode::ProcMacro,
);
let cfg = CfgExpr::parse(&tt);
- let dnf = DnfExpr::new(cfg);
+ let dnf = DnfExpr::new(&cfg);
let hints = dnf.compute_enable_hints(opts).map(|diff| diff.to_string()).collect::<Vec<_>>();
assert_eq!(hints, expected_hints);
}
#[test]
fn test_cfg_expr_parser() {
- assert_parse_result("#![cfg(foo)]", CfgAtom::Flag("foo".into()).into());
- assert_parse_result("#![cfg(foo,)]", CfgAtom::Flag("foo".into()).into());
+ assert_parse_result("#![cfg(foo)]", CfgAtom::Flag(Symbol::intern("foo")).into());
+ assert_parse_result("#![cfg(foo,)]", CfgAtom::Flag(Symbol::intern("foo")).into());
assert_parse_result(
"#![cfg(not(foo))]",
- CfgExpr::Not(Box::new(CfgAtom::Flag("foo".into()).into())),
+ CfgExpr::Not(Box::new(CfgAtom::Flag(Symbol::intern("foo")).into())),
);
assert_parse_result("#![cfg(foo(bar))]", CfgExpr::Invalid);
// Only take the first
- assert_parse_result(r#"#![cfg(foo, bar = "baz")]"#, CfgAtom::Flag("foo".into()).into());
+ assert_parse_result(
+ r#"#![cfg(foo, bar = "baz")]"#,
+ CfgAtom::Flag(Symbol::intern("foo")).into(),
+ );
assert_parse_result(
r#"#![cfg(all(foo, bar = "baz"))]"#,
- CfgExpr::All(vec![
- CfgAtom::Flag("foo".into()).into(),
- CfgAtom::KeyValue { key: "bar".into(), value: "baz".into() }.into(),
- ]),
+ CfgExpr::All(
+ vec![
+ CfgAtom::Flag(Symbol::intern("foo")).into(),
+ CfgAtom::KeyValue { key: Symbol::intern("bar"), value: Symbol::intern("baz") }
+ .into(),
+ ]
+ .into_boxed_slice(),
+ ),
);
assert_parse_result(
r#"#![cfg(any(not(), all(), , bar = "baz",))]"#,
- CfgExpr::Any(vec![
- CfgExpr::Not(Box::new(CfgExpr::Invalid)),
- CfgExpr::All(vec![]),
- CfgExpr::Invalid,
- CfgAtom::KeyValue { key: "bar".into(), value: "baz".into() }.into(),
- ]),
+ CfgExpr::Any(
+ vec![
+ CfgExpr::Not(Box::new(CfgExpr::Invalid)),
+ CfgExpr::All(Box::new([])),
+ CfgExpr::Invalid,
+ CfgAtom::KeyValue { key: Symbol::intern("bar"), value: Symbol::intern("baz") }
+ .into(),
+ ]
+ .into_boxed_slice(),
+ ),
);
}
@@ -167,7 +179,7 @@ fn hints() {
check_enable_hints("#![cfg(all(a, b))]", &opts, &["enable a and b"]);
- opts.insert_atom("test".into());
+ opts.insert_atom(Symbol::intern("test"));
check_enable_hints("#![cfg(test)]", &opts, &[]);
check_enable_hints("#![cfg(not(test))]", &opts, &["disable test"]);
@@ -180,7 +192,7 @@ fn hints_impossible() {
check_enable_hints("#![cfg(all(test, not(test)))]", &opts, &[]);
- opts.insert_atom("test".into());
+ opts.insert_atom(Symbol::intern("test"));
check_enable_hints("#![cfg(all(test, not(test)))]", &opts, &[]);
}
@@ -188,8 +200,8 @@ fn hints_impossible() {
#[test]
fn why_inactive() {
let mut opts = CfgOptions::default();
- opts.insert_atom("test".into());
- opts.insert_atom("test2".into());
+ opts.insert_atom(Symbol::intern("test"));
+ opts.insert_atom(Symbol::intern("test2"));
check_why_inactive("#![cfg(a)]", &opts, expect![["a is disabled"]]);
check_why_inactive("#![cfg(not(test))]", &opts, expect![["test is enabled"]]);
@@ -231,6 +243,6 @@ fn proptest() {
let mut u = Unstructured::new(&buf);
let cfg = CfgExpr::arbitrary(&mut u).unwrap();
- DnfExpr::new(cfg);
+ DnfExpr::new(&cfg);
}
}