f044f3ba75
- Added language-specific import management for TypeScript, JavaScript, Python, Rust, Go, and C/C++ with automatic deduplication and grouping. - Added `imports` parameter to patch, hashline, and replace edit operations for structured import/include requests with named, default, namespace, and alias support. - Added `edit.manageImports` setting to control post-edit import management behavior across all edit operations. - Implemented language-specific import handlers with parsing, merging, and rendering logic for each supported language. - Integrated import application into EditTool with feature flag support and comprehensive test coverage across all languages.
47 lines
1.6 KiB
TypeScript
47 lines
1.6 KiB
TypeScript
import { describe, expect, test } from "bun:test";
|
|
import { rustImportHandler } from "../../../src/patch/imports/rust";
|
|
|
|
describe("rustImportHandler.apply", () => {
|
|
test("adds a use statement to a file with no imports", () => {
|
|
const result = rustImportHandler.apply("fn main() {}\n", [{ from: "std::fmt::Debug" }]);
|
|
|
|
expect(result).toEqual({
|
|
content: "use std::fmt::Debug;\n\nfn main() {}\n",
|
|
added: ["use std::fmt::Debug;"],
|
|
warnings: [],
|
|
});
|
|
});
|
|
|
|
test("merges a requested member into an existing brace-group import", () => {
|
|
const content = "use std::fmt::{Debug};\n\nfn main() {}\n";
|
|
|
|
const result = rustImportHandler.apply(content, [{ from: "std::fmt", imports: ["Display"] }]);
|
|
|
|
expect(result.content).toBe("use std::fmt::{Debug, Display};\n\nfn main() {}\n");
|
|
expect(result.added).toEqual(["use std::fmt::{Display};"]);
|
|
expect(result.warnings).toEqual([]);
|
|
});
|
|
|
|
test("keeps distinct simple-path imports when they cannot be merged semantically", () => {
|
|
const content = "use crate::config;\n\nfn main() {}\n";
|
|
|
|
const result = rustImportHandler.apply(content, [{ from: "crate::config::load" }]);
|
|
|
|
expect(result.content).toBe("use crate::config;\nuse crate::config::load;\n\nfn main() {}\n");
|
|
expect(result.added).toEqual(["use crate::config::load;"]);
|
|
expect(result.warnings).toEqual([]);
|
|
});
|
|
|
|
test("dedupes an already present use statement", () => {
|
|
const content = "use std::fmt::Debug;\n";
|
|
|
|
const result = rustImportHandler.apply(content, [{ from: "std::fmt::Debug" }]);
|
|
|
|
expect(result).toEqual({
|
|
content,
|
|
added: [],
|
|
warnings: [],
|
|
});
|
|
});
|
|
});
|