TestEditFiles_FuzzyIndent_InsertionLevelAware covers indent- propagation bugs that fire when the caller's search/replace whitespace differs from the file's (tab vs space, 2sp vs 4sp). - Red_* cases assert the correct output that the indent-unit translation produces for inserted splice lines. - Lock
(t *testing.T)
| 2798 | // that the insertion-only fix does not cover; tracked in |
| 2799 | // CODAGT-214. |
| 2800 | func TestEditFiles_FuzzyIndent_InsertionLevelAware(t *testing.T) { |
| 2801 | t.Parallel() |
| 2802 | |
| 2803 | tmpdir := os.TempDir() |
| 2804 | logger := slogtest.Make(t, &slogtest.Options{IgnoreErrors: true}).Leveled(slog.LevelDebug) |
| 2805 | |
| 2806 | type edit struct { |
| 2807 | search, replace string |
| 2808 | replaceAll bool |
| 2809 | } |
| 2810 | tests := []struct { |
| 2811 | name string |
| 2812 | content string |
| 2813 | edits []edit |
| 2814 | expected string |
| 2815 | }{ |
| 2816 | // Wrap an existing line in a new block. Tab file, 4sp caller. |
| 2817 | { |
| 2818 | name: "Red_WrapInBlock_TabFile_4spLLM", |
| 2819 | content: "func main() {\n" + |
| 2820 | "\tfmt.Println(\"hello\")\n" + |
| 2821 | "\tfmt.Println(\"world\")\n" + |
| 2822 | "}\n", |
| 2823 | edits: []edit{{ |
| 2824 | search: " fmt.Println(\"hello\")\n" + |
| 2825 | " fmt.Println(\"world\")", |
| 2826 | replace: " fmt.Println(\"hello\")\n" + |
| 2827 | " if verbose {\n" + |
| 2828 | " fmt.Println(\"world\")\n" + |
| 2829 | " }", |
| 2830 | }}, |
| 2831 | expected: "func main() {\n" + |
| 2832 | "\tfmt.Println(\"hello\")\n" + |
| 2833 | "\tif verbose {\n" + |
| 2834 | "\t\tfmt.Println(\"world\")\n" + |
| 2835 | "\t}\n" + |
| 2836 | "}\n", |
| 2837 | }, |
| 2838 | |
| 2839 | // Wrap in a new block, 2sp file, 4sp caller. The common |
| 2840 | // real-world trigger: Claude/GPT default 4sp into a 2sp file. |
| 2841 | { |
| 2842 | name: "Red_WrapInBlock_2spFile_4spLLM", |
| 2843 | content: "function main() {\n" + |
| 2844 | " console.log('hello')\n" + |
| 2845 | " console.log('world')\n" + |
| 2846 | "}\n", |
| 2847 | edits: []edit{{ |
| 2848 | search: " console.log('hello')\n" + |
| 2849 | " console.log('world')", |
| 2850 | replace: " console.log('hello')\n" + |
| 2851 | " if (verbose) {\n" + |
| 2852 | " console.log('world')\n" + |
| 2853 | " }", |
| 2854 | }}, |
| 2855 | expected: "function main() {\n" + |
| 2856 | " console.log('hello')\n" + |
| 2857 | " if (verbose) {\n" + |