From 05daa86634b41aa3f311a1ac0b02bf7fed7ed569 Mon Sep 17 00:00:00 2001 From: Jan Jansen Date: Thu, 27 Dec 2018 21:45:16 +0100 Subject: Make modules with tests runnable Fixes #154 --- crates/ra_editor/src/lib.rs | 60 +-------------------------------------------- 1 file changed, 1 insertion(+), 59 deletions(-) (limited to 'crates/ra_editor/src') diff --git a/crates/ra_editor/src/lib.rs b/crates/ra_editor/src/lib.rs index a65637d52..412b8aea9 100644 --- a/crates/ra_editor/src/lib.rs +++ b/crates/ra_editor/src/lib.rs @@ -22,7 +22,7 @@ pub use self::{ use ra_text_edit::{TextEdit, TextEditBuilder}; use ra_syntax::{ algo::find_leaf_at_offset, - ast::{self, AstNode, NameOwner}, + ast::{self, AstNode}, SourceFileNode, SyntaxKind::{self, *}, SyntaxNodeRef, TextRange, TextUnit, Direction, @@ -49,18 +49,6 @@ pub struct Diagnostic { pub fix: Option, } -#[derive(Debug)] -pub struct Runnable { - pub range: TextRange, - pub kind: RunnableKind, -} - -#[derive(Debug)] -pub enum RunnableKind { - Test { name: String }, - Bin, -} - pub fn matching_brace(file: &SourceFileNode, offset: TextUnit) -> Option { const BRACES: &[SyntaxKind] = &[ L_CURLY, R_CURLY, L_BRACK, R_BRACK, L_PAREN, R_PAREN, L_ANGLE, R_ANGLE, @@ -133,29 +121,6 @@ pub fn syntax_tree(file: &SourceFileNode) -> String { ::ra_syntax::utils::dump_tree(file.syntax()) } -pub fn runnables(file: &SourceFileNode) -> Vec { - file.syntax() - .descendants() - .filter_map(ast::FnDef::cast) - .filter_map(|f| { - let name = f.name()?.text(); - let kind = if name == "main" { - RunnableKind::Bin - } else if f.has_atom_attr("test") { - RunnableKind::Test { - name: name.to_string(), - } - } else { - return None; - }; - Some(Runnable { - range: f.syntax().range(), - kind, - }) - }) - .collect() -} - pub fn find_node_at_offset<'a, N: AstNode<'a>>( syntax: SyntaxNodeRef<'a>, offset: TextUnit, @@ -190,29 +155,6 @@ fn main() {} ); } - #[test] - fn test_runnables() { - let file = SourceFileNode::parse( - r#" -fn main() {} - -#[test] -fn test_foo() {} - -#[test] -#[ignore] -fn test_foo() {} -"#, - ); - let runnables = runnables(&file); - assert_eq_dbg( - r#"[Runnable { range: [1; 13), kind: Bin }, - Runnable { range: [15; 39), kind: Test { name: "test_foo" } }, - Runnable { range: [41; 75), kind: Test { name: "test_foo" } }]"#, - &runnables, - ) - } - #[test] fn test_matching_brace() { fn do_check(before: &str, after: &str) { -- cgit v1.2.3