Skip to content

Commit 74af9ee

Browse files
committed
Add multifile completions tests
1 parent c5d6691 commit 74af9ee

File tree

1 file changed

+102
-9
lines changed

1 file changed

+102
-9
lines changed

crates/ty_ide/src/completion.rs

Lines changed: 102 additions & 9 deletions
Original file line numberDiff line numberDiff line change
@@ -445,6 +445,7 @@ mod tests {
445445
test.assert_completions_do_not_include("_T");
446446
// Dunder attributes should not be stripped
447447
test.assert_completions_include("__annotations__");
448+
// See `private_symbols_in_stub` for more comprehensive testing private of symbol filtering.
448449
}
449450

450451
#[test]
@@ -510,17 +511,109 @@ re.<CURSOR>
510511
}
511512

512513
#[test]
513-
fn private_symbol() {
514-
let test = cursor_test(
515-
"\
516-
import os
514+
fn private_symbols_in_stub() {
515+
let test = CursorTest::builder()
516+
.source(
517+
"package/__init__.pyi",
518+
r#"\
519+
from typing import TypeAlias, Literal, TypeVar, ParamSpec, TypeVarTuple, Protocol
517520
518-
os.<CURSOR>
519-
",
520-
);
521+
public_name = 1
522+
_private_name = 1
523+
__managed_name = 1
524+
__dunder_name__ = 1
525+
526+
public_type_var = TypeVar("public_type_var")
527+
_private_type_var = TypeVar("_private_type_var")
528+
__mangled_type_var = TypeVar("__mangled_type_var")
529+
530+
public_param_spec = ParamSpec("public_param_spec")
531+
_private_param_spec = ParamSpec("_private_param_spec")
532+
533+
public_type_var_tuple = TypeVarTuple("public_type_var_tuple")
534+
_private_type_var_tuple = TypeVarTuple("_private_type_var_tuple")
535+
536+
public_explicit_type_alias: TypeAlias = Literal[1]
537+
_private_explicit_type_alias: TypeAlias = Literal[1]
538+
539+
class PublicProtocol(Protocol):
540+
def method(self) -> None: ...
541+
542+
class _PrivateProtocol(Protocol):
543+
def method(self) -> None: ...
544+
"#,
545+
)
546+
.source("main.py", "import package; package.<CURSOR>")
547+
.build();
548+
test.assert_completions_include("public_name");
549+
test.assert_completions_include("_private_name");
550+
test.assert_completions_include("__managed_name");
551+
test.assert_completions_include("__dunder_name__");
552+
test.assert_completions_include("public_type_var");
553+
test.assert_completions_do_not_include("_private_type_var");
554+
test.assert_completions_do_not_include("__mangled_type_var");
555+
test.assert_completions_include("public_param_spec");
556+
test.assert_completions_do_not_include("_private_param_spec");
557+
test.assert_completions_include("public_type_var_tuple");
558+
test.assert_completions_do_not_include("_private_type_var_tuple");
559+
test.assert_completions_include("public_explicit_type_alias");
560+
test.assert_completions_include("_private_explicit_type_alias");
561+
test.assert_completions_include("PublicProtocol");
562+
test.assert_completions_do_not_include("_PrivateProtocol");
563+
}
564+
565+
/// Unlike [`private_symbols_in_stub`], this test doesn't use a `.pyi` file so all of the names
566+
/// are visible.
567+
#[test]
568+
fn private_symbols_in_module() {
569+
let test = CursorTest::builder()
570+
.source(
571+
"package/__init__.py",
572+
r#"\
573+
from typing import TypeAlias, Literal, TypeVar, ParamSpec, TypeVarTuple, Protocol
574+
575+
public_name = 1
576+
_private_name = 1
577+
__managed_name = 1
578+
__dunder_name__ = 1
579+
580+
public_type_var = TypeVar("public_type_var")
581+
_private_type_var = TypeVar("_private_type_var")
582+
__mangled_type_var = TypeVar("__mangled_type_var")
583+
584+
public_param_spec = ParamSpec("public_param_spec")
585+
_private_param_spec = ParamSpec("_private_param_spec")
521586
522-
// The `_exit` symbol is private, but is a type that is relevant at runtime.
523-
test.assert_completions_include("_exit");
587+
public_type_var_tuple = TypeVarTuple("public_type_var_tuple")
588+
_private_type_var_tuple = TypeVarTuple("_private_type_var_tuple")
589+
590+
public_explicit_type_alias: TypeAlias = Literal[1]
591+
_private_explicit_type_alias: TypeAlias = Literal[1]
592+
593+
class PublicProtocol(Protocol):
594+
def method(self) -> None: ...
595+
596+
class _PrivateProtocol(Protocol):
597+
def method(self) -> None: ...
598+
"#,
599+
)
600+
.source("main.py", "import package; package.<CURSOR>")
601+
.build();
602+
test.assert_completions_include("public_name");
603+
test.assert_completions_include("_private_name");
604+
test.assert_completions_include("__managed_name");
605+
test.assert_completions_include("__dunder_name__");
606+
test.assert_completions_include("public_type_var");
607+
test.assert_completions_include("_private_type_var");
608+
test.assert_completions_include("__mangled_type_var");
609+
test.assert_completions_include("public_param_spec");
610+
test.assert_completions_include("_private_param_spec");
611+
test.assert_completions_include("public_type_var_tuple");
612+
test.assert_completions_include("_private_type_var_tuple");
613+
test.assert_completions_include("public_explicit_type_alias");
614+
test.assert_completions_include("_private_explicit_type_alias");
615+
test.assert_completions_include("PublicProtocol");
616+
test.assert_completions_include("_PrivateProtocol");
524617
}
525618

526619
#[test]

0 commit comments

Comments
 (0)