Skip to content

Commit

Permalink
Fix clippy warning (#25)
Browse files Browse the repository at this point in the history
Signed-off-by: Anand Krishnamoorthi <anakrish@microsoft.com>
  • Loading branch information
anakrish authored Sep 27, 2023
1 parent 8a9652b commit b7420ac
Show file tree
Hide file tree
Showing 3 changed files with 38 additions and 63 deletions.
4 changes: 3 additions & 1 deletion src/interpreter.rs
Original file line number Diff line number Diff line change
Expand Up @@ -547,7 +547,9 @@ impl<'source> Interpreter<'source> {
let field_value = &value[&key];

if field_value == &Value::Undefined {
if raise_error {}
if raise_error {
return Err(span.error("Expected value, got undefined."));
}
return Ok(false);
}

Expand Down
74 changes: 25 additions & 49 deletions tests/scheduler/mod.rs
Original file line number Diff line number Diff line change
Expand Up @@ -40,7 +40,7 @@ fn check_result(stmts: &[&str], expected: &[&str], r: SortResult) -> Result<()>

#[test]
fn case1() -> Result<()> {
let stmts = vec![
let stmts = [
"v = x",
"y = [1, 2, 4][_]",
"x > 10",
Expand All @@ -50,7 +50,7 @@ fn case1() -> Result<()> {
"v = 1",
];

let expected = vec![
let expected = [
"v = 1",
"v = x",
"x = 5",
Expand All @@ -77,18 +77,14 @@ fn case1() -> Result<()> {
//#[ignore = "destructing needs more thought. Hoist exprs and introduce new assignments?"]
fn case2() -> Result<()> {
#[rustfmt::skip]
let stmts = vec![
"[x, y+1] = [y, p]",
let stmts = ["[x, y+1] = [y, p]",
"value = x + p",
"y = 5"
];
"y = 5"];

#[rustfmt::skip]
let expected = vec![
"y = 5",
let expected = ["y = 5",
"[x, y+1] = [y, p]",
"value = x + p"
];
"value = x + p"];

let mut infos = vec![
make_info(&[("x", &["y"]), ("y", &["x"]), ("p", &["y"])]),
Expand All @@ -102,19 +98,15 @@ fn case2() -> Result<()> {
#[test]
fn case2_rewritten() -> Result<()> {
#[rustfmt::skip]
let stmts = vec![
"y+1 = p",
let stmts = ["y+1 = p",
"x = y",
"value = x + p", "y = 5"
];
"value = x + p", "y = 5"];

#[rustfmt::skip]
let expected = vec![
"y = 5",
let expected = ["y = 5",
"y+1 = p",
"x = y",
"value = x + p"
];
"value = x + p"];

let mut infos = vec![
make_info(&[("p", &["y"])]),
Expand All @@ -129,20 +121,16 @@ fn case2_rewritten() -> Result<()> {
#[test]
fn case3() -> Result<()> {
#[rustfmt::skip]
let stmts = vec![
r#"[x, {"p":p}] = [y, t]"#,
let stmts = [r#"[x, {"p":p}] = [y, t]"#,
r#"t = {"p":8, "p":6}"#,
"value = x + y + p",
"y = 5",
];
"y = 5"];

#[rustfmt::skip]
let expected = vec![
r#"t = {"p":8, "p":6}"#,
let expected = [r#"t = {"p":8, "p":6}"#,
"y = 5",
r#"[x, {"p":p}] = [y, t]"#,
"value = x + y + p",
];
"value = x + y + p"];

let mut infos = vec![
make_info(&[("x", &["y"]), ("p", &["t"])]),
Expand All @@ -158,18 +146,14 @@ fn case3() -> Result<()> {
#[ignore = "cycle needs to be detected"]
fn case4_cycle() -> Result<()> {
#[rustfmt::skip]
let stmts = vec![
r#"[x, {"p":p}] = [y, t]"#,
let stmts = [r#"[x, {"p":p}] = [y, t]"#,
r#"t = {"p":x}"#,
"value = x + y + p",
"y = 5",
];
"y = 5"];

// Rest of the statements cannot be processed due to cycle.
#[rustfmt::skip]
let expected = vec![
"y = 5",
];
let expected = ["y = 5"];

let mut infos = vec![
make_info(&[("x", &["y"]), ("p", &["t"])]),
Expand All @@ -185,19 +169,15 @@ fn case4_cycle() -> Result<()> {
#[test]
fn case4_no_cycle() -> Result<()> {
#[rustfmt::skip]
let stmts = vec![
r#"[x, {"p":p}] = [y, {"p":x}]"#,
let stmts = [r#"[x, {"p":p}] = [y, {"p":x}]"#,
"value = x + y + p",
"y = 5",
];
"y = 5"];

// Rest of the statements cannot be processed due to cycle.
#[rustfmt::skip]
let expected = vec![
"y = 5",
let expected = ["y = 5",
r#"[x, {"p":p}] = [y, {"p":x}]"#,
"value = x + y + p",
];
"value = x + y + p"];

let mut infos = vec![
make_info(&[("x", &["y"]), ("p", &["x"])]),
Expand All @@ -212,23 +192,19 @@ fn case4_no_cycle() -> Result<()> {
#[test]
fn case4_cycle_removed_via_split_multi_assign() -> Result<()> {
#[rustfmt::skip]
let stmts = vec![
r#"x = y"#,
let stmts = [r#"x = y"#,
r#"{"p":p} = t"#,
r#"t = {"p":x}"#,
"value = x + y + p",
"y = 5",
];
"y = 5"];

// Rest of the statements cannot be processed due to cycle.
#[rustfmt::skip]
let expected = vec![
"y = 5",
let expected = ["y = 5",
r#"x = y"#,
r#"t = {"p":x}"#,
r#"{"p":p} = t"#,
"value = x + y + p",
];
"value = x + y + p"];

let mut infos = vec![
make_info(&[("x", &["y"])]),
Expand Down
23 changes: 10 additions & 13 deletions tests/value/mod.rs
Original file line number Diff line number Diff line change
Expand Up @@ -162,22 +162,19 @@ fn api() -> Result<()> {
assert_eq!(v.as_set()?.len(), 0);

// Check invalid api calls.
assert!(matches!(Value::Undefined.as_object(), Err(_)));
assert!(matches!(Value::Undefined.as_object_mut(), Err(_)));
assert!(Value::Undefined.as_object().is_err());
assert!(Value::Undefined.as_object_mut().is_err());

assert!(matches!(Value::Null.as_set(), Err(_)));
assert!(matches!(Value::Null.as_set_mut(), Err(_)));
assert!(Value::Null.as_set().is_err());
assert!(Value::Null.as_set_mut().is_err());

assert!(matches!(Value::String("anc".to_owned()).as_array(), Err(_)));
assert!(matches!(
Value::String("anc".to_owned()).as_array_mut(),
Err(_)
));
assert!(Value::String("anc".to_owned()).as_array().is_err());
assert!(Value::String("anc".to_owned()).as_array_mut().is_err());

assert!(matches!(Value::new_object().as_number(), Err(_)));
assert!(matches!(Value::new_object().as_number_mut(), Err(_)));
assert!(Value::new_object().as_number().is_err());
assert!(Value::new_object().as_number_mut().is_err());

assert!(matches!(Value::from_float(5.6).as_bool(), Err(_)));
assert!(matches!(Value::from_float(5.6).as_bool_mut(), Err(_)));
assert!(Value::from_float(5.6).as_bool().is_err());
assert!(Value::from_float(5.6).as_bool_mut().is_err());
Ok(())
}

0 comments on commit b7420ac

Please sign in to comment.