Repository: astral-sh/ruff
File: crates/ty_ide/src/completion.rs (Rust)

Code before:
        assert_snapshot!(snapshot, @r"
        Protocol
        PendingDeprecationWarning
        PermissionError
        ProcessLookupError
        PythonFinalizationError
        ");
    }

    #[test]
    fn from_import_i_suggests_import() {
        let builder = completion_test_builder("from typing i<CURSOR>");

        let completions_test = builder.build();

        completions_test.contains("import");

        let completions = completions_test.completions();

        assert!(completions.len() == 1);
    }

    #[test]
    fn from_import_two_imports_suggests_import() {
        let builder =
            completion_test_builder("from collections.abc import Sequence\nfrom typing i<CURSOR>");

        let completions_test = builder.build();

        completions_test.contains("import");

        let completions = completions_test.completions();

        assert!(completions.len() == 1);
    }

    /// The following behaviour may not be reflected in editors, since LSP clients may do their own
    /// filtering of completion suggestions.
    #[test]
    fn from_import_random_name_suggests_import() {
        let builder = completion_test_builder("from typing aa<CURSOR>");

        let completions_test = builder.build();

        completions_test.contains("import");

        let completions = completions_test.completions();

        assert!(completions.len() == 1);
    }


Review comment (suggestion):
For something really short, I'm fine with the `\n` here. But this starts to make very long lines. I'd rather see this written out using actual new lines:

```
        let builder = completion_test_builder(
            "from collections.abc import Sequence
             from typing i<CURSOR>"
        );
```

The test code should automatically handle dedenting.

Code after:
        ");
    }

    #[test]
    fn favour_imported_over_builtin() {
        let snapshot =
            completion_test_builder("from typing import Protocol\nclass Foo(P<CURSOR>: ...")
                .filter(|c| c.name.starts_with('P'))
                .build()
                .snapshot();

        // Here we favour `Protocol` over the other completions
        // because `Protocol` has been imported, and the other completions are builtin.
        assert_snapshot!(snapshot, @r"
        Protocol
        PendingDeprecationWarning
        PermissionError
        ProcessLookupError
        PythonFinalizationError
        ");
    }

    #[test]
    fn from_import_i_suggests_import() {
        let builder = completion_test_builder("from typing i<CURSOR>");
        assert_snapshot!(builder.build().snapshot(), @"import");
    }

    #[test]
    fn from_import_import_suggests_nothing() {
        let builder = completion_test_builder("from typing import<CURSOR>");
        assert_snapshot!(builder.build().snapshot(), @"import");
    }

    #[test]
    fn from_import_importt_suggests_import() {
        let builder = completion_test_builder("from typing importt<CURSOR>");
        assert_snapshot!(builder.build().snapshot(), @"import");
    }

    #[test]
    fn from_import_space_suggests_import() {
        let builder = completion_test_builder("from typing <CURSOR>");
        assert_snapshot!(builder.build().snapshot(), @"import");
    }

    #[test]
    fn from_import_no_space_not_suggests_import() {
        let builder = completion_test_builder("from typing<CURSOR>");
        assert_snapshot!(builder.build().snapshot(), @r"
        typing