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.rs40
1 files changed, 14 insertions, 26 deletions
diff --git a/crates/cfg/src/tests.rs b/crates/cfg/src/tests.rs
index 0ea176858c..61cdbded0b 100644
--- a/crates/cfg/src/tests.rs
+++ b/crates/cfg/src/tests.rs
@@ -1,12 +1,12 @@
use arbitrary::{Arbitrary, Unstructured};
use expect_test::{expect, Expect};
-use mbe::syntax_node_to_token_tree;
+use mbe::{syntax_node_to_token_tree, SpanMapper};
use syntax::{ast, AstNode};
use tt::{SpanAnchor, SyntaxContext};
use crate::{CfgAtom, CfgExpr, CfgOptions, DnfExpr};
-#[derive(Debug, Copy, Clone, PartialEq, Eq)]
+#[derive(Debug, Copy, Clone, PartialEq, Eq, Hash)]
struct DummyFile;
impl SpanAnchor for DummyFile {
const DUMMY: Self = DummyFile;
@@ -17,15 +17,18 @@ impl SyntaxContext for DummyCtx {
const DUMMY: Self = DummyCtx;
}
+struct NoOpMap;
+
+impl SpanMapper<tt::SpanData<DummyFile, DummyCtx>> for NoOpMap {
+ fn span_for(&self, range: syntax::TextRange) -> tt::SpanData<DummyFile, DummyCtx> {
+ tt::SpanData { range, anchor: DummyFile, ctx: DummyCtx }
+ }
+}
+
fn assert_parse_result(input: &str, expected: CfgExpr) {
let source_file = ast::SourceFile::parse(input).ok().unwrap();
let tt = source_file.syntax().descendants().find_map(ast::TokenTree::cast).unwrap();
- let tt = syntax_node_to_token_tree::<_, DummyCtx>(
- tt.syntax(),
- DummyFile,
- 0.into(),
- &Default::default(),
- );
+ let tt = syntax_node_to_token_tree(tt.syntax(), NoOpMap);
let cfg = CfgExpr::parse(&tt);
assert_eq!(cfg, expected);
}
@@ -33,12 +36,7 @@ fn assert_parse_result(input: &str, expected: CfgExpr) {
fn check_dnf(input: &str, expect: Expect) {
let source_file = ast::SourceFile::parse(input).ok().unwrap();
let tt = source_file.syntax().descendants().find_map(ast::TokenTree::cast).unwrap();
- let tt = syntax_node_to_token_tree::<_, DummyCtx>(
- tt.syntax(),
- DummyFile,
- 0.into(),
- &Default::default(),
- );
+ let tt = syntax_node_to_token_tree(tt.syntax(), NoOpMap);
let cfg = CfgExpr::parse(&tt);
let actual = format!("#![cfg({})]", DnfExpr::new(cfg));
expect.assert_eq(&actual);
@@ -47,12 +45,7 @@ fn check_dnf(input: &str, expect: Expect) {
fn check_why_inactive(input: &str, opts: &CfgOptions, expect: Expect) {
let source_file = ast::SourceFile::parse(input).ok().unwrap();
let tt = source_file.syntax().descendants().find_map(ast::TokenTree::cast).unwrap();
- let tt = syntax_node_to_token_tree::<_, DummyCtx>(
- tt.syntax(),
- DummyFile,
- 0.into(),
- &Default::default(),
- );
+ let tt = syntax_node_to_token_tree(tt.syntax(), NoOpMap);
let cfg = CfgExpr::parse(&tt);
let dnf = DnfExpr::new(cfg);
let why_inactive = dnf.why_inactive(opts).unwrap().to_string();
@@ -63,12 +56,7 @@ fn check_why_inactive(input: &str, opts: &CfgOptions, expect: Expect) {
fn check_enable_hints(input: &str, opts: &CfgOptions, expected_hints: &[&str]) {
let source_file = ast::SourceFile::parse(input).ok().unwrap();
let tt = source_file.syntax().descendants().find_map(ast::TokenTree::cast).unwrap();
- let tt = syntax_node_to_token_tree::<_, DummyCtx>(
- tt.syntax(),
- DummyFile,
- 0.into(),
- &Default::default(),
- );
+ let tt = syntax_node_to_token_tree(tt.syntax(), NoOpMap);
let cfg = CfgExpr::parse(&tt);
let dnf = DnfExpr::new(cfg);
let hints = dnf.compute_enable_hints(opts).map(|diff| diff.to_string()).collect::<Vec<_>>();