Use disassembly for snapshot testing

This commit is contained in:
Noah 2020-10-17 21:54:47 -05:00
parent 3f9dd3dd4c
commit 4afbc082ed
5 changed files with 60 additions and 286 deletions

View file

@ -2351,20 +2351,43 @@ mod tests {
compiler.pop_code_object()
}
macro_rules! assert_dis_snapshot {
($value:expr) => {
insta::assert_snapshot!(
insta::internals::AutoName,
$value.display_expand_codeobjects().to_string(),
stringify!($value)
)
};
}
#[test]
fn test_if_ors() {
insta::assert_ron_snapshot!(compile_exec("if True or False or False:\n pass\n"));
assert_dis_snapshot!(compile_exec(
"\
if True or False or False:
pass
"
));
}
#[test]
fn test_if_ands() {
insta::assert_ron_snapshot!(compile_exec("if True and False and False:\n pass\n"));
assert_dis_snapshot!(compile_exec(
"\
if True and False and False:
pass
"
));
}
#[test]
fn test_if_mixed() {
insta::assert_ron_snapshot!(compile_exec(
"if (True and False) or (False and True):\n pass\n"
assert_dis_snapshot!(compile_exec(
"\
if (True and False) or (False and True):
pass
"
));
}
}