mirror of
https://github.com/rust-lang/rust-analyzer.git
synced 2025-09-28 04:44:57 +00:00
Use symbol in cfg
This commit is contained in:
parent
93024ad411
commit
c30bdfcc84
22 changed files with 147 additions and 92 deletions
|
@ -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};
|
||||
|
||||
|
@ -65,22 +66,25 @@ fn check_enable_hints(input: &str, opts: &CfgOptions, expected_hints: &[&str]) {
|
|||
|
||||
#[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(),
|
||||
CfgAtom::Flag(Symbol::intern("foo")).into(),
|
||||
CfgAtom::KeyValue { key: Symbol::intern("bar"), value: Symbol::intern("baz") }.into(),
|
||||
]),
|
||||
);
|
||||
|
||||
|
@ -90,7 +94,7 @@ fn test_cfg_expr_parser() {
|
|||
CfgExpr::Not(Box::new(CfgExpr::Invalid)),
|
||||
CfgExpr::All(vec![]),
|
||||
CfgExpr::Invalid,
|
||||
CfgAtom::KeyValue { key: "bar".into(), value: "baz".into() }.into(),
|
||||
CfgAtom::KeyValue { key: Symbol::intern("bar"), value: Symbol::intern("baz") }.into(),
|
||||
]),
|
||||
);
|
||||
}
|
||||
|
@ -167,7 +171,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 +184,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 +192,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"]]);
|
||||
|
|
Loading…
Add table
Add a link
Reference in a new issue