summaryrefslogtreecommitdiff
path: root/src/cmd/gofmt
diff options
context:
space:
mode:
authorRobert Griesemer <gri@golang.org>2012-09-19 14:14:21 -0700
committerRobert Griesemer <gri@golang.org>2012-09-19 14:14:21 -0700
commit16ba7773952394a34afdb476459658b36c670193 (patch)
tree4d8797be93b1a340d349e2584319d14969438ecb /src/cmd/gofmt
parent92a40d2d078cadd4d1fdb8724b11a8a7d0b7aa5d (diff)
downloadgo-16ba7773952394a34afdb476459658b36c670193.tar.gz
gofmt: added testcase for files containing \r\n line endings
(see also issue 3961). hexdump -c testdata/crlf.input 0000000 / * \r \n \t S o u r c e c o n t 0000010 a i n i n g C R / L F l i n 0000020 e e n d i n g s . \r \n \t T h e 0000030 g o f m t ' e d o u t p u t 0000040 m u s t o n l y h a v e 0000050 L F \r \n \t l i n e e n d i n g 0000060 s . \r \n * / \r \n p a c k a g e 0000070 m a i n \r \n \r \n f u n c m a i 0000080 n ( ) { \r \n \t / / l i n e 0000090 c o m m e n t \r \n \t p r i n t l 00000a0 n ( " h e l l o , w o r l d ! 00000b0 " ) / / a n o t h e r l i 00000c0 n e c o m m e n t \r \n \t p r i 00000d0 n t l n ( ) \r \n } \r \n 00000db hexdump -c testdata/crlf.golden 0000000 / * \n \t S o u r c e c o n t a 0000010 i n i n g C R / L F l i n e 0000020 e n d i n g s . \n \t T h e g 0000030 o f m t ' e d o u t p u t m 0000040 u s t o n l y h a v e L F 0000050 \n \t l i n e e n d i n g s . \n 0000060 * / \n p a c k a g e m a i n \n 0000070 \n f u n c m a i n ( ) { \n \t 0000080 / / l i n e c o m m e n t \n 0000090 \t p r i n t l n ( " h e l l o , 00000a0 w o r l d ! " ) / / a n o 00000b0 t h e r l i n e c o m m e n 00000c0 t \n \t p r i n t l n ( ) \n } \n 00000cf R=rsc CC=golang-dev http://codereview.appspot.com/6526052
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()
+}