Skip to content

Commit c950912

Browse files
committed
add chompLeadingSpace to align with Strada behavior
1 parent 69c1134 commit c950912

File tree

4 files changed

+21
-3
lines changed

4 files changed

+21
-3
lines changed

internal/fourslash/test_parser.go

Lines changed: 18 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -215,6 +215,7 @@ const (
215215

216216
func parseFileContent(fileName string, content string, fileOptions map[string]string) (*testFileWithMarkers, error) {
217217
fileName = tspath.GetNormalizedAbsolutePath(fileName, "/")
218+
content = chompLeadingSpace(content)
218219

219220
// The file content (minus metacharacters) so far
220221
var output strings.Builder
@@ -466,6 +467,23 @@ func reportError(fileName string, line int, col int, message string) error {
466467
return &fourslashError{fmt.Sprintf("%v (%v,%v): %v", fileName, line, col, message)}
467468
}
468469

470+
func chompLeadingSpace(content string) string {
471+
lines := strings.Split(content, "\n")
472+
for _, line := range lines {
473+
if len(line) > 0 && line[0] != ' ' {
474+
return content
475+
}
476+
}
477+
478+
result := make([]string, len(lines))
479+
for i, line := range lines {
480+
if len(line) > 0 {
481+
result[i] = line[1:]
482+
}
483+
}
484+
return strings.Join(result, "\n")
485+
}
486+
469487
type fourslashError struct {
470488
err string
471489
}

internal/fourslash/tests/gen/formatOnEnterInComment_test.go

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -18,5 +18,5 @@ func TestFormatOnEnterInComment(t *testing.T) {
1818
defer done()
1919
f.GoToMarker(t, "1")
2020
f.InsertLine(t, "")
21-
f.VerifyCurrentFileContentIs(t, " /**\n * \n\n */")
21+
f.VerifyCurrentFileContentIs(t, " /**\n * \n\n */")
2222
}

internal/fourslash/tests/gen/semicolonFormattingInsideAComment_test.go

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -16,5 +16,5 @@ func TestSemicolonFormattingInsideAComment(t *testing.T) {
1616
defer done()
1717
f.GoToMarker(t, "")
1818
f.Insert(t, ";")
19-
f.VerifyCurrentLineContentIs(t, " //;")
19+
f.VerifyCurrentLineContentIs(t, " //;")
2020
}

internal/fourslash/tests/gen/semicolonFormattingInsideAStringLiteral_test.go

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -16,5 +16,5 @@ func TestSemicolonFormattingInsideAStringLiteral(t *testing.T) {
1616
defer done()
1717
f.GoToMarker(t, "")
1818
f.Insert(t, ";")
19-
f.VerifyCurrentLineContentIs(t, " var x = \"string;")
19+
f.VerifyCurrentLineContentIs(t, " var x = \"string;")
2020
}

0 commit comments

Comments
 (0)