tape: Improve table tests
This commit is contained in:
parent
0e7e935374
commit
23c3efa845
@ -29,10 +29,38 @@ func TestTable(test *testing.T) {
|
|||||||
test.Logf("len of longText: %d 0x%X", len(longText), len(longText))
|
test.Logf("len of longText: %d 0x%X", len(longText), len(longText))
|
||||||
correct := []byte("\x00\x05\x05hello\x00\x07\x05world\x00\x00\x83\x28" + longText)
|
correct := []byte("\x00\x05\x05hello\x00\x07\x05world\x00\x00\x83\x28" + longText)
|
||||||
if got := buffer[:len(correct)]; !slices.Equal(got, correct) {
|
if got := buffer[:len(correct)]; !slices.Equal(got, correct) {
|
||||||
if !compareHexArray(test, correct, got) {
|
if !compareHexArray(test, got, correct) { test.Fatal("failed") }
|
||||||
test.FailNow()
|
|
||||||
}
|
|
||||||
}
|
}
|
||||||
|
|
||||||
|
pull := DecodeTable(buffer[:len(correct)])
|
||||||
|
|
||||||
|
tag, value, _, err := pull()
|
||||||
|
if err != nil { test.Fatal(err) }
|
||||||
|
if got, correct := tag, uint16(5); got != correct {
|
||||||
|
test.Fatal("not equal:", got)
|
||||||
|
}
|
||||||
|
if !compareHexArray(test, value, []byte("hello")) { test.Fatal("failed") }
|
||||||
|
|
||||||
|
tag, value, _, err = pull()
|
||||||
|
if err != nil { test.Fatal(err) }
|
||||||
|
if got, correct := tag, uint16(7); got != correct {
|
||||||
|
test.Fatal("not equal:", got)
|
||||||
|
}
|
||||||
|
if !compareHexArray(test, value, []byte("world")) { test.Fatal("failed") }
|
||||||
|
|
||||||
|
tag, value, _, err = pull()
|
||||||
|
if err != nil { test.Fatal(err) }
|
||||||
|
if got, correct := tag, uint16(0); got != correct {
|
||||||
|
test.Fatal("not equal:", got)
|
||||||
|
}
|
||||||
|
if !compareHexArray(test, value, []byte(longText)) { test.Fatal("failed") }
|
||||||
|
|
||||||
|
tag, value, _, err = pull()
|
||||||
|
if err != nil { test.Fatal(err) }
|
||||||
|
if got, correct := tag, uint16(3249); got != correct {
|
||||||
|
test.Fatal("not equal:", got)
|
||||||
|
}
|
||||||
|
if !compareHexArray(test, value, []byte { 0x0, 0x1, 0x2, 0x3, 0xA0, 0x5 }) { test.Fatal("failed") }
|
||||||
}
|
}
|
||||||
|
|
||||||
func TestTableSmall(test *testing.T) {
|
func TestTableSmall(test *testing.T) {
|
||||||
@ -48,10 +76,24 @@ func TestTableSmall(test *testing.T) {
|
|||||||
|
|
||||||
correct := []byte("\x00\x02\x05hello\x0C\xB1\x06\x00\x01\x02\x03\xA0\x05")
|
correct := []byte("\x00\x02\x05hello\x0C\xB1\x06\x00\x01\x02\x03\xA0\x05")
|
||||||
if got := buffer[:len(correct)]; !slices.Equal(got, correct) {
|
if got := buffer[:len(correct)]; !slices.Equal(got, correct) {
|
||||||
if !compareHexArray(test, correct, got) {
|
if !compareHexArray(test, got, correct) { test.Fatal("failed") }
|
||||||
test.FailNow()
|
|
||||||
}
|
|
||||||
}
|
}
|
||||||
|
|
||||||
|
pull := DecodeTable(buffer[:len(correct)])
|
||||||
|
|
||||||
|
tag, value, _, err := pull()
|
||||||
|
if err != nil { test.Fatal(err) }
|
||||||
|
if got, correct := tag, uint16(2); got != correct {
|
||||||
|
test.Fatal("not equal:", got)
|
||||||
|
}
|
||||||
|
if !compareHexArray(test, value, []byte("hello")) { test.Fatal("failed") }
|
||||||
|
|
||||||
|
tag, value, _, err = pull()
|
||||||
|
if err != nil { test.Fatal(err) }
|
||||||
|
if got, correct := tag, uint16(3249); got != correct {
|
||||||
|
test.Fatal("not equal:", got)
|
||||||
|
}
|
||||||
|
if !compareHexArray(test, value, []byte { 0x0, 0x1, 0x2, 0x3, 0xA0, 0x5 }) { test.Fatal("failed") }
|
||||||
}
|
}
|
||||||
|
|
||||||
func dumpHexArray(data []byte) (message string) {
|
func dumpHexArray(data []byte) (message string) {
|
||||||
@ -61,7 +103,7 @@ func dumpHexArray(data []byte) (message string) {
|
|||||||
return message
|
return message
|
||||||
}
|
}
|
||||||
|
|
||||||
func compareHexArray(test *testing.T, correct, got []byte) bool {
|
func compareHexArray(test *testing.T, got, correct []byte) bool {
|
||||||
index := 0
|
index := 0
|
||||||
for {
|
for {
|
||||||
if index >= len(correct) {
|
if index >= len(correct) {
|
||||||
@ -71,6 +113,7 @@ func compareHexArray(test *testing.T, correct, got []byte) bool {
|
|||||||
test.Log("correct:", dumpHexArray(correct))
|
test.Log("correct:", dumpHexArray(correct))
|
||||||
return false
|
return false
|
||||||
}
|
}
|
||||||
|
break
|
||||||
}
|
}
|
||||||
if index >= len(got) {
|
if index >= len(got) {
|
||||||
if index < len(correct) {
|
if index < len(correct) {
|
||||||
@ -79,6 +122,7 @@ func compareHexArray(test *testing.T, correct, got []byte) bool {
|
|||||||
test.Log("correct:", dumpHexArray(correct))
|
test.Log("correct:", dumpHexArray(correct))
|
||||||
return false
|
return false
|
||||||
}
|
}
|
||||||
|
break
|
||||||
}
|
}
|
||||||
if correct[index] != got[index] {
|
if correct[index] != got[index] {
|
||||||
test.Log("not equal")
|
test.Log("not equal")
|
||||||
|
Loading…
x
Reference in New Issue
Block a user