mirror of
https://github.com/microsoft/regorus.git
synced 2026-08-05 02:16:11 +00:00
Fix clippy warning (#25)
Signed-off-by: Anand Krishnamoorthi <anakrish@microsoft.com>
This commit is contained in:
committed by
GitHub
parent
8a9652b8d2
commit
b7420aceba
@@ -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);
|
||||
}
|
||||
|
||||
|
||||
@@ -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",
|
||||
@@ -50,7 +50,7 @@ fn case1() -> Result<()> {
|
||||
"v = 1",
|
||||
];
|
||||
|
||||
let expected = vec![
|
||||
let expected = [
|
||||
"v = 1",
|
||||
"v = x",
|
||||
"x = 5",
|
||||
@@ -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"])]),
|
||||
@@ -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"])]),
|
||||
@@ -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"])]),
|
||||
@@ -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"])]),
|
||||
@@ -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"])]),
|
||||
@@ -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"])]),
|
||||
|
||||
@@ -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(())
|
||||
}
|
||||
|
||||
Reference in New Issue
Block a user