editor: Fix editor tests from changing on format on save (#33532)

Use placeholder to prevent format-on-save from removing whitespace in
editor tests, which leads to unnecessary git diff and failing tests.

cc: https://github.com/zed-industries/zed/pull/32340

Release Notes:

- N/A
This commit is contained in:
Smit Barmase 2025-06-27 20:14:01 +05:30 committed by GitHub
parent 3ab4ad6de8
commit 9e2023bffc
No known key found for this signature in database
GPG key ID: B5690EEEBB952194

View file

@ -4335,48 +4335,60 @@ async fn test_convert_indentation_to_spaces(cx: &mut TestAppContext) {
cx.update_editor(|e, window, cx| { cx.update_editor(|e, window, cx| {
e.convert_indentation_to_spaces(&ConvertIndentationToSpaces, window, cx); e.convert_indentation_to_spaces(&ConvertIndentationToSpaces, window, cx);
}); });
cx.assert_editor_state(indoc! {" cx.assert_editor_state(
« indoc! {"
abc // No indentation «
abc // 1 tab abc // No indentation
abc // 2 tabs abc // 1 tab
abc // Tab followed by space abc // 2 tabs
abc // Space followed by tab (3 spaces should be the result) abc // Tab followed by space
abc // Mixed indentation (tab conversion depends on the column) abc // Space followed by tab (3 spaces should be the result)
abc // Already space indented abc // Mixed indentation (tab conversion depends on the column)
abc // Already space indented
abc\tdef // Only the leading tab is manipulatedˇ» ·
"}); abc\tdef // Only the leading tab is manipulatedˇ»
"}
.replace("·", "")
.as_str(), // · used as placeholder to prevent format-on-save from removing whitespace
);
// Test on just a few lines, the others should remain unchanged // Test on just a few lines, the others should remain unchanged
// Only lines (3, 5, 10, 11) should change // Only lines (3, 5, 10, 11) should change
cx.set_state(indoc! {" cx.set_state(
indoc! {"
abc // No indentation ·
\tabcˇ // 1 tab abc // No indentation
\t\tabc // 2 tabs \tabcˇ // 1 tab
\t abcˇ // Tab followed by space \t\tabc // 2 tabs
\tabc // Space followed by tab (3 spaces should be the result) \t abcˇ // Tab followed by space
\t \t \t \tabc // Mixed indentation (tab conversion depends on the column) \tabc // Space followed by tab (3 spaces should be the result)
abc // Already space indented \t \t \t \tabc // Mixed indentation (tab conversion depends on the column)
«\t abc // Already space indented
\tabc\tdef // Only the leading tab is manipulatedˇ» «\t
"}); \tabc\tdef // Only the leading tab is manipulatedˇ»
"}
.replace("·", "")
.as_str(), // · used as placeholder to prevent format-on-save from removing whitespace
);
cx.update_editor(|e, window, cx| { cx.update_editor(|e, window, cx| {
e.convert_indentation_to_spaces(&ConvertIndentationToSpaces, window, cx); e.convert_indentation_to_spaces(&ConvertIndentationToSpaces, window, cx);
}); });
cx.assert_editor_state(indoc! {" cx.assert_editor_state(
indoc! {"
abc // No indentation ·
« abc // 1 tabˇ» abc // No indentation
\t\tabc // 2 tabs « abc // 1 tabˇ»
« abc // Tab followed by spaceˇ» \t\tabc // 2 tabs
\tabc // Space followed by tab (3 spaces should be the result) « abc // Tab followed by spaceˇ»
\t \t \t \tabc // Mixed indentation (tab conversion depends on the column) \tabc // Space followed by tab (3 spaces should be the result)
abc // Already space indented \t \t \t \tabc // Mixed indentation (tab conversion depends on the column)
« abc // Already space indented
abc\tdef // Only the leading tab is manipulatedˇ» « ·
"}); abc\tdef // Only the leading tab is manipulatedˇ»
"}
.replace("·", "")
.as_str(), // · used as placeholder to prevent format-on-save from removing whitespace
);
// SINGLE SELECTION // SINGLE SELECTION
// Ln.1 "«" tests empty lines // Ln.1 "«" tests empty lines
@ -4396,18 +4408,22 @@ async fn test_convert_indentation_to_spaces(cx: &mut TestAppContext) {
cx.update_editor(|e, window, cx| { cx.update_editor(|e, window, cx| {
e.convert_indentation_to_spaces(&ConvertIndentationToSpaces, window, cx); e.convert_indentation_to_spaces(&ConvertIndentationToSpaces, window, cx);
}); });
cx.assert_editor_state(indoc! {" cx.assert_editor_state(
« indoc! {"
abc // No indentation «
abc // 1 tab abc // No indentation
abc // 2 tabs abc // 1 tab
abc // Tab followed by space abc // 2 tabs
abc // Space followed by tab (3 spaces should be the result) abc // Tab followed by space
abc // Mixed indentation (tab conversion depends on the column) abc // Space followed by tab (3 spaces should be the result)
abc // Already space indented abc // Mixed indentation (tab conversion depends on the column)
abc // Already space indented
abc\tdef // Only the leading tab is manipulatedˇ» ·
"}); abc\tdef // Only the leading tab is manipulatedˇ»
"}
.replace("·", "")
.as_str(), // · used as placeholder to prevent format-on-save from removing whitespace
);
} }
#[gpui::test] #[gpui::test]
@ -4455,39 +4471,47 @@ async fn test_convert_indentation_to_tabs(cx: &mut TestAppContext) {
// Test on just a few lines, the other should remain unchanged // Test on just a few lines, the other should remain unchanged
// Only lines (4, 8, 11, 12) should change // Only lines (4, 8, 11, 12) should change
cx.set_state(indoc! {" cx.set_state(
indoc! {"
abc // No indentation ·
abc // 1 space (< 3 so dont convert) abc // No indentation
abc // 2 spaces (< 3 so dont convert) abc // 1 space (< 3 so dont convert)
« abc // 3 spaces (convert)ˇ» abc // 2 spaces (< 3 so dont convert)
abc // 5 spaces (1 tab + 2 spaces) « abc // 3 spaces (convert)ˇ»
\t\t\tabc // Already tab indented abc // 5 spaces (1 tab + 2 spaces)
\t abc // Tab followed by space \t\t\tabc // Already tab indented
\tabc ˇ // Space followed by tab (should be consumed due to tab) \t abc // Tab followed by space
\t\t \tabc // Mixed indentation \tabc ˇ // Space followed by tab (should be consumed due to tab)
\t \t \t \tabc // Mixed indentation \t\t \tabc // Mixed indentation
\t \ \t \t \t \tabc // Mixed indentation
« abc \t // Only the leading spaces should be convertedˇ» \t \
"}); « abc \t // Only the leading spaces should be convertedˇ»
"}
.replace("·", "")
.as_str(), // · used as placeholder to prevent format-on-save from removing whitespace
);
cx.update_editor(|e, window, cx| { cx.update_editor(|e, window, cx| {
e.convert_indentation_to_tabs(&ConvertIndentationToTabs, window, cx); e.convert_indentation_to_tabs(&ConvertIndentationToTabs, window, cx);
}); });
cx.assert_editor_state(indoc! {" cx.assert_editor_state(
indoc! {"
abc // No indentation ·
abc // 1 space (< 3 so dont convert) abc // No indentation
abc // 2 spaces (< 3 so dont convert) abc // 1 space (< 3 so dont convert)
«\tabc // 3 spaces (convert)ˇ» abc // 2 spaces (< 3 so dont convert)
abc // 5 spaces (1 tab + 2 spaces) «\tabc // 3 spaces (convert)ˇ»
\t\t\tabc // Already tab indented abc // 5 spaces (1 tab + 2 spaces)
\t abc // Tab followed by space \t\t\tabc // Already tab indented
«\tabc // Space followed by tab (should be consumed due to tab)ˇ» \t abc // Tab followed by space
\t\t \tabc // Mixed indentation «\tabc // Space followed by tab (should be consumed due to tab)ˇ»
\t \t \t \tabc // Mixed indentation \t\t \tabc // Mixed indentation
«\t\t\t \t \t \t \tabc // Mixed indentation
\tabc \t // Only the leading spaces should be convertedˇ» «\t\t\t
"}); \tabc \t // Only the leading spaces should be convertedˇ»
"}
.replace("·", "")
.as_str(), // · used as placeholder to prevent format-on-save from removing whitespace
);
// SINGLE SELECTION // SINGLE SELECTION
// Ln.1 "«" tests empty lines // Ln.1 "«" tests empty lines