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,7 +4335,8 @@ async fn test_convert_indentation_to_spaces(cx: &mut TestAppContext) {
cx.update_editor(|e, 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
@ -4344,14 +4345,18 @@ async fn test_convert_indentation_to_spaces(cx: &mut TestAppContext) {
abc // Space followed by tab (3 spaces should be the result)
abc // Mixed indentation (tab conversion depends on the column)
abc // Already space indented
·
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
// Only lines (3, 5, 10, 11) should change
cx.set_state(indoc! {"
cx.set_state(
indoc! {"
·
abc // No indentation
\tabcˇ // 1 tab
\t\tabc // 2 tabs
@ -4361,12 +4366,16 @@ async fn test_convert_indentation_to_spaces(cx: &mut TestAppContext) {
abc // Already space indented
«\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| {
e.convert_indentation_to_spaces(&ConvertIndentationToSpaces, window, cx);
});
cx.assert_editor_state(indoc! {"
cx.assert_editor_state(
indoc! {"
·
abc // No indentation
« abc // 1 tabˇ»
\t\tabc // 2 tabs
@ -4374,9 +4383,12 @@ async fn test_convert_indentation_to_spaces(cx: &mut TestAppContext) {
\tabc // Space followed by tab (3 spaces should be the result)
\t \t \t \tabc // Mixed indentation (tab conversion depends on the column)
abc // Already space indented
«
« ·
abc\tdef // Only the leading tab is manipulatedˇ»
"});
"}
.replace("·", "")
.as_str(), // · used as placeholder to prevent format-on-save from removing whitespace
);
// SINGLE SELECTION
// Ln.1 "«" tests empty lines
@ -4396,7 +4408,8 @@ async fn test_convert_indentation_to_spaces(cx: &mut TestAppContext) {
cx.update_editor(|e, 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
@ -4405,9 +4418,12 @@ async fn test_convert_indentation_to_spaces(cx: &mut TestAppContext) {
abc // Space followed by tab (3 spaces should be the result)
abc // Mixed indentation (tab conversion depends on the column)
abc // Already space indented
·
abc\tdef // Only the leading tab is manipulatedˇ»
"});
"}
.replace("·", "")
.as_str(), // · used as placeholder to prevent format-on-save from removing whitespace
);
}
#[gpui::test]
@ -4455,8 +4471,9 @@ async fn test_convert_indentation_to_tabs(cx: &mut TestAppContext) {
// Test on just a few lines, the other should remain unchanged
// 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 // 2 spaces (< 3 so dont convert)
@ -4469,12 +4486,16 @@ async fn test_convert_indentation_to_tabs(cx: &mut TestAppContext) {
\t \t \t \tabc // Mixed indentation
\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| {
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 // 2 spaces (< 3 so dont convert)
@ -4487,7 +4508,10 @@ async fn test_convert_indentation_to_tabs(cx: &mut TestAppContext) {
\t \t \t \tabc // Mixed indentation
«\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
// Ln.1 "«" tests empty lines