mirror of
https://github.com/astral-sh/ruff.git
synced 2025-10-02 06:42:02 +00:00
[red-knot] is_disjoint_from: tests for function/module literals (#14264)
## Summary Add unit tests for `is_disjoint_from` for function and module literals as a follow-up to #14210. Ref: https://github.com/astral-sh/ruff/pull/14210/files#r1835069885
This commit is contained in:
parent
5bf4759cff
commit
438f3d967b
1 changed files with 59 additions and 1 deletions
|
@ -3188,7 +3188,7 @@ mod tests {
|
||||||
}
|
}
|
||||||
|
|
||||||
#[test]
|
#[test]
|
||||||
fn is_disjoint_type_type() {
|
fn is_disjoint_type_subclass_of() {
|
||||||
let mut db = setup_db();
|
let mut db = setup_db();
|
||||||
db.write_dedented(
|
db.write_dedented(
|
||||||
"/src/module.py",
|
"/src/module.py",
|
||||||
|
@ -3221,6 +3221,64 @@ mod tests {
|
||||||
assert!(!subclass_of_a.is_disjoint_from(&db, subclass_of_b));
|
assert!(!subclass_of_a.is_disjoint_from(&db, subclass_of_b));
|
||||||
}
|
}
|
||||||
|
|
||||||
|
#[test]
|
||||||
|
fn is_disjoint_module_literals() {
|
||||||
|
let mut db = setup_db();
|
||||||
|
db.write_dedented(
|
||||||
|
"/src/module.py",
|
||||||
|
"
|
||||||
|
import random
|
||||||
|
import math
|
||||||
|
",
|
||||||
|
)
|
||||||
|
.unwrap();
|
||||||
|
|
||||||
|
let module = ruff_db::files::system_path_to_file(&db, "/src/module.py").unwrap();
|
||||||
|
|
||||||
|
let module_literal_random = super::global_symbol(&db, module, "random").expect_type();
|
||||||
|
let module_literal_math = super::global_symbol(&db, module, "math").expect_type();
|
||||||
|
|
||||||
|
assert!(module_literal_random.is_disjoint_from(&db, module_literal_math));
|
||||||
|
|
||||||
|
assert!(!module_literal_random.is_disjoint_from(
|
||||||
|
&db,
|
||||||
|
Ty::KnownClassInstance(KnownClass::ModuleType).into_type(&db)
|
||||||
|
));
|
||||||
|
assert!(!module_literal_random.is_disjoint_from(
|
||||||
|
&db,
|
||||||
|
Ty::KnownClassInstance(KnownClass::Object).into_type(&db)
|
||||||
|
));
|
||||||
|
}
|
||||||
|
|
||||||
|
#[test]
|
||||||
|
fn is_disjoint_function_literals() {
|
||||||
|
let mut db = setup_db();
|
||||||
|
db.write_dedented(
|
||||||
|
"/src/module.py",
|
||||||
|
"
|
||||||
|
def f(): ...
|
||||||
|
def g(): ...
|
||||||
|
",
|
||||||
|
)
|
||||||
|
.unwrap();
|
||||||
|
|
||||||
|
let module = ruff_db::files::system_path_to_file(&db, "/src/module.py").unwrap();
|
||||||
|
|
||||||
|
let function_literal_f = super::global_symbol(&db, module, "f").expect_type();
|
||||||
|
let function_literal_g = super::global_symbol(&db, module, "g").expect_type();
|
||||||
|
|
||||||
|
assert!(function_literal_f.is_disjoint_from(&db, function_literal_g));
|
||||||
|
|
||||||
|
assert!(!function_literal_f.is_disjoint_from(
|
||||||
|
&db,
|
||||||
|
Ty::KnownClassInstance(KnownClass::FunctionType).into_type(&db)
|
||||||
|
));
|
||||||
|
assert!(!function_literal_f.is_disjoint_from(
|
||||||
|
&db,
|
||||||
|
Ty::KnownClassInstance(KnownClass::Object).into_type(&db)
|
||||||
|
));
|
||||||
|
}
|
||||||
|
|
||||||
#[test_case(Ty::None)]
|
#[test_case(Ty::None)]
|
||||||
#[test_case(Ty::BooleanLiteral(true))]
|
#[test_case(Ty::BooleanLiteral(true))]
|
||||||
#[test_case(Ty::BooleanLiteral(false))]
|
#[test_case(Ty::BooleanLiteral(false))]
|
||||||
|
|
Loading…
Add table
Add a link
Reference in a new issue