mirror of
https://github.com/RustPython/Parser.git
synced 2025-07-20 03:25:18 +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"
|
arrayvec = "0.5"
|
||||||
|
|
||||||
[dev-dependencies]
|
[dev-dependencies]
|
||||||
insta = { version = "1.1", features = ["ron"] }
|
insta = "1.1"
|
||||||
|
|
|
@ -2351,20 +2351,43 @@ mod tests {
|
||||||
compiler.pop_code_object()
|
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]
|
#[test]
|
||||||
fn test_if_ors() {
|
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]
|
#[test]
|
||||||
fn test_if_ands() {
|
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]
|
#[test]
|
||||||
fn test_if_mixed() {
|
fn test_if_mixed() {
|
||||||
insta::assert_ron_snapshot!(compile_exec(
|
assert_dis_snapshot!(compile_exec(
|
||||||
"if (True and False) or (False and True):\n pass\n"
|
"\
|
||||||
|
if (True and False) or (False and True):
|
||||||
|
pass
|
||||||
|
"
|
||||||
));
|
));
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
|
@ -1,90 +1,13 @@
|
||||||
---
|
---
|
||||||
source: compiler/src/compile.rs
|
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(
|
0 LoadConst (true)
|
||||||
instructions: [
|
1 JumpIfFalse (6)
|
||||||
LoadConst(
|
2 LoadConst (false)
|
||||||
idx: 0,
|
3 JumpIfFalse (6)
|
||||||
),
|
4 LoadConst (false)
|
||||||
JumpIfFalse(
|
5 JumpIfFalse (6)
|
||||||
target: Label(0),
|
>> 6 LoadConst (None)
|
||||||
),
|
7 ReturnValue
|
||||||
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,
|
|
||||||
],
|
|
||||||
)
|
|
||||||
|
|
|
@ -1,109 +1,15 @@
|
||||||
---
|
---
|
||||||
source: compiler/src/compile.rs
|
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(
|
0 LoadConst (true)
|
||||||
instructions: [
|
1 JumpIfFalse (4)
|
||||||
LoadConst(
|
2 LoadConst (false)
|
||||||
idx: 0,
|
3 JumpIfTrue (8)
|
||||||
),
|
>> 4 LoadConst (false)
|
||||||
JumpIfFalse(
|
5 JumpIfFalse (8)
|
||||||
target: Label(2),
|
6 LoadConst (true)
|
||||||
),
|
7 JumpIfFalse (8)
|
||||||
LoadConst(
|
>> 8 LoadConst (None)
|
||||||
idx: 1,
|
9 ReturnValue
|
||||||
),
|
|
||||||
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,
|
|
||||||
],
|
|
||||||
)
|
|
||||||
|
|
|
@ -1,91 +1,13 @@
|
||||||
---
|
---
|
||||||
source: compiler/src/compile.rs
|
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(
|
0 LoadConst (true)
|
||||||
instructions: [
|
1 JumpIfTrue (6)
|
||||||
LoadConst(
|
2 LoadConst (false)
|
||||||
idx: 0,
|
3 JumpIfTrue (6)
|
||||||
),
|
4 LoadConst (false)
|
||||||
JumpIfTrue(
|
5 JumpIfFalse (6)
|
||||||
target: Label(1),
|
>> 6 LoadConst (None)
|
||||||
),
|
7 ReturnValue
|
||||||
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,
|
|
||||||
],
|
|
||||||
)
|
|
||||||
|
|
Loading…
Add table
Add a link
Reference in a new issue