]> Cypherpunks.ru repositories - netstring.git/blobdiff - ns_test.go
Unify copyright comment format
[netstring.git] / ns_test.go
index 6ac07e42f662ce075532867fd06854c98d81c7bf..e4ca00a43ae7fe67eb2b8c160d0de8dba9282367 100644 (file)
@@ -1,19 +1,17 @@
-/*
-netstring -- netstring format serialization library
-Copyright (C) 2015-2023 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
 
@@ -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()
        }
 }
@@ -73,7 +71,7 @@ func TestSymmetric(t *testing.T) {
                                return false
                        }
                        got, err := io.ReadAll(r)
-                       if err != nil || bytes.Compare(got, data) != 0 {
+                       if err != nil || !bytes.Equal(got, data) {
                                return false
                        }
                }
@@ -107,19 +105,7 @@ 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 {
-               t.FailNow()
-       }
-
-       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()
        }