miekg / learninggo

Learning Go Book in mmark
https://miek.nl/go
Other
539 stars 111 forks source link

Fix cat solution to handle no newlines #22

Closed StevenMaude closed 7 years ago

StevenMaude commented 7 years ago

Only break if there's no content to send to standard output.

Fixes #21.

StevenMaude commented 7 years ago

This seems to give consistent behaviour with GNU cat.

testfile containing a line with a newline:

some text\n
$ ./cat testfile
some text
$

testfile containing a line with no newline:

some text
$ ./cat
some text$

testfile containing no characters at all:

(no characters)
$ ./cat testfile
$

There might be some other edge case I've not thought of, however, where my solution behaves differently to GNU cat.