-/*
-netstring -- netstring format serialization library
-Copyright (C) 2015-2022 Sergey Matveev <stargrave@stargrave.org>
-
-This program is free software: you can redistribute it and/or modify
-it under the terms of the GNU General Public License as published by
-the Free Software Foundation, version 3 of the License.
-
-This program is distributed in the hope that it will be useful,
-but WITHOUT ANY WARRANTY; without even the implied warranty of
-MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
-GNU General Public License for more details.
-
-You should have received a copy of the GNU General Public License
-along with this program. If not, see <http://www.gnu.org/licenses/>.
-*/
+// netstring -- netstring format serialization library
+// Copyright (C) 2015-2024 Sergey Matveev <stargrave@stargrave.org>
+//
+// This program is free software: you can redistribute it and/or modify
+// it under the terms of the GNU General Public License as published by
+// the Free Software Foundation, version 3 of the License.
+//
+// This program is distributed in the hope that it will be useful,
+// but WITHOUT ANY WARRANTY; without even the implied warranty of
+// MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
+// GNU General Public License for more details.
+//
+// You should have received a copy of the GNU General Public License
+// along with this program. If not, see <http://www.gnu.org/licenses/>.
package netstring
import (
"bytes"
- "io/ioutil"
+ "io"
"testing"
"testing/quick"
)
if n, err := w.WriteChunk([]byte("barz")); err != nil || n != 7 {
t.FailNow()
}
- if string(buf.Bytes()) != "3:foo,4:barz," {
+ if buf.String() != "3:foo,4:barz," {
t.FailNow()
}
r := NewReader(&buf)
if n, err := r.Read(m); err != nil || n != 4 {
t.FailNow()
}
- if bytes.Compare(m, []byte("barz")) != 0 {
+ if !bytes.Equal(m, []byte("barz")) {
t.FailNow()
}
}
if n, err := r.Next(); err != nil || n != uint64(len(data)) {
return false
}
- got, err := ioutil.ReadAll(r)
- if err != nil || bytes.Compare(got, data) != 0 {
+ got, err := io.ReadAll(r)
+ if err != nil || !bytes.Equal(got, data) {
return false
}
}
b = bytes.NewBufferString("0:foobar,")
r = NewReader(b)
- if _, err := r.Next(); err != nil {
- t.FailNow()
- }
- if _, err := r.Read(data); err == nil {
+ if _, err := r.Next(); err == nil {
t.FailNow()
}
- b = bytes.NewBufferString("0:foobar")
+ b = bytes.NewBufferString("6:foobar")
r = NewReader(b)
if _, err := r.Next(); err != nil {
t.FailNow()
t.FailNow()
}
- b = bytes.NewBufferString("6:foobar")
+ b = bytes.NewBufferString(":foobar,")
r = NewReader(b)
- if _, err := r.Next(); err != nil {
+ if _, err := r.Next(); err == nil {
t.FailNow()
}
- if _, err := r.Read(data); err == nil {
+
+ b = bytes.NewBufferString("06:foobar,")
+ r = NewReader(b)
+ if _, err := r.Next(); err == nil {
t.FailNow()
}
}
if size, err := r.Next(); err != nil || size != 6 {
t.FailNow()
}
- if data, err := ioutil.ReadAll(r); err != nil || string(data) != "world!" {
+ if data, err := io.ReadAll(r); err != nil || string(data) != "world!" {
t.FailNow()
}
}