diff options
author | Jonas Schievink <[email protected]> | 2020-10-23 11:14:58 +0100 |
---|---|---|
committer | Jonas Schievink <[email protected]> | 2020-10-23 11:14:58 +0100 |
commit | a246d4f599dcf2612fa99720fb4ca98101ed93fb (patch) | |
tree | 5972eedd06b94860d1c87a6711766377585a04b5 /crates/cfg/src/cfg_expr.rs | |
parent | dab8870f5c6d90ea1a327037825dc87a46778045 (diff) |
cfg: move tests to separate file
that way we don't have to re-check the entire project when a test is
changed
Diffstat (limited to 'crates/cfg/src/cfg_expr.rs')
-rw-r--r-- | crates/cfg/src/cfg_expr.rs | 50 |
1 files changed, 0 insertions, 50 deletions
diff --git a/crates/cfg/src/cfg_expr.rs b/crates/cfg/src/cfg_expr.rs index 283ff968f..42327f1e1 100644 --- a/crates/cfg/src/cfg_expr.rs +++ b/crates/cfg/src/cfg_expr.rs | |||
@@ -128,53 +128,3 @@ fn next_cfg_expr(it: &mut SliceIter<tt::TokenTree>) -> Option<CfgExpr> { | |||
128 | } | 128 | } |
129 | Some(ret) | 129 | Some(ret) |
130 | } | 130 | } |
131 | |||
132 | #[cfg(test)] | ||
133 | mod tests { | ||
134 | use super::*; | ||
135 | |||
136 | use mbe::ast_to_token_tree; | ||
137 | use syntax::ast::{self, AstNode}; | ||
138 | |||
139 | fn assert_parse_result(input: &str, expected: CfgExpr) { | ||
140 | let (tt, _) = { | ||
141 | let source_file = ast::SourceFile::parse(input).ok().unwrap(); | ||
142 | let tt = source_file.syntax().descendants().find_map(ast::TokenTree::cast).unwrap(); | ||
143 | ast_to_token_tree(&tt).unwrap() | ||
144 | }; | ||
145 | let cfg = CfgExpr::parse(&tt); | ||
146 | assert_eq!(cfg, expected); | ||
147 | } | ||
148 | |||
149 | #[test] | ||
150 | fn test_cfg_expr_parser() { | ||
151 | assert_parse_result("#![cfg(foo)]", CfgAtom::Flag("foo".into()).into()); | ||
152 | assert_parse_result("#![cfg(foo,)]", CfgAtom::Flag("foo".into()).into()); | ||
153 | assert_parse_result( | ||
154 | "#![cfg(not(foo))]", | ||
155 | CfgExpr::Not(Box::new(CfgAtom::Flag("foo".into()).into())), | ||
156 | ); | ||
157 | assert_parse_result("#![cfg(foo(bar))]", CfgExpr::Invalid); | ||
158 | |||
159 | // Only take the first | ||
160 | assert_parse_result(r#"#![cfg(foo, bar = "baz")]"#, CfgAtom::Flag("foo".into()).into()); | ||
161 | |||
162 | assert_parse_result( | ||
163 | r#"#![cfg(all(foo, bar = "baz"))]"#, | ||
164 | CfgExpr::All(vec![ | ||
165 | CfgAtom::Flag("foo".into()).into(), | ||
166 | CfgAtom::KeyValue { key: "bar".into(), value: "baz".into() }.into(), | ||
167 | ]), | ||
168 | ); | ||
169 | |||
170 | assert_parse_result( | ||
171 | r#"#![cfg(any(not(), all(), , bar = "baz",))]"#, | ||
172 | CfgExpr::Any(vec![ | ||
173 | CfgExpr::Not(Box::new(CfgExpr::Invalid)), | ||
174 | CfgExpr::All(vec![]), | ||
175 | CfgExpr::Invalid, | ||
176 | CfgAtom::KeyValue { key: "bar".into(), value: "baz".into() }.into(), | ||
177 | ]), | ||
178 | ); | ||
179 | } | ||
180 | } | ||