diff options
Diffstat (limited to 'libgo/go/text/scanner/scanner_test.go')
-rw-r--r-- | libgo/go/text/scanner/scanner_test.go | 49 |
1 files changed, 49 insertions, 0 deletions
diff --git a/libgo/go/text/scanner/scanner_test.go b/libgo/go/text/scanner/scanner_test.go index 702fac2b1ad..798bed7e92a 100644 --- a/libgo/go/text/scanner/scanner_test.go +++ b/libgo/go/text/scanner/scanner_test.go @@ -616,3 +616,52 @@ func TestPos(t *testing.T) { t.Errorf("%d errors", s.ErrorCount) } } + +type countReader int + +func (r *countReader) Read([]byte) (int, error) { + *r++ + return 0, io.EOF +} + +func TestNextEOFHandling(t *testing.T) { + var r countReader + + // corner case: empty source + s := new(Scanner).Init(&r) + + tok := s.Next() + if tok != EOF { + t.Error("1) EOF not reported") + } + + tok = s.Peek() + if tok != EOF { + t.Error("2) EOF not reported") + } + + if r != 1 { + t.Errorf("scanner called Read %d times, not once", r) + } +} + +func TestScanEOFHandling(t *testing.T) { + var r countReader + + // corner case: empty source + s := new(Scanner).Init(&r) + + tok := s.Scan() + if tok != EOF { + t.Error("1) EOF not reported") + } + + tok = s.Peek() + if tok != EOF { + t.Error("2) EOF not reported") + } + + if r != 1 { + t.Errorf("scanner called Read %d times, not once", r) + } +} |