Skip to content

Commit 7de9901

Browse files
committed
Use LF for printer tests
1 parent 61a3e78 commit 7de9901

File tree

2 files changed

+39
-24
lines changed

2 files changed

+39
-24
lines changed

internal/printer/printer_test.go

Lines changed: 5 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -549,7 +549,11 @@ func checkDiagnostics(t *testing.T, file *ast.SourceFile) {
549549

550550
func checkEmit(t *testing.T, file *ast.SourceFile, expected string) {
551551
t.Helper()
552-
printer := &Printer{}
552+
printer := &Printer{
553+
Options: PrinterOptions{
554+
NewLine: core.NewLineKindLF,
555+
},
556+
}
553557
text := printer.EmitSourceFile(file)
554558
actual := strings.TrimSuffix(text, "\n")
555559
assert.Equal(t, expected, actual)

internal/vfs/vfs.go

Lines changed: 34 additions & 23 deletions
Original file line numberDiff line numberDiff line change
@@ -3,6 +3,7 @@ package vfs
33
import (
44
"bytes"
55
"encoding/binary"
6+
"errors"
67
"fmt"
78
"io/fs"
89
"os"
@@ -115,6 +116,12 @@ func FromIOFS(fsys fs.FS, useCaseSensitiveFileNames bool) FS {
115116
return sub
116117
},
117118
realpath: realpath,
119+
writeFile: func(string, string, bool) error {
120+
return errors.ErrUnsupported
121+
},
122+
mkdirAll: func(string) error {
123+
return errors.ErrUnsupported
124+
},
118125
}
119126
}
120127

@@ -138,6 +145,28 @@ func FromOS() FS {
138145
}
139146
return tspath.NormalizeSlashes(path), nil
140147
},
148+
writeFile: func(path string, content string, writeByteOrderMark bool) error {
149+
file, err := os.Create(path)
150+
if err != nil {
151+
return err
152+
}
153+
defer file.Close()
154+
155+
if writeByteOrderMark {
156+
if _, err := file.WriteString("\uFEFF"); err != nil {
157+
return err
158+
}
159+
}
160+
161+
if _, err := file.WriteString(content); err != nil {
162+
return err
163+
}
164+
165+
return nil
166+
},
167+
mkdirAll: func(path string) error {
168+
return os.MkdirAll(path, 0o777)
169+
},
141170
}
142171
}
143172

@@ -173,8 +202,10 @@ type vfs struct {
173202

174203
useCaseSensitiveFileNames bool
175204

176-
rootFor func(root string) fs.FS
177-
realpath func(path string) (string, error)
205+
rootFor func(root string) fs.FS
206+
realpath func(path string) (string, error)
207+
writeFile func(path string, content string, writeByteOrderMark bool) error
208+
mkdirAll func(path string) error
178209
}
179210

180211
func (v *vfs) UseCaseSensitiveFileNames() bool {
@@ -313,28 +344,8 @@ func (v *vfs) Realpath(path string) string {
313344
return realpath
314345
}
315346

316-
func (v *vfs) writeFile(path string, content string, writeByteOrderMark bool) error {
317-
file, err := os.Create(path)
318-
if err != nil {
319-
return err
320-
}
321-
defer file.Close()
322-
323-
if writeByteOrderMark {
324-
if _, err := file.WriteString("\uFEFF"); err != nil {
325-
return err
326-
}
327-
}
328-
329-
if _, err := file.WriteString(content); err != nil {
330-
return err
331-
}
332-
333-
return nil
334-
}
335-
336347
func (v *vfs) ensureDirectoryExists(directoryPath string) error {
337-
return os.MkdirAll(directoryPath, 0o777)
348+
return v.mkdirAll(directoryPath)
338349
}
339350

340351
func (v *vfs) WriteFile(path string, content string, writeByteOrderMark bool) error {

0 commit comments

Comments
 (0)