fix clippy

This commit is contained in:
Jeong Yunwon
2022-07-21 06:36:16 +09:00
parent a3df2169f4
commit dd2bf4c96b
9 changed files with 50 additions and 62 deletions

View File

@@ -478,40 +478,32 @@ fn test_to_hex() {
#[test]
fn test_remove_trailing_zeros() {
assert!(remove_trailing_zeros(String::from("100")) == String::from("1"));
assert!(remove_trailing_zeros(String::from("100.00")) == String::from("100."));
assert!(remove_trailing_zeros(String::from("100")) == *"1");
assert!(remove_trailing_zeros(String::from("100.00")) == *"100.");
// leave leading zeros untouched
assert!(remove_trailing_zeros(String::from("001")) == String::from("001"));
assert!(remove_trailing_zeros(String::from("001")) == *"001");
// leave strings untouched if they don't end with 0
assert!(remove_trailing_zeros(String::from("101")) == String::from("101"));
assert!(remove_trailing_zeros(String::from("101")) == *"101");
}
#[test]
fn test_remove_trailing_decimal_point() {
assert!(remove_trailing_decimal_point(String::from("100.")) == String::from("100"));
assert!(remove_trailing_decimal_point(String::from("1.")) == String::from("1"));
assert!(remove_trailing_decimal_point(String::from("100.")) == *"100");
assert!(remove_trailing_decimal_point(String::from("1.")) == *"1");
// leave leading decimal points untouched
assert!(remove_trailing_decimal_point(String::from(".5")) == String::from(".5"));
assert!(remove_trailing_decimal_point(String::from(".5")) == *".5");
}
#[test]
fn test_maybe_remove_trailing_redundant_chars() {
assert!(
maybe_remove_trailing_redundant_chars(String::from("100."), true) == String::from("100.")
);
assert!(
maybe_remove_trailing_redundant_chars(String::from("100."), false) == String::from("100")
);
assert!(maybe_remove_trailing_redundant_chars(String::from("1."), false) == String::from("1"));
assert!(
maybe_remove_trailing_redundant_chars(String::from("10.0"), false) == String::from("10")
);
assert!(maybe_remove_trailing_redundant_chars(String::from("100."), true) == *"100.");
assert!(maybe_remove_trailing_redundant_chars(String::from("100."), false) == *"100");
assert!(maybe_remove_trailing_redundant_chars(String::from("1."), false) == *"1");
assert!(maybe_remove_trailing_redundant_chars(String::from("10.0"), false) == *"10");
// don't truncate integers
assert!(
maybe_remove_trailing_redundant_chars(String::from("1000"), false) == String::from("1000")
);
assert!(maybe_remove_trailing_redundant_chars(String::from("1000"), false) == *"1000");
}

View File

@@ -141,7 +141,7 @@ impl StackMachine {
instruction
),
}
return false;
false
}
pub fn get_function(&self, name: &str) -> Function {

View File

@@ -306,7 +306,7 @@ mod tests {
#[test]
fn test_parse_fstring() {
let source = "{a}{ b }{{foo}}";
let parse_ast = parse_fstring(&source).unwrap();
let parse_ast = parse_fstring(source).unwrap();
insta::assert_debug_snapshot!(parse_ast);
}
@@ -314,7 +314,7 @@ mod tests {
#[test]
fn test_parse_fstring_nested_spec() {
let source = "{foo:{spec}}";
let parse_ast = parse_fstring(&source).unwrap();
let parse_ast = parse_fstring(source).unwrap();
insta::assert_debug_snapshot!(parse_ast);
}
@@ -322,7 +322,7 @@ mod tests {
#[test]
fn test_parse_fstring_not_nested_spec() {
let source = "{foo:spec}";
let parse_ast = parse_fstring(&source).unwrap();
let parse_ast = parse_fstring(source).unwrap();
insta::assert_debug_snapshot!(parse_ast);
}
@@ -335,7 +335,7 @@ mod tests {
#[test]
fn test_fstring_parse_selfdocumenting_base() {
let src = "{user=}";
let parse_ast = parse_fstring(&src).unwrap();
let parse_ast = parse_fstring(src).unwrap();
insta::assert_debug_snapshot!(parse_ast);
}
@@ -343,7 +343,7 @@ mod tests {
#[test]
fn test_fstring_parse_selfdocumenting_base_more() {
let src = "mix {user=} with text and {second=}";
let parse_ast = parse_fstring(&src).unwrap();
let parse_ast = parse_fstring(src).unwrap();
insta::assert_debug_snapshot!(parse_ast);
}
@@ -351,7 +351,7 @@ mod tests {
#[test]
fn test_fstring_parse_selfdocumenting_format() {
let src = "{user=:>10}";
let parse_ast = parse_fstring(&src).unwrap();
let parse_ast = parse_fstring(src).unwrap();
insta::assert_debug_snapshot!(parse_ast);
}
@@ -384,35 +384,35 @@ mod tests {
#[test]
fn test_parse_fstring_not_equals() {
let source = "{1 != 2}";
let parse_ast = parse_fstring(&source).unwrap();
let parse_ast = parse_fstring(source).unwrap();
insta::assert_debug_snapshot!(parse_ast);
}
#[test]
fn test_parse_fstring_equals() {
let source = "{42 == 42}";
let parse_ast = parse_fstring(&source).unwrap();
let parse_ast = parse_fstring(source).unwrap();
insta::assert_debug_snapshot!(parse_ast);
}
#[test]
fn test_parse_fstring_selfdoc_prec_space() {
let source = "{x =}";
let parse_ast = parse_fstring(&source).unwrap();
let parse_ast = parse_fstring(source).unwrap();
insta::assert_debug_snapshot!(parse_ast);
}
#[test]
fn test_parse_fstring_selfdoc_trailing_space() {
let source = "{x= }";
let parse_ast = parse_fstring(&source).unwrap();
let parse_ast = parse_fstring(source).unwrap();
insta::assert_debug_snapshot!(parse_ast);
}
#[test]
fn test_parse_fstring_yield_expr() {
let source = "{yield}";
let parse_ast = parse_fstring(&source).unwrap();
let parse_ast = parse_fstring(source).unwrap();
insta::assert_debug_snapshot!(parse_ast);
}
}

View File

@@ -122,7 +122,7 @@ mod tests {
#[test]
fn test_parse_lambda() {
let source = "lambda x, y: x * y"; // lambda(x, y): x * y";
let parse_ast = parse_program(&source).unwrap();
let parse_ast = parse_program(source).unwrap();
insta::assert_debug_snapshot!(parse_ast);
}
@@ -130,7 +130,7 @@ mod tests {
fn test_parse_tuples() {
let source = "a, b = 4, 5";
insta::assert_debug_snapshot!(parse_program(&source).unwrap());
insta::assert_debug_snapshot!(parse_program(source).unwrap());
}
#[test]
@@ -141,7 +141,7 @@ class Foo(A, B):
pass
def method_with_default(self, arg='default'):
pass";
insta::assert_debug_snapshot!(parse_program(&source).unwrap());
insta::assert_debug_snapshot!(parse_program(source).unwrap());
}
#[test]

View File

@@ -1592,23 +1592,19 @@ mod tests {
Interpreter::without_stdlib(Default::default()).enter(|vm| {
let table = vm.ctx.new_dict();
table
.set_item("a", vm.ctx.new_str("🎅").into(), &vm)
.set_item("a", vm.ctx.new_str("🎅").into(), vm)
.unwrap();
table.set_item("b", vm.ctx.none(), &vm).unwrap();
table.set_item("b", vm.ctx.none(), vm).unwrap();
table
.set_item("c", vm.ctx.new_str(ascii!("xda")).into(), &vm)
.set_item("c", vm.ctx.new_str(ascii!("xda")).into(), vm)
.unwrap();
let translated = PyStr::maketrans(
table.into(),
OptionalArg::Missing,
OptionalArg::Missing,
&vm,
)
.unwrap();
let translated =
PyStr::maketrans(table.into(), OptionalArg::Missing, OptionalArg::Missing, vm)
.unwrap();
let text = PyStr::from("abc");
let translated = text.translate(translated, &vm).unwrap();
let translated = text.translate(translated, vm).unwrap();
assert_eq!(translated, "🎅xda".to_owned());
let translated = text.translate(vm.ctx.new_int(3).into(), &vm);
let translated = text.translate(vm.ctx.new_int(3).into(), vm);
assert_eq!(
translated.unwrap_err().class().name().deref(),
"TypeError".to_owned()

View File

@@ -990,7 +990,7 @@ mod tests {
vec![object.clone()],
PyAttributes::default(),
Default::default(),
type_type.clone(),
type_type,
)
.unwrap();
@@ -1006,7 +1006,7 @@ mod tests {
vec![a.clone(), object.clone()],
vec![b.clone(), object.clone()],
])),
map_ids(Ok(vec![a.clone(), b.clone(), object.clone()]))
map_ids(Ok(vec![a, b, object]))
);
}
}

View File

@@ -922,27 +922,27 @@ mod tests {
let key1 = vm.new_pyobj(true);
let value1 = vm.new_pyobj(ascii!("abc"));
dict.insert(&vm, &*key1, value1.clone()).unwrap();
dict.insert(vm, &*key1, value1).unwrap();
assert_eq!(1, dict.len());
let key2 = vm.new_pyobj(ascii!("x"));
let value2 = vm.new_pyobj(ascii!("def"));
dict.insert(&vm, &*key2, value2.clone()).unwrap();
dict.insert(vm, &*key2, value2.clone()).unwrap();
assert_eq!(2, dict.len());
dict.insert(&vm, &*key1, value2.clone()).unwrap();
dict.insert(vm, &*key1, value2.clone()).unwrap();
assert_eq!(2, dict.len());
dict.delete(&vm, &*key1).unwrap();
dict.delete(vm, &*key1).unwrap();
assert_eq!(1, dict.len());
dict.insert(&vm, &*key1, value2.clone()).unwrap();
dict.insert(vm, &*key1, value2.clone()).unwrap();
assert_eq!(2, dict.len());
assert_eq!(true, dict.contains(&vm, &*key1).unwrap());
assert_eq!(true, dict.contains(&vm, "x").unwrap());
assert_eq!(true, dict.contains(vm, &*key1).unwrap());
assert_eq!(true, dict.contains(vm, "x").unwrap());
let val = dict.get(&vm, "x").unwrap().unwrap();
let val = dict.get(vm, "x").unwrap().unwrap();
vm.bool_eq(&val, &value2)
.expect("retrieved value must be equal to inserted value.");
})
@@ -969,8 +969,8 @@ mod tests {
let value1 = text;
let value2 = vm.new_pyobj(value1.to_owned());
let hash1 = value1.key_hash(&vm).expect("Hash should not fail.");
let hash2 = value2.key_hash(&vm).expect("Hash should not fail.");
let hash1 = value1.key_hash(vm).expect("Hash should not fail.");
let hash2 = value2.key_hash(vm).expect("Hash should not fail.");
assert_eq!(hash1, hash2);
})
}

View File

@@ -23,7 +23,7 @@ mod tests {
Interpreter::without_stdlib(Default::default()).enter(|vm| {
let source = String::from("print('Hello world')");
let vars = vm.new_scope_with_builtins();
let result = eval(&vm, &source, vars, "<unittest>").expect("this should pass");
let result = eval(vm, &source, vars, "<unittest>").expect("this should pass");
assert!(vm.is_none(&result));
})
}

View File

@@ -760,8 +760,8 @@ fn test_nested_frozen() {
.map_err(|err| vm.new_syntax_error(&err))
.unwrap();
if let Err(e) = vm.run_code_obj(code_obj, scope.clone()) {
vm.print_exception(e.clone());
if let Err(e) = vm.run_code_obj(code_obj, scope) {
vm.print_exception(e);
assert!(false);
}
})