Skip to content

Commit

Permalink
chore: revert comments changes
Browse files Browse the repository at this point in the history
Signed-off-by: Norman <[email protected]>
  • Loading branch information
Norman authored and Norman committed Dec 25, 2024
1 parent f9e8c94 commit d5ee04e
Show file tree
Hide file tree
Showing 2 changed files with 42 additions and 42 deletions.
64 changes: 32 additions & 32 deletions gnovm/stdlibs/io/io_test.gno
Original file line number Diff line number Diff line change
Expand Up @@ -16,19 +16,19 @@ import (
// A version of bytes.Buffer without ReadFrom and WriteTo
type Buffer struct {
bytes.Buffer
io.ReaderFrom // conflicts with and hides bytes.Buffer's io.ReaderFrom.
io.WriterTo // conflicts with and hides bytes.Buffer's io.WriterTo.
io.ReaderFrom // conflicts with and hides bytes.Buffer's ReaderFrom.
io.WriterTo // conflicts with and hides bytes.Buffer's WriterTo.
}

// Simple tests, primarily to verify the ReadFrom and WriteTo callouts inside io.Copy, io.CopyBuffer and io.CopyN.
// Simple tests, primarily to verify the ReadFrom and WriteTo callouts inside Copy, CopyBuffer and CopyN.

func TestCopy(t *testing.T) {
rb := new(Buffer)
wb := new(Buffer)
rb.WriteString("hello, world.")
io.Copy(wb, rb)
if wb.String() != "hello, world." {
t.Errorf("io.Copy did not work properly")
t.Errorf("Copy did not work properly")
}
}

Expand All @@ -38,12 +38,12 @@ func TestCopyNegative(t *testing.T) {
rb.WriteString("hello")
io.Copy(wb, &io.LimitedReader{R: rb, N: -1})
if wb.String() != "" {
t.Errorf("io.Copy on io.LimitedReader with N<0 copied data")
t.Errorf("Copy on LimitedReader with N<0 copied data")
}

io.CopyN(wb, rb, -1)
if wb.String() != "" {
t.Errorf("io.CopyN with N<0 copied data")
t.Errorf("CopyN with N<0 copied data")
}
}

Expand All @@ -53,7 +53,7 @@ func TestCopyBuffer(t *testing.T) {
rb.WriteString("hello, world.")
io.CopyBuffer(wb, rb, make([]byte, 1)) // Tiny buffer to keep it honest.
if wb.String() != "hello, world." {
t.Errorf("io.CopyBuffer did not work properly")
t.Errorf("CopyBuffer did not work properly")
}
}

Expand All @@ -63,7 +63,7 @@ func TestCopyBufferNil(t *testing.T) {
rb.WriteString("hello, world.")
io.CopyBuffer(wb, rb, nil) // Should allocate a buffer.
if wb.String() != "hello, world." {
t.Errorf("io.CopyBuffer did not work properly")
t.Errorf("CopyBuffer did not work properly")
}
}

Expand All @@ -73,7 +73,7 @@ func TestCopyReadFrom(t *testing.T) {
rb.WriteString("hello, world.")
io.Copy(wb, rb)
if wb.String() != "hello, world." {
t.Errorf("io.Copy did not work properly")
t.Errorf("Copy did not work properly")
}
}

Expand All @@ -83,7 +83,7 @@ func TestCopyWriteTo(t *testing.T) {
rb.WriteString("hello, world.")
io.Copy(wb, rb)
if wb.String() != "hello, world." {
t.Errorf("io.Copy did not work properly")
t.Errorf("Copy did not work properly")
}
}

Expand All @@ -98,16 +98,16 @@ func (wt *writeToChecker) WriteTo(w io.Writer) (int64, error) {
return wt.Buffer.WriteTo(w)
}

// It's preferable to choose io.WriterTo over io.ReaderFrom, since a io.WriterTo can issue one large write,
// while the io.ReaderFrom must read until io.EOF, potentially allocating when running out of buffer.
// Make sure that we choose io.WriterTo when both are implemented.
// It's preferable to choose WriterTo over ReaderFrom, since a WriterTo can issue one large write,
// while the ReaderFrom must read until EOF, potentially allocating when running out of buffer.
// Make sure that we choose WriterTo when both are implemented.
func TestCopyPriority(t *testing.T) {
rb := new(writeToChecker)
wb := new(bytes.Buffer)
rb.WriteString("hello, world.")
io.Copy(wb, rb)
if wb.String() != "hello, world." {
t.Errorf("io.Copy did not work properly")
t.Errorf("Copy did not work properly")
} else if !rb.writeToCalled {
t.Errorf("WriteTo was not prioritized over ReadFrom")
}
Expand Down Expand Up @@ -137,7 +137,7 @@ func TestCopyReadErrWriteErr(t *testing.T) {
r, w := zeroErrReader{err: er}, errWriter{err: ew}
n, err := io.Copy(w, r)
if n != 0 || err != ew {
t.Errorf("io.Copy(zeroErrReader, errWriter) = %d, %v; want 0, writeError", n, err)
t.Errorf("Copy(zeroErrReader, errWriter) = %d, %v; want 0, writeError", n, err)
}
}

Expand All @@ -147,7 +147,7 @@ func TestCopyN(t *testing.T) {
rb.WriteString("hello, world.")
io.CopyN(wb, rb, 5)
if wb.String() != "hello" {
t.Errorf("io.CopyN did not work properly")
t.Errorf("CopyN did not work properly")
}
}

Expand All @@ -157,7 +157,7 @@ func TestCopyNReadFrom(t *testing.T) {
rb.WriteString("hello")
io.CopyN(wb, rb, 5)
if wb.String() != "hello" {
t.Errorf("io.CopyN did not work properly")
t.Errorf("CopyN did not work properly")
}
}

Expand All @@ -167,7 +167,7 @@ func TestCopyNWriteTo(t *testing.T) {
rb.WriteString("hello, world.")
io.CopyN(wb, rb, 5)
if wb.String() != "hello" {
t.Errorf("io.CopyN did not work properly")
t.Errorf("CopyN did not work properly")
}
}

Expand Down Expand Up @@ -210,39 +210,39 @@ func (wantedAndErrReader) Read(p []byte) (int, error) {
}

func TestCopyNEOF(t *testing.T) {
// Test that io.EOF behavior is the same regardless of whether
// argument to io.CopyN has ReadFrom.
// Test that EOF behavior is the same regardless of whether
// argument to CopyN has ReadFrom.

b := new(bytes.Buffer)

n, err := io.CopyN(&noReadFrom{b}, strings.NewReader("foo"), 3)
if n != 3 || err != nil {
t.Errorf("io.CopyN(noReadFrom, foo, 3) = %d, %v; want 3, nil", n, err)
t.Errorf("CopyN(noReadFrom, foo, 3) = %d, %v; want 3, nil", n, err)
}

n, err = io.CopyN(&noReadFrom{b}, strings.NewReader("foo"), 4)
if n != 3 || err != io.EOF {
t.Errorf("io.CopyN(noReadFrom, foo, 4) = %d, %v; want 3, io.EOF", n, err)
t.Errorf("CopyN(noReadFrom, foo, 4) = %d, %v; want 3, EOF", n, err)
}

n, err = io.CopyN(b, strings.NewReader("foo"), 3) // b has read from
if n != 3 || err != nil {
t.Errorf("io.CopyN(bytes.Buffer, foo, 3) = %d, %v; want 3, nil", n, err)
t.Errorf("CopyN(bytes.Buffer, foo, 3) = %d, %v; want 3, nil", n, err)
}

n, err = io.CopyN(b, strings.NewReader("foo"), 4) // b has read from
if n != 3 || err != io.EOF {
t.Errorf("io.CopyN(bytes.Buffer, foo, 4) = %d, %v; want 3, io.EOF", n, err)
t.Errorf("CopyN(bytes.Buffer, foo, 4) = %d, %v; want 3, EOF", n, err)
}

n, err = io.CopyN(b, wantedAndErrReader{}, 5)
if n != 5 || err != nil {
t.Errorf("io.CopyN(bytes.Buffer, wantedAndErrReader, 5) = %d, %v; want 5, nil", n, err)
t.Errorf("CopyN(bytes.Buffer, wantedAndErrReader, 5) = %d, %v; want 5, nil", n, err)
}

n, err = io.CopyN(&noReadFrom{b}, wantedAndErrReader{}, 5)
if n != 5 || err != nil {
t.Errorf("io.CopyN(noReadFrom, wantedAndErrReader, 5) = %d, %v; want 5, nil", n, err)
t.Errorf("CopyN(noReadFrom, wantedAndErrReader, 5) = %d, %v; want 5, nil", n, err)
}
}

Expand Down Expand Up @@ -290,7 +290,7 @@ func testReadAtLeast(t *testing.T, rb io.ReadWriter) {
}
n, err = io.ReadAtLeast(rb, buf, 4)
if err != io.ErrShortBuffer {
t.Errorf("expected `io.ErrShortBuffer` got %v", err)
t.Errorf("expected `ErrShortBuffer` got %v", err)
}
if n != 0 {
t.Errorf("expected to have read 0 bytes, got %v", n)
Expand All @@ -304,7 +304,7 @@ func testReadAtLeast(t *testing.T, rb io.ReadWriter) {
}
n, err = io.ReadAtLeast(rb, buf, 2)
if err != io.EOF {
t.Errorf("expected io.EOF, got %v", err)
t.Errorf("expected EOF, got %v", err)
}
if n != 0 {
t.Errorf("expected to have read 0 bytes, got %v", n)
Expand Down Expand Up @@ -340,7 +340,7 @@ func TestTeeReader(t *testing.T) {
t.Errorf("bytes written = %q want %q", wb.Bytes(), src)
}
if n, err := r.Read(dst); n != 0 || err != io.EOF {
t.Errorf("r.Read at io.EOF = %d, %v want 0, io.EOF", n, err)
t.Errorf("r.Read at EOF = %d, %v want 0, EOF", n, err)
}
rb = bytes.NewBuffer(src)
pr, pw := Pipe()
Expand Down Expand Up @@ -387,7 +387,7 @@ func TestSectionReader_ReadAt(t *testing.T) {
}

func TestSectionReader_Seek(t *testing.T) {
// Verifies that io.NewSectionReader's Seeker behaves like bytes.NewReader (which is like strings.NewReader)
// Verifies that NewSectionReader's Seeker behaves like bytes.NewReader (which is like strings.NewReader)
br := bytes.NewReader([]byte("foo"))
sr := io.NewSectionReader(br, 0, int64(len("foo")))

Expand All @@ -402,15 +402,15 @@ func TestSectionReader_Seek(t *testing.T) {
}
}

// And verify we can just seek past the end and get an io.EOF
// And verify we can just seek past the end and get an EOF
got, err := sr.Seek(100, io.SeekStart)
if err != nil || got != 100 {
t.Errorf("Seek = %v, %v; want 100, nil", got, err)
}

n, err := sr.Read(make([]byte, 10))
if n != 0 || err != io.EOF {
t.Errorf("Read = %v, %v; want 0, io.EOF", n, err)
t.Errorf("Read = %v, %v; want 0, EOF", n, err)
}
}

Expand Down
20 changes: 10 additions & 10 deletions gnovm/stdlibs/io/multi_test.gno
Original file line number Diff line number Diff line change
Expand Up @@ -222,7 +222,7 @@ func TestMultiWriterCopy(t *testing.T) {
}
}

// readerFunc is an io.Reader implemented by the underlying func.
// readerFunc is an Reader implemented by the underlying func.
type readerFunc func(p []byte) (int, error)

func (f readerFunc) Read(p []byte) (int, error) {
Expand All @@ -241,7 +241,7 @@ func callDepth(callers []uintptr) (depth int) {
return
}
// Test that io.MultiReader properly flattens chained multiReaders when Read is called
// Test that MultiReader properly flattens chained multiReaders when Read is called
func TestMultiReaderFlatten(t *testing.T) {
pc := make([]uintptr, 1000) // 1000 should fit the full stack
n := runtime.Callers(0, pc)
Expand All @@ -261,14 +261,14 @@ func TestMultiReaderFlatten(t *testing.T) {
r.Read(nil) // don't care about errors, just want to check the call-depth for Read
if readDepth != myDepth+2 { // 2 should be io.MultiReader.Read and fakeReader.Read
t.Errorf("io.MultiReader did not flatten chained multiReaders: expected readDepth %d, got %d",
t.Errorf("MultiReader did not flatten chained multiReaders: expected readDepth %d, got %d",
myDepth+2, readDepth)
}
}
*/

// byteAndEOFReader is a io.Reader which reads one byte (the underlying
// byte) and io.EOF at once in its Read call.
// byteAndEOFReader is a Reader which reads one byte (the underlying
// byte) and EOF at once in its Read call.
type byteAndEOFReader byte

func (b byteAndEOFReader) Read(p []byte) (n int, err error) {
Expand All @@ -293,15 +293,15 @@ func TestMultiReaderSingleByteWithEOF(t *testing.T) {
}
}

// Test that a io.Reader returning (n, io.EOF) at the end of a io.MultiReader
// chain continues to return io.EOF on its final read, rather than
// yielding a (0, io.EOF).
// Test that a Reader returning (n, EOF) at the end of a MultiReader
// chain continues to return EOF on its final read, rather than
// yielding a (0, EOF).
func TestMultiReaderFinalEOF(t *testing.T) {
r := io.MultiReader(bytes.NewReader(nil), byteAndEOFReader('a'))
buf := make([]byte, 2)
n, err := r.Read(buf)
if n != 1 || err != io.EOF {
t.Errorf("got %v, %v; want 1, io.EOF", n, err)
t.Errorf("got %v, %v; want 1, EOF", n, err)
}
}

Expand All @@ -310,7 +310,7 @@ func TestMultiReaderFreesExhaustedReaders(t *testing.T) {
var mr io.Reader
closed := make(chan struct{})
// The closure ensures that we don't have a live reference to buf1
// on our stack after io.MultiReader is inlined (Issue 18819). This
// on our stack after MultiReader is inlined (Issue 18819). This
// is a work around for a limitation in liveness analysis.
func() {
buf1 := bytes.NewReader([]byte("foo"))
Expand Down

0 comments on commit d5ee04e

Please sign in to comment.