Compare commits

..

No commits in common. "510eaae73ac1e0169c57375cd432d89d2ad5e487" and "7d68efc59902e70cb746ad7368d6d5109272d035" have entirely different histories.

2 changed files with 1 additions and 146 deletions

View File

@ -196,7 +196,7 @@ impl TopLevelComposer {
let mut current_class = class.clone(); let mut current_class = class.clone();
while let Some(base) = base_class_lookup.get(current_class) { while let Some(base) = base_class_lookup.get(current_class) {
if let Some(cons) = constructor_lookup.get(base) { if let Some(cons) = constructor_lookup.get(base) {
self.constructor_lookup.insert(**class, cons.clone()); self.constructor_lookup.insert(*current_class, cons.clone());
break; break;
} else { } else {
current_class = base; current_class = base;

View File

@ -566,151 +566,6 @@ fn test_analyze(source: Vec<&str>, res: Vec<&str>) {
} }
} }
#[test_case(
indoc! {"
class A:
def __init__(self):
pass
class B(A):
pass
class C(B):
pass
"},
HashMap::from([
("A".into(),ast::Located {
location: ast::Location::new(2, 5, ast::FileName("unknown".into())),
custom: (),
node: ast::StmtKind::FunctionDef {
name: "__init__".into(),
args: Box::new(ast::Arguments {
posonlyargs: vec![],
args: vec![
ast::Located {
location: ast::Location::new(2, 18, ast::FileName("unknown".into())),
custom: (),
node: ast::ArgData {
arg: "self".into(),
annotation: None,
type_comment: None,
},
},
],
vararg: None,
kwonlyargs: vec![],
kw_defaults: vec![],
kwarg: None,
defaults: vec![],
}),
body: vec![
ast::Located {
location: Location::new(3, 9, ast::FileName("unknown".into())),
custom: (),
node: ast::StmtKind::Pass {
config_comment: vec![],
},
},
],
decorator_list: vec![],
returns: None,
type_comment: None,
config_comment: vec![],
},
}),
("B".into(), ast::Located {
location: ast::Location::new(2, 5, ast::FileName("unknown".into())),
custom: (),
node: ast::StmtKind::FunctionDef {
name: "__init__".into(),
args: Box::new(ast::Arguments {
posonlyargs: vec![],
args: vec![
ast::Located {
location: ast::Location::new(2, 18, ast::FileName("unknown".into())),
custom: (),
node: ast::ArgData {
arg: "self".into(),
annotation: None,
type_comment: None,
},
},
],
vararg: None,
kwonlyargs: vec![],
kw_defaults: vec![],
kwarg: None,
defaults: vec![],
}),
body: vec![
ast::Located {
location: Location::new(3, 9, ast::FileName("unknown".into())),
custom: (),
node: ast::StmtKind::Pass {
config_comment: vec![],
},
},
],
decorator_list: vec![],
returns: None,
type_comment: None,
config_comment: vec![],
},
}),
("C".into(), ast::Located {
location: ast::Location::new(2, 5, ast::FileName("unknown".into())),
custom: (),
node: ast::StmtKind::FunctionDef {
name: "__init__".into(),
args: Box::new(ast::Arguments {
posonlyargs: vec![],
args: vec![
ast::Located {
location: ast::Location::new(2, 18, ast::FileName("unknown".into())),
custom: (),
node: ast::ArgData {
arg: "self".into(),
annotation: None,
type_comment: None,
},
},
],
vararg: None,
kwonlyargs: vec![],
kw_defaults: vec![],
kwarg: None,
defaults: vec![],
}),
body: vec![
ast::Located {
location: Location::new(3, 9, ast::FileName("unknown".into())),
custom: (),
node: ast::StmtKind::Pass {
config_comment: vec![],
},
},
],
decorator_list: vec![],
returns: None,
type_comment: None,
config_comment: vec![],
},
}),
]);
"build_constructor_lookup_table"
)]
fn test_build_constructor_lookup(source: &str, result: HashMap<ast::StrRef, ast::Located<ast::StmtKind>>) {
let ast = parse_program(source, Default::default());
let mut composer: TopLevelComposer = Default::default();
if let Ok(stmts) = ast {
composer.build_constructor_lookup(stmts.iter())
}
assert_eq!(result.get(&"A".into()).unwrap(), result.get(&"B".into()).unwrap());
assert_eq!(result.get(&"B".into()).unwrap(), result.get(&"C".into()).unwrap());
}
#[test_case( #[test_case(
vec![ vec![
indoc! {" indoc! {"