summaryrefslogtreecommitdiff
path: root/src/cmd/gofmt
diff options
context:
space:
mode:
Diffstat (limited to 'src/cmd/gofmt')
-rw-r--r--src/cmd/gofmt/gofmt_test.go22
-rw-r--r--src/cmd/gofmt/testdata/crlf.golden12
-rwxr-xr-xsrc/cmd/gofmt/testdata/crlf.input12
3 files changed, 46 insertions, 0 deletions
diff --git a/src/cmd/gofmt/gofmt_test.go b/src/cmd/gofmt/gofmt_test.go
index 903ba2177..e4d5796f3 100644
--- a/src/cmd/gofmt/gofmt_test.go
+++ b/src/cmd/gofmt/gofmt_test.go
@@ -81,6 +81,7 @@ var tests = []struct {
{"testdata/stdin*.input", "-stdin"},
{"testdata/comments.input", ""},
{"testdata/import.input", ""},
+ {"testdata/crlf.input", ""}, // test case for issue 3961; see also TestCRLF
}
func TestRewrite(t *testing.T) {
@@ -103,3 +104,24 @@ func TestRewrite(t *testing.T) {
}
}
}
+
+func TestCRLF(t *testing.T) {
+ const input = "testdata/crlf.input" // must contain CR/LF's
+ const golden = "testdata/crlf.golden" // must not contain any CR's
+
+ data, err := ioutil.ReadFile(input)
+ if err != nil {
+ t.Error(err)
+ }
+ if bytes.Index(data, []byte("\r\n")) < 0 {
+ t.Errorf("%s contains no CR/LF's", input)
+ }
+
+ data, err = ioutil.ReadFile(golden)
+ if err != nil {
+ t.Error(err)
+ }
+ if bytes.Index(data, []byte("\r")) >= 0 {
+ t.Errorf("%s contains CR's", golden)
+ }
+}
diff --git a/src/cmd/gofmt/testdata/crlf.golden b/src/cmd/gofmt/testdata/crlf.golden
new file mode 100644
index 000000000..57679f770
--- /dev/null
+++ b/src/cmd/gofmt/testdata/crlf.golden
@@ -0,0 +1,12 @@
+/*
+ Source containing CR/LF line endings.
+ The gofmt'ed output must only have LF
+ line endings.
+*/
+package main
+
+func main() {
+ // line comment
+ println("hello, world!") // another line comment
+ println()
+}
diff --git a/src/cmd/gofmt/testdata/crlf.input b/src/cmd/gofmt/testdata/crlf.input
new file mode 100755
index 000000000..61a1aa0b4
--- /dev/null
+++ b/src/cmd/gofmt/testdata/crlf.input
@@ -0,0 +1,12 @@
+/*
+ Source containing CR/LF line endings.
+ The gofmt'ed output must only have LF
+ line endings.
+*/
+package main
+
+func main() {
+ // line comment
+ println("hello, world!") // another line comment
+ println()
+}