8000 rune: Clean up root-level modules by udoprog · Pull Request #770 · rune-rs/rune · GitHub
[go: up one dir, main page]

Skip to content

rune: Clean up root-level modules #770

New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Merged
merged 2 commits into from
Jul 23, 2024
Merged
Show file tree
Hide file tree
Changes from 1 commit
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
Next Next commit
rune: Clean up root-level modules
  • Loading branch information
udoprog committed Jul 23, 2024
commit 71aa2f1481f769cc70e6566ac1c7b2441ab398d8
2 changes: 0 additions & 2 deletions crates/rune/src/ast/attribute.rs
A8C6
Original file line number Diff line number Diff line change
Expand Up @@ -2,8 +2,6 @@ use crate::ast::prelude::*;

#[test]
fn ast_parse() {
use crate::testing::rt;

rt::<ast::Attribute>("#[foo = \"foo\"]");
rt::<ast::Attribute>("#[foo()]");
rt::<ast::Attribute>("#![foo]");
Expand Down
2 changes: 0 additions & 2 deletions crates/rune/src/ast/block.rs
Original file line number Diff line number Diff line change
Expand Up @@ -2,8 +2,6 @@ use crate::ast::prelude::*;

#[test]
fn ast_parse() {
use crate::testing::rt;

let expr = rt::<ast::ExprBlock>("{}");
assert_eq!(expr.block.statements.len(), 0);

Expand Down
2 changes: 0 additions & 2 deletions crates/rune/src/ast/condition.rs
Original file line number Diff line number Diff line change
Expand Up @@ -2,8 +2,6 @@ use crate::ast::prelude::*;

#[test]
fn ast_parse() {
use crate::testing::rt;

rt::<ast::Condition>("true");
rt::<ast::Condition>("let [a, ..] = v");
}
Expand Down
72 changes: 21 additions & 51 deletions crates/rune/src/ast/expr.rs
Original file line number Diff line number Diff line change
Expand Up @@ -5,16 +5,14 @@ use crate::ast::prelude::*;

#[test]
fn ast_parse() {
use crate::testing::rt;

rt::<ast::Expr>("()");
rt::<ast::Expr>("foo[\"foo\"]");
rt::<ast::Expr>("foo[\"bar\"]");
rt::<ast::Expr>("foo.bar()");
rt::<ast::Expr>("var()");
rt::<ast::Expr>("var");
rt::<ast::Expr>("42");
rt::<ast::Expr>("1 + 2 / 3 - 4 * 1");
rt::<ast::Expr>("foo[\"bar\"]");
rt::<ast::Expr>("let var = 42");
rt::<ast::Expr>("let var = \"foo bar\"");
rt::<ast::Expr>("var[\"foo\"] = \"bar\"");
Expand Down Expand Up @@ -47,6 +45,26 @@ fn ast_parse() {
rt::<ast::Expr>("[false, 1, 'b']");
}

#[test]
fn expr_if() {
let expr = rt::<ast::Expr>(r#"if true {} else {}"#);
assert!(matches!(expr, ast::Expr::If(..)));

let expr = rt::<ast::Expr>("if 1 { } else { if 2 { } else { } }");
assert!(matches!(expr, ast::Expr::If(..)));
}

#[test]
fn expr_while() {
let expr = rt::<ast::Expr>(r#"while true {}"#);
assert!(matches!(expr, ast::Expr::While(..)));
}

#[test]
fn test_macro_call_chain() {
rt::<ast::Expr>("format!(\"{}\", a).bar()");
}

/// Indicator that an expression should be parsed with an eager brace.
#[derive(Debug, Clone, Copy)]
pub(crate) struct EagerBrace(bool);
Expand Down Expand Up @@ -785,51 +803,3 @@ fn paren_group(p: &mut Parser<'_>, attributes: Vec<ast::Attribute>) -> Result<Ex
p, attributes, open, expr,
)?))
}

#[cfg(test)]
mod tests {
use crate::ast;
use crate::testing::rt;

#[test]
fn test_expr_if() {
let expr = rt::<ast::Expr>(r#"if true {} else {}"#);
assert!(matches!(expr, ast::Expr::If(..)));

let expr = rt::<ast::Expr>("if 1 { } else { if 2 { } else { } }");
assert!(matches!(expr, ast::Expr::If(..)));
}

#[test]
fn test_expr_while() {
let expr = rt::<ast::Expr>(r#"while true {}"#);
assert!(matches!(expr, ast::Expr::While(..)));
}

#[test]
fn test_expr() {
rt::<ast::Expr>("foo[\"foo\"]");
rt::<ast::Expr>("foo.bar()");
rt::<ast::Expr>("var()");
rt::<ast::Expr>("var");
rt::<ast::Expr>("42");
rt::<ast::Expr>("1 + 2 / 3 - 4 * 1");
rt::<ast::Expr>("foo[\"bar\"]");
rt::<ast::Expr>("let var = 42");
rt::<ast::Expr>("let var = \"foo bar\"");
rt::<ast::Expr>("var[\"foo\"] = \"bar\"");
rt::<ast::Expr>("let var = objects[\"foo\"] + 1");
rt::<ast::Expr>("var = 42");

// Chained function calls.
rt::<ast::Expr>("foo.bar.baz()");
rt::<ast::Expr>("foo[0][1][2]");
rt::<ast::Expr>("foo.bar()[0].baz()[1]");
rt::<ast::Expr>("42 is i64::i64");
}

#[test]
fn test_macro_call_chain() {
rt::<ast::Expr>("format!(\"{}\", a).bar()");
}
}
2 changes: 0 additions & 2 deletions crates/rune/src/ast/expr_assign.rs
Original file line number Diff line number Diff line change
Expand Up @@ -2,8 +2,6 @@ use crate::ast::prelude::*;

#[test]
fn ast_parse() {
use crate::testing::rt;

rt::<ast::ExprAssign>("a = 2");
rt::<ast::ExprAssign>("a = b = 3");
}
Expand Down
2 changes: 0 additions & 2 deletions crates/rune/src/ast/expr_await.rs
Original file line number Diff line number Diff line change
EED3 Expand Up @@ -2,8 +2,6 @@ use crate::ast::prelude::*;

#[test]
fn ast_parse() {
use crate::testing::rt;

rt::<ast::Expr>("(42).await");
rt::<ast::Expr>("self.await");
rt::<ast::Expr>("test.await");
Expand Down
2 changes: 0 additions & 2 deletions crates/rune/src/ast/expr_binary.rs
Original file line number Diff line number Diff line change
Expand Up @@ -4,8 +4,6 @@ use crate::ast::prelude::*;

#[test]
fn ast_parse() {
use crate::testing::rt;

rt::<ast::ExprBinary>("42 + b");
rt::<ast::ExprBinary>("b << 10");
}
Expand Down
2 changes: 0 additions & 2 deletions crates/rune/src/ast/expr_block.rs
Original file line number Diff line number Diff line change
Expand Up @@ -2,8 +2,6 @@ use crate::ast::prelude::*;

#[test]
fn ast_parse() {
use crate::testing::rt;

let expr = rt::<ast::ExprBlock>("async {}");
assert_eq!(expr.block.statements.len(), 0);

Expand Down
2 changes: 0 additions & 2 deletions crates/rune/src/ast/expr_break.rs
Original file line number Diff line number Diff line change
Expand Up @@ -2,8 +2,6 @@ use crate::ast::prelude::*;

#[test]
fn ast_parse() {
use crate::testing::rt;

rt::<ast::ExprBreak>("break");
rt::<ast::ExprBreak>("break 42");
rt::<ast::ExprBreak>("#[attr] break 42");
Expand Down
2 changes: 0 additions & 2 deletions crates/rune/src/ast/expr_call.rs
Original file line number Diff line number Diff line change
Expand Up @@ -2,8 +2,6 @@ use crate::ast::prelude::*;

#[test]
fn ast_parse() {
use crate::testing::rt;

rt::<ast::ExprCall>("test()");
rt::<ast::ExprCall>("(foo::bar)()");
}
Expand Down
2 changes: 0 additions & 2 deletions crates/rune/src/ast/expr_closure.rs
Original file line number Diff line number Diff line change
Expand Up @@ -2,8 +2,6 @@ use crate::ast::prelude::*;

#[test]
fn ast_parse() {
use crate::testing::rt;

rt::<ast::ExprClosure>("async || 42");
rt::<ast::ExprClosure>("|| 42");
rt::<ast::ExprClosure>("|| { 42 }");
Expand Down
2 changes: 0 additions & 2 deletions crates/rune/src/ast/expr_continue.rs
Original file line number Diff line number Diff line change
Expand Up @@ -2,8 +2,6 @@ use crate::ast::prelude::*;

#[test]
fn ast_parse() {
use crate::testing::rt;

rt::<ast::ExprContinue>("continue");
rt::<ast::ExprContinue>("continue 'foo");
}
Expand Down
2 changes: 0 additions & 2 deletions crates/rune/src/ast/expr_field_access.rs
Original file line number Diff line number Diff line change
Expand Up @@ -2,8 +2,6 @@ use crate::ast::prelude::*;

#[test]
fn ast_parse() {
use crate::testing::rt;

rt::<ast::ExprFieldAccess>("foo.bar");
rt::<ast::ExprFieldAccess>("foo.bar::<A, B>");
rt::<ast::ExprFieldAccess>("foo.0.bar");
Expand Down
2 changes: 0 additions & 2 deletions crates/rune/src/ast/expr_for.rs
Original file line number Diff line number Diff line change
Expand Up @@ -2,8 +2,6 @@ use crate::ast::prelude::*;

#[test]
fn ast_parse() {
use crate::testing::rt;

rt::<ast::ExprFor>("for i in x {}");
rt::<ast::ExprFor>("for (a, _) in x {}");
rt::<ast::ExprFor>("'label: for i in x {}");
Expand Down
2 changes: 0 additions & 2 deletions crates/rune/src/ast/expr_group.rs
Original file line number Diff line number Diff line change
Expand Up @@ -2,8 +2,6 @@ use crate::ast::prelude::*;

#[test]
fn ast_parse() {
use crate::testing::rt;

rt::<ast::ExprGroup>("(for i in x {})");
rt::<ast::ExprGroup>("(1 + 2)");
}
Expand Down
2 changes: 0 additions & 2 deletions crates/rune/src/ast/expr_if.rs
Original file line number Diff line number Diff line change
Expand Up @@ -2,8 +2,6 @@ use crate::ast::prelude::*;

#[test]
fn ast_parse() {
use crate::testing::rt;

rt::<ast::ExprIf>("if 0 { }");
rt::<ast::ExprIf>("if 0 { } else { }");
rt::<ast::ExprIf>("if 0 { } else if 0 { } else { }");
Expand Down
2 changes: 0 additions & 2 deletions crates/rune/src/ast/expr_index.rs
Original file line number Diff line number Diff line change
Expand Up @@ -2,8 +2,6 @@ use crate::ast::prelude::*;

#[test]
fn ast_parse() {
use crate::testing::rt;

rt::<ast::ExprIndex>("value[42]");
rt::<ast::ExprIndex>("value[value2[v + 2]]");
}
Expand Down
2 changes: 0 additions & 2 deletions crates/rune/src/ast/expr_let.rs
Original file line number Diff line number Diff line change
Expand Up @@ -2,8 +2,6 @@ use crate::ast::prelude::*;

#[test]
fn ast_parse() {
use crate::testing::rt;

rt::<ast::ExprLet>("let x = 1");
rt::<ast::ExprLet>("#[attr] let a = f()");
}
Expand Down
2 changes: 0 additions & 2 deletions crates/rune/src/ast/expr_lit.rs
Original file line number Diff line number Diff line change
Expand Up @@ -2,8 +2,6 @@ use crate::ast::prelude::*;

#[test]
fn ast_parse() {
use crate::testing::rt;

rt::<ast::ExprLit>("42");
rt::<ast::ExprLit>("\"test\"");
rt::<ast::ExprLit>("#[attr] 42");
Expand Down
2 changes: 0 additions & 2 deletions crates/rune/src/ast/expr_loop.rs
Original file line number Diff line number Diff line change
Expand Up @@ -2,8 +2,6 @@ use crate::ast::prelude::*;

#[test]
fn ast_parse() {
use crate::testing::rt;

rt::<ast::ExprLoop>("loop {}");
rt::<ast::ExprLoop>("loop { 1; }");
rt::<ast::ExprLoop>("'label: loop {1;}");
Expand Down
2 changes: 0 additions & 2 deletions crates/rune/src/ast/expr_match.rs
Original file line number Diff line number Diff line change
Expand Up @@ -2,8 +2,6 @@ use crate::ast::prelude::*;

#[test]
fn ast_parse() {
use crate::testing::rt;

rt::<ast::ExprMatch>("match 0 { _ => 1, }");
let expr = rt::<ast::ExprMatch>("#[jit(always)] match 0 { _ => 1, }");
assert_eq!(expr.attributes.len(), 1);
Expand Down
2 changes: 0 additions & 2 deletions crates/rune/src/ast/expr_object.rs
Original file line number Diff line number Diff line change
Expand Up @@ -3,8 +3,6 @@ use crate::ast::prelude::*;

#[test]
fn ast_parse() {
use crate::testing::rt;

rt::<ast::ExprObject>("Foo {\"foo\": 42}");
rt::<ast::ExprObject>("#{\"foo\": 42}");
rt::<ast::ExprObject>("#{\"foo\": 42,}");
Expand Down
2 changes: 0 additions & 2 deletions crates/rune/src/ast/expr_range.rs
Original file line number Diff line number Diff line change
Expand Up @@ -2,8 +2,6 @@ use crate::ast::prelude::*;

#[test]
fn ast_parse() {
use crate::testing::rt;

rt::<ast::ExprRange>("0..42");
rt::<ast::ExprRange>("0..=42");
rt::<ast::ExprRange>("0..=a + 2");
Expand Down
2 changes: 0 additions & 2 deletions crates/rune/src/ast/expr_return.rs
Original file line number Diff line number Diff line change
Expand Up @@ -2,8 +2,6 @@ use crate::ast::prelude::*;

#[test]
fn ast_parse() {
use crate::testing::rt;

rt::<ast::ExprReturn>("return");
rt::<ast::ExprReturn>("return 42");
rt::<ast::ExprReturn>("#[attr] return 42");
Expand Down
2 changes: 0 additions & 2 deletions crates/rune/src/ast/expr_select.rs
Original file line number Diff line number Diff line change
Expand Up @@ -2,8 +2,6 @@ use crate::ast::prelude::*;

#[test]
fn ast_parse() {
use crate::testing::rt;

let select = rt::<ast::ExprSelect>(
r#"
select {
Expand Down
2 changes: 0 additions & 2 deletions crates/rune/src/ast/expr_try.rs
Original file line number Diff line number Diff line change
Expand Up @@ -2,8 +2,6 @@ use crate::ast::prelude::*;

#[test]
fn ast_parse() {
use crate::testing::rt;

rt::<ast::ExprTry>("42?");
rt::<ast::ExprTry>("foo()?");
}
Expand Down
2 changes: 0 additions & 2 deletions crates/rune/src/ast/expr_tuple.rs
Original file line number Diff line number Diff line change
Expand Up @@ -2,8 +2,6 @@ use crate::ast::prelude::*;

#[test]
fn ast_parse() {
use crate::testing::rt;

rt::<ast::ExprTuple>("()");
rt::<ast::ExprTuple>("(1,)");
rt::<ast::ExprTuple>("(1, \"two\")");
Expand Down
2 changes: 0 additions & 2 deletions crates/rune/src/ast/expr_unary.rs
Original file line number Diff line number Diff line change
Expand Up @@ -4,8 +4,6 @@ use crate::ast::prelude::*;

#[test]
fn ast_parse() {
use crate::testing::rt;

rt::<ast::ExprUnary>("!0");
rt::<ast::ExprUnary>("*foo");
rt::<ast::ExprUnary>("&foo");
Expand Down
2 changes: 0 additions & 2 deletions crates/rune/src/ast/expr_vec.rs
Original file line number Diff line number Diff line change
Expand Up @@ -2,8 +2,6 @@ use crate::ast::prelude::*;

#[test]
fn ast_parse() {
use crate::testing::rt;

rt::<ast::ExprVec>("[1, \"two\"]");
rt::<ast::ExprVec>("[1, 2,]");
rt::<ast::ExprVec>("[1, 2, foo()]");
Expand Down
2 changes: 0 additions & 2 deletions crates/rune/src/ast/expr_while.rs
Original file line number Diff line number Diff line change
Expand Up @@ -2,8 +2,6 @@ use crate::ast::prelude::*;

#[test]
fn ast_parse() {
use crate::testing::rt;

rt::<ast::ExprWhile>("while x {}");
rt::<ast::ExprWhile>("'label: while x {}");
rt::<ast::ExprWhile>("#[attr] 'label: while x {}");
Expand Down
2 changes: 0 additions & 2 deletions crates/rune/src/ast/expr_yield.rs
Original file line number Diff line number Diff line change
Expand Up @@ -2,8 +2,6 @@ use crate::ast::prelude::*;

#[test]
fn ast_parse() {
use crate::testing::rt;

rt::<ast::ExprYield>("yield");
rt::<ast::ExprYield>("yield 42");
rt::<ast::ExprYield>("#[attr] yield 42");
Expand Down
4 changes: 1 addition & 3 deletions crates/rune/src/ast/file.rs
< A73C td id="diff-9f48113c54d33b69ab83c950aa1a07bbe0c540616f37c441d5fc34c81188414cR43" data-line-number="43" class="blob-num blob-num-context js-linkable-line-number js-blob-rnum">
Original file line number Diff line number Diff line change
Expand Up @@ -2,8 +2,6 @@ use crate::ast::prelude::*;

#[test]
fn ast_parse() {
use crate::testing::rt;

rt::<ast::File>(
r#"
use foo;
Expand Down Expand Up @@ -41,7 +39,7 @@ fn ast_parse() {
"#,
);

let file = crate::testing::rt_with::<ast::File>(
let file = rt_with::<ast::File>(
r#"#!rune run

fn main() {}
Expand Down
2 changes: 0 additions & 2 deletions crates/rune/src/ast/fn_arg.rs
Original file line number Diff line number Diff line change
Expand Up @@ -2,8 +2,6 @@ use crate::ast::prelude::*;

#[test]
fn ast_parse() {
use crate::testing::rt;

rt::<ast::FnArg>("self");
rt::<ast::FnArg>("_");
rt::<ast::FnArg>("abc");
Expand Down
Loading
0