]> Cypherpunks.ru repositories - netstring.git/blobdiff - ns_test.go
Unify copyright comment format
[netstring.git] / ns_test.go
index cf519680481796deb18c7e6d2871b1f2460ee639..e4ca00a43ae7fe67eb2b8c160d0de8dba9282367 100644 (file)
@@ -1,25 +1,23 @@
-/*
-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"
 )
@@ -36,7 +34,7 @@ func TestTrivial(t *testing.T) {
        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)
@@ -53,7 +51,7 @@ func TestTrivial(t *testing.T) {
        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()
        }
 }
@@ -72,8 +70,8 @@ func TestSymmetric(t *testing.T) {
                        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
                        }
                }
@@ -107,14 +105,11 @@ func TestErrors(t *testing.T) {
 
        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()
@@ -123,12 +118,15 @@ func TestErrors(t *testing.T) {
                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()
        }
 }
@@ -158,7 +156,7 @@ func TestExample(t *testing.T) {
        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()
        }
 }