Skip to content
Merged
Show file tree
Hide file tree
Changes from all commits
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
32 changes: 12 additions & 20 deletions common/src/float_ops.rs
Original file line number Diff line number Diff line change
Expand Up @@ -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");
}
2 changes: 1 addition & 1 deletion jit/tests/common.rs
Original file line number Diff line number Diff line change
Expand Up @@ -141,7 +141,7 @@ impl StackMachine {
instruction
),
}
return false;
false
}

pub fn get_function(&self, name: &str) -> Function {
Expand Down
22 changes: 11 additions & 11 deletions parser/src/fstring.rs
Original file line number Diff line number Diff line change
Expand Up @@ -306,23 +306,23 @@ 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);
}

#[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);
}

#[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);
}
Expand All @@ -335,23 +335,23 @@ 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);
}

#[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);
}

#[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);
}
Expand Down Expand Up @@ -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);
}
}
6 changes: 3 additions & 3 deletions parser/src/parser.rs
Original file line number Diff line number Diff line change
Expand Up @@ -122,15 +122,15 @@ 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);
}

#[test]
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]
Expand All @@ -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]
Expand Down
20 changes: 8 additions & 12 deletions vm/src/builtins/str.rs
Original file line number Diff line number Diff line change
Expand Up @@ -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()
Expand Down
4 changes: 2 additions & 2 deletions vm/src/builtins/type.rs
Original file line number Diff line number Diff line change
Expand Up @@ -990,7 +990,7 @@ mod tests {
vec![object.clone()],
PyAttributes::default(),
Default::default(),
type_type.clone(),
type_type,
)
.unwrap();

Expand All @@ -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]))
);
}
}
20 changes: 10 additions & 10 deletions vm/src/dictdatatype.rs
Original file line number Diff line number Diff line change
Expand Up @@ -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.");
})
Expand All @@ -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);
})
}
Expand Down
2 changes: 1 addition & 1 deletion vm/src/eval.rs
Original file line number Diff line number Diff line change
Expand Up @@ -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));
})
}
Expand Down
4 changes: 2 additions & 2 deletions vm/src/vm/mod.rs
Original file line number Diff line number Diff line change
Expand Up @@ -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);
}
})
Expand Down