Просмотр исходного кода

Add some edge cases to the unit test

Signed-off-by: Matt Bolt <mbolt35@gmail.com>
Matt Bolt 2 лет назад
Родитель
Сommit
168d7b8a34
1 измененных файлов с 14 добавлено и 0 удалено
  1. 14 0
      core/pkg/util/buffer_test.go

+ 14 - 0
core/pkg/util/buffer_test.go

@@ -231,12 +231,18 @@ func TestTooLargeStringTruncate(t *testing.T) {
 	bigStr := generateRandomString(math.MaxUint16 + (math.MaxUint16 / 2))
 	expectedBigStrRead := bigStr[:math.MaxUint16]
 
+	otherBigStr := generateRandomString(math.MaxUint16)
+	plusOne := generateRandomString(math.MaxUint16 + 1)
+	expectedPlusOne := plusOne[:math.MaxUint16]
+
 	buf := NewBuffer()
 
 	buf.WriteInt(42)
 	buf.WriteFloat64(3.14)
 	buf.WriteString(normalStr)
 	buf.WriteString(bigStr)
+	buf.WriteString(otherBigStr)
+	buf.WriteString(plusOne)
 
 	readBuf := NewBufferFromBytes(buf.Bytes())
 
@@ -244,6 +250,8 @@ func TestTooLargeStringTruncate(t *testing.T) {
 	floatVal := readBuf.ReadFloat64()
 	normalStrRead := readBuf.ReadString()
 	bigStrRead := readBuf.ReadString()
+	otherBigStrRead := readBuf.ReadString()
+	plusOneRead := readBuf.ReadString()
 
 	if intVal != 42 {
 		t.Errorf("Expected int value to be 42, got %v", intVal)
@@ -257,4 +265,10 @@ func TestTooLargeStringTruncate(t *testing.T) {
 	if bigStrRead != expectedBigStrRead {
 		t.Errorf("Expected large string values to be equivalent!")
 	}
+	if otherBigStrRead != otherBigStr {
+		t.Errorf("Expected large string values to be equivalent!")
+	}
+	if plusOneRead != expectedPlusOne {
+		t.Errorf("Expected large string values to be equivalent!")
+	}
 }