buffer_test.go 763 B

123456789101112131415161718192021222324252627282930313233343536
  1. // Copyright 2011 The Go Authors. All rights reserved.
  2. // Use of this source code is governed by a BSD-style
  3. // license that can be found in the LICENSE file.
  4. package tiff
  5. import (
  6. "io"
  7. "strings"
  8. "testing"
  9. )
  10. var readAtTests = []struct {
  11. n int
  12. off int64
  13. s string
  14. err error
  15. }{
  16. {2, 0, "ab", nil},
  17. {6, 0, "abcdef", nil},
  18. {3, 3, "def", nil},
  19. {3, 5, "f", io.EOF},
  20. {3, 6, "", io.EOF},
  21. }
  22. func TestReadAt(t *testing.T) {
  23. r := newReaderAt(strings.NewReader("abcdef"))
  24. b := make([]byte, 10)
  25. for _, test := range readAtTests {
  26. n, err := r.ReadAt(b[:test.n], test.off)
  27. s := string(b[:n])
  28. if s != test.s || err != test.err {
  29. t.Errorf("buffer.ReadAt(<%v bytes>, %v): got %v, %q; want %v, %q", test.n, test.off, err, s, test.err, test.s)
  30. }
  31. }
  32. }