mirror of
https://github.com/RustPython/Parser.git
synced 2025-07-19 19:15:43 +00:00
Use disassembly for snapshot testing
This commit is contained in:
parent
3f9dd3dd4c
commit
4afbc082ed
5 changed files with 60 additions and 286 deletions
|
@ -17,4 +17,4 @@ log = "0.4"
|
|||
arrayvec = "0.5"
|
||||
|
||||
[dev-dependencies]
|
||||
insta = { version = "1.1", features = ["ron"] }
|
||||
insta = "1.1"
|
||||
|
|
|
@ -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
|
||||
"
|
||||
));
|
||||
}
|
||||
}
|
||||
|
|
|
@ -1,90 +1,13 @@
|
|||
---
|
||||
source: compiler/src/compile.rs
|
||||
expression: "compile_exec(\"if True and False and False:\\n pass\\n\")"
|
||||
expression: "compile_exec(\"\\\nif True and False and False:\n pass\n\")"
|
||||
---
|
||||
CodeObject(
|
||||
instructions: [
|
||||
LoadConst(
|
||||
idx: 0,
|
||||
),
|
||||
JumpIfFalse(
|
||||
target: Label(0),
|
||||
),
|
||||
LoadConst(
|
||||
idx: 1,
|
||||
),
|
||||
JumpIfFalse(
|
||||
target: Label(0),
|
||||
),
|
||||
LoadConst(
|
||||
idx: 2,
|
||||
),
|
||||
JumpIfFalse(
|
||||
target: Label(0),
|
||||
),
|
||||
LoadConst(
|
||||
idx: 3,
|
||||
),
|
||||
ReturnValue,
|
||||
],
|
||||
label_map: {
|
||||
Label(0): 6,
|
||||
},
|
||||
locations: [
|
||||
Location(
|
||||
row: 1,
|
||||
column: 4,
|
||||
),
|
||||
Location(
|
||||
row: 1,
|
||||
column: 4,
|
||||
),
|
||||
Location(
|
||||
row: 1,
|
||||
column: 13,
|
||||
),
|
||||
Location(
|
||||
row: 1,
|
||||
column: 13,
|
||||
),
|
||||
Location(
|
||||
row: 1,
|
||||
column: 23,
|
||||
),
|
||||
Location(
|
||||
row: 1,
|
||||
column: 23,
|
||||
),
|
||||
Location(
|
||||
row: 2,
|
||||
column: 2,
|
||||
),
|
||||
Location(
|
||||
row: 2,
|
||||
column: 2,
|
||||
),
|
||||
],
|
||||
flags: CodeFlags(
|
||||
bits: 8,
|
||||
),
|
||||
posonlyarg_count: 0,
|
||||
arg_names: [],
|
||||
varargs_name: None,
|
||||
kwonlyarg_names: [],
|
||||
varkeywords_name: None,
|
||||
source_path: "source_path",
|
||||
first_line_number: 0,
|
||||
obj_name: "<module>",
|
||||
constants: [
|
||||
Boolean(
|
||||
value: true,
|
||||
),
|
||||
Boolean(
|
||||
value: false,
|
||||
),
|
||||
Boolean(
|
||||
value: false,
|
||||
),
|
||||
None,
|
||||
],
|
||||
)
|
||||
0 LoadConst (true)
|
||||
1 JumpIfFalse (6)
|
||||
2 LoadConst (false)
|
||||
3 JumpIfFalse (6)
|
||||
4 LoadConst (false)
|
||||
5 JumpIfFalse (6)
|
||||
>> 6 LoadConst (None)
|
||||
7 ReturnValue
|
||||
|
||||
|
|
|
@ -1,109 +1,15 @@
|
|||
---
|
||||
source: compiler/src/compile.rs
|
||||
expression: "compile_exec(\"if (True and False) or (False and True):\\n pass\\n\")"
|
||||
expression: "compile_exec(\"\\\nif (True and False) or (False and True):\n pass\n\")"
|
||||
---
|
||||
CodeObject(
|
||||
instructions: [
|
||||
LoadConst(
|
||||
idx: 0,
|
||||
),
|
||||
JumpIfFalse(
|
||||
target: Label(2),
|
||||
),
|
||||
LoadConst(
|
||||
idx: 1,
|
||||
),
|
||||
JumpIfTrue(
|
||||
target: Label(1),
|
||||
),
|
||||
LoadConst(
|
||||
idx: 2,
|
||||
),
|
||||
JumpIfFalse(
|
||||
target: Label(0),
|
||||
),
|
||||
LoadConst(
|
||||
idx: 3,
|
||||
),
|
||||
JumpIfFalse(
|
||||
target: Label(0),
|
||||
),
|
||||
LoadConst(
|
||||
idx: 4,
|
||||
),
|
||||
ReturnValue,
|
||||
],
|
||||
label_map: {
|
||||
Label(0): 8,
|
||||
Label(1): 8,
|
||||
Label(2): 4,
|
||||
},
|
||||
locations: [
|
||||
Location(
|
||||
row: 1,
|
||||
column: 5,
|
||||
),
|
||||
Location(
|
||||
row: 1,
|
||||
column: 5,
|
||||
),
|
||||
Location(
|
||||
row: 1,
|
||||
column: 14,
|
||||
),
|
||||
Location(
|
||||
row: 1,
|
||||
column: 14,
|
||||
),
|
||||
Location(
|
||||
row: 1,
|
||||
column: 25,
|
||||
),
|
||||
Location(
|
||||
row: 1,
|
||||
column: 25,
|
||||
),
|
||||
Location(
|
||||
row: 1,
|
||||
column: 35,
|
||||
),
|
||||
Location(
|
||||
row: 1,
|
||||
column: 35,
|
||||
),
|
||||
Location(
|
||||
row: 2,
|
||||
column: 2,
|
||||
),
|
||||
Location(
|
||||
row: 2,
|
||||
column: 2,
|
||||
),
|
||||
],
|
||||
flags: CodeFlags(
|
||||
bits: 8,
|
||||
),
|
||||
posonlyarg_count: 0,
|
||||
arg_names: [],
|
||||
varargs_name: None,
|
||||
kwonlyarg_names: [],
|
||||
varkeywords_name: None,
|
||||
source_path: "source_path",
|
||||
first_line_number: 0,
|
||||
obj_name: "<module>",
|
||||
constants: [
|
||||
Boolean(
|
||||
value: true,
|
||||
),
|
||||
Boolean(
|
||||
value: false,
|
||||
),
|
||||
Boolean(
|
||||
value: false,
|
||||
),
|
||||
Boolean(
|
||||
value: true,
|
||||
),
|
||||
None,
|
||||
],
|
||||
)
|
||||
0 LoadConst (true)
|
||||
1 JumpIfFalse (4)
|
||||
2 LoadConst (false)
|
||||
3 JumpIfTrue (8)
|
||||
>> 4 LoadConst (false)
|
||||
5 JumpIfFalse (8)
|
||||
6 LoadConst (true)
|
||||
7 JumpIfFalse (8)
|
||||
>> 8 LoadConst (None)
|
||||
9 ReturnValue
|
||||
|
||||
|
|
|
@ -1,91 +1,13 @@
|
|||
---
|
||||
source: compiler/src/compile.rs
|
||||
expression: "compile_exec(\"if True or False or False:\\n pass\\n\")"
|
||||
expression: "compile_exec(\"\\\nif True or False or False:\n pass\n\")"
|
||||
---
|
||||
CodeObject(
|
||||
instructions: [
|
||||
LoadConst(
|
||||
idx: 0,
|
||||
),
|
||||
JumpIfTrue(
|
||||
target: Label(1),
|
||||
),
|
||||
LoadConst(
|
||||
idx: 1,
|
||||
),
|
||||
JumpIfTrue(
|
||||
target: Label(1),
|
||||
),
|
||||
LoadConst(
|
||||
idx: 2,
|
||||
),
|
||||
JumpIfFalse(
|
||||
target: Label(0),
|
||||
),
|
||||
LoadConst(
|
||||
idx: 3,
|
||||
),
|
||||
ReturnValue,
|
||||
],
|
||||
label_map: {
|
||||
Label(0): 6,
|
||||
Label(1): 6,
|
||||
},
|
||||
locations: [
|
||||
Location(
|
||||
row: 1,
|
||||
column: 4,
|
||||
),
|
||||
Location(
|
||||
row: 1,
|
||||
column: 4,
|
||||
),
|
||||
Location(
|
||||
row: 1,
|
||||
column: 12,
|
||||
),
|
||||
Location(
|
||||
row: 1,
|
||||
column: 12,
|
||||
),
|
||||
Location(
|
||||
row: 1,
|
||||
column: 21,
|
||||
),
|
||||
Location(
|
||||
row: 1,
|
||||
column: 21,
|
||||
),
|
||||
Location(
|
||||
row: 2,
|
||||
column: 2,
|
||||
),
|
||||
Location(
|
||||
row: 2,
|
||||
column: 2,
|
||||
),
|
||||
],
|
||||
flags: CodeFlags(
|
||||
bits: 8,
|
||||
),
|
||||
posonlyarg_count: 0,
|
||||
arg_names: [],
|
||||
varargs_name: None,
|
||||
kwonlyarg_names: [],
|
||||
varkeywords_name: None,
|
||||
source_path: "source_path",
|
||||
first_line_number: 0,
|
||||
obj_name: "<module>",
|
||||
constants: [
|
||||
Boolean(
|
||||
value: true,
|
||||
),
|
||||
Boolean(
|
||||
value: false,
|
||||
),
|
||||
Boolean(
|
||||
value: false,
|
||||
),
|
||||
None,
|
||||
],
|
||||
)
|
||||
0 LoadConst (true)
|
||||
1 JumpIfTrue (6)
|
||||
2 LoadConst (false)
|
||||
3 JumpIfTrue (6)
|
||||
4 LoadConst (false)
|
||||
5 JumpIfFalse (6)
|
||||
>> 6 LoadConst (None)
|
||||
7 ReturnValue
|
||||
|
||||
|
|
Loading…
Add table
Add a link
Reference in a new issue