Skip to content

Commit

Permalink
fix new clippy violations
Browse files Browse the repository at this point in the history
  • Loading branch information
orsinium committed Nov 21, 2023
1 parent ddd910a commit 72ae863
Show file tree
Hide file tree
Showing 3 changed files with 61 additions and 62 deletions.
28 changes: 14 additions & 14 deletions src/interpreter/session.rs
Original file line number Diff line number Diff line change
Expand Up @@ -98,20 +98,20 @@ mod tests {
// These are the most important tests of the runtime.
// Perhaps, there should be more of these.
#[rstest]
#[case::id(r#"id"#, "λx x")]
#[case::assign(r#"c = \a a a"#, "λa a a")]
#[case::def(r#"\a id a"#, "λa id a")]
#[case::call(r#"id A"#, "λa a")]
#[case(r#"id B"#, "λb b")]
#[case(r#"id A B"#, "λb b")]
#[case(r#"(id A) B"#, "λb b")]
#[case(r#"id (A B)"#, "λb b")]
#[case::left(r#"(\a \b a) A B"#, "λa a")]
#[case::right(r#"(\a \b b) A B"#, "λb b")]
#[case(r#"(\a \a a) A B"#, "λb b")]
#[case(r#"(\a (\a a) (\x a)) A"#, "λx A")]
#[case(r#"(\a (\a a) (\x a)) A B"#, "λa a")]
#[case(r#"(\a \a a) A"#, "λa a")]
#[case::id(r"id", "λx x")]
#[case::assign(r"c = \a a a", "λa a a")]
#[case::def(r"\a id a", "λa id a")]
#[case::call(r"id A", "λa a")]
#[case(r"id B", "λb b")]
#[case(r"id A B", "λb b")]
#[case(r"(id A) B", "λb b")]
#[case(r"id (A B)", "λb b")]
#[case::left(r"(\a \b a) A B", "λa a")]
#[case::right(r"(\a \b b) A B", "λb b")]
#[case(r"(\a \a a) A B", "λb b")]
#[case(r"(\a (\a a) (\x a)) A", "λx A")]
#[case(r"(\a (\a a) (\x a)) A B", "λa a")]
#[case(r"(\a \a a) A", "λa a")]
fn eval_module(#[case] input: &str, #[case] exp: &str) {
let mut session = Session::new(None);
session.eval_module(&parse("id = λx x").unwrap()).unwrap();
Expand Down
14 changes: 7 additions & 7 deletions src/interpreter/value.rs
Original file line number Diff line number Diff line change
Expand Up @@ -284,13 +284,13 @@ mod tests {
//
// I believe that the tests must be simple.
#[rstest]
#[case::id(r#"id"#, "id")]
#[case::id(r#"\x x"#, "λx x")]
#[case::id(r#"\a \b a b"#, "λa λb a b")]
#[case::id(r#"\a \b (\c c) b"#, "λa λb (λc c) b")]
#[case::id(r#"\a \b a (b a)"#, "λa λb a (b a)")]
#[case::id(r#"\a \b a b a"#, "λa λb a b a")]
#[case::id(r#"\a \b (a b) a"#, "λa λb a b a")]
#[case::id(r"id", "id")]
#[case::id(r"\x x", "λx x")]
#[case::id(r"\a \b a b", "λa λb a b")]
#[case::id(r"\a \b (\c c) b", "λa λb (λc c) b")]
#[case::id(r"\a \b a (b a)", "λa λb a (b a)")]
#[case::id(r"\a \b a b a", "λa λb a b a")]
#[case::id(r"\a \b (a b) a", "λa λb a b a")]
fn parse_and_repr(#[case] input: &str, #[case] exp: &str) {
let module = parse(input).unwrap();
assert_eq!(module.stmts.len(), 1);
Expand Down
81 changes: 40 additions & 41 deletions src/parser.rs
Original file line number Diff line number Diff line change
Expand Up @@ -110,15 +110,14 @@ fn parse_expression(root: Pair<Rule>) -> Expr {
expr: Box::new(parse_expression(p2)),
}
}
Rule::call => {
root.into_inner()
.map(parse_expression)
.reduce(|target, arg| Expr::Call {
target: Box::new(target),
arg: Box::new(arg)
})
.unwrap()
}
Rule::call => root
.into_inner()
.map(parse_expression)
.reduce(|target, arg| Expr::Call {
target: Box::new(target),
arg: Box::new(arg),
})
.unwrap(),
Rule::identifier => Expr::Id {
name: root.as_str().parse().unwrap(),
},
Expand All @@ -132,30 +131,30 @@ mod tests {
use rstest::rstest;

#[rstest]
#[case::id(r#"id"#, "id")]
#[case::space(r#" id"#, "id")]
#[case::space(r#"id "#, "id")]
#[case::call(r#"id x"#, "call(id, id)")]
#[case::def(r#"\x x"#, "def(id)")]
#[case::def(r#"λx x"#, "def(id)")]
#[case::assign(r#"id = \x x"#, "let(def(id))")]
#[case::assign(r#"id = (\x x)"#, "let(def(id))")]
#[case::assign(r#"& = \a a"#, "let(def(id))")]
#[case(r#"id= \x x"#, "let(def(id))")]
#[case(r#"id =\x x"#, "let(def(id))")]
#[case(r#"id=\x x"#, "let(def(id))")]
#[case::call_chain(r#"id a b"#, "call(call(id, id), id)")]
#[case(r#"id = \a \b x"#, "let(def(def(id)))")]
#[case(r#"apply = \f f f"#, "let(def(call(id, id)))")]
#[case(r#"x = \f a (b c)"#, "let(def(call(id, call(id, id))))")]
#[case(r#"x = \f (a b) c"#, "let(def(call(call(id, id), id)))")]
#[case(r#"x = \f (\x x) c"#, "let(def(call(def(id), id)))")]
#[case(r#"x = \f \x x"#, "let(def(def(id)))")]
#[case(r#"x = \f (\x x)"#, "let(def(def(id)))")]
#[case::call_punct(r#"+ a b"#, "call(call(id, id), id)")]
#[case::assign_punct(r#"+ = \a \b a b"#, "let(def(def(call(id, id))))")]
#[case(r#"add = \a \b + a b"#, "let(def(def(call(call(id, id), id))))")]
#[case::alias(r#"add = +"#, "let(id)")]
#[case::id(r"id", "id")]
#[case::space(r" id", "id")]
#[case::space(r"id ", "id")]
#[case::call(r"id x", "call(id, id)")]
#[case::def(r"\x x", "def(id)")]
#[case::def(r"λx x", "def(id)")]
#[case::assign(r"id = \x x", "let(def(id))")]
#[case::assign(r"id = (\x x)", "let(def(id))")]
#[case::assign(r"& = \a a", "let(def(id))")]
#[case(r"id= \x x", "let(def(id))")]
#[case(r"id =\x x", "let(def(id))")]
#[case(r"id=\x x", "let(def(id))")]
#[case::call_chain(r"id a b", "call(call(id, id), id)")]
#[case(r"id = \a \b x", "let(def(def(id)))")]
#[case(r"apply = \f f f", "let(def(call(id, id)))")]
#[case(r"x = \f a (b c)", "let(def(call(id, call(id, id))))")]
#[case(r"x = \f (a b) c", "let(def(call(call(id, id), id)))")]
#[case(r"x = \f (\x x) c", "let(def(call(def(id), id)))")]
#[case(r"x = \f \x x", "let(def(def(id)))")]
#[case(r"x = \f (\x x)", "let(def(def(id)))")]
#[case::call_punct(r"+ a b", "call(call(id, id), id)")]
#[case::assign_punct(r"+ = \a \b a b", "let(def(def(call(id, id))))")]
#[case(r"add = \a \b + a b", "let(def(def(call(call(id, id), id))))")]
#[case::alias(r"add = +", "let(id)")]
fn smoke_parse_stmt_ok(#[case] input: &str, #[case] exp: &str) {
let module = parse(input).unwrap();
assert_eq!(module.stmts.len(), 1);
Expand All @@ -164,14 +163,14 @@ mod tests {
}

#[rstest]
#[case(r#""#)]
#[case(r#"\x"#)]
#[case(r#"a \x"#)]
#[case(r#"id = "#)]
#[case(r#"id = \x"#)]
#[case(r#"(a)"#)]
#[case(r#"(((\a a)))"#)]
#[case(r#"\a a \b b a"#)]
#[case(r"")]
#[case(r"\x")]
#[case(r"a \x")]
#[case(r"id = ")]
#[case(r"id = \x")]
#[case(r"(a)")]
#[case(r"(((\a a)))")]
#[case(r"\a a \b b a")]
fn smoke_parse_stmt_err(#[case] input: &str) {
assert!(parse(input).is_err());
}
Expand Down

0 comments on commit 72ae863

Please sign in to comment.