tape: WIP

This commit is contained in:
2025-07-02 06:25:24 -04:00
parent 2138d47f07
commit 07fc77c83e
2 changed files with 65 additions and 2 deletions

View File

@@ -67,6 +67,65 @@ func TestEncodeDecodeAnyMap(test *testing.T) {
if err != nil { test.Fatal(err) }
}
func TestPeekSlice(test *testing.T) {
buffer := bytes.NewBuffer([]byte {
2, byte(OTA.WithCN(3)),
0, 0, 0, 1, byte(LI.WithCN(1)),
0, 0x5,
2, byte(LI.WithCN(1)),
0, 0x17,
0xAA, 0xAA,
})
decoder := NewDecoder(buffer)
elem, dimension, err := peekSlice(decoder, OTA.WithCN(0))
if err != nil { test.Fatal(err) }
if elem != LI.WithCN(1) {
test.Fatalf("wrong element tag: %v %02X", elem, byte(elem))
}
if got, correct := dimension, 2; got != correct {
test.Fatalf("wrong dimension: %d != %d", got, correct)
}
}
func TestPeekSliceOnce(test *testing.T) {
buffer := bytes.NewBuffer([]byte {
2, byte(OTA.WithCN(3)),
0, 0, 0, 1, byte(LI.WithCN(1)),
0, 0x5,
2, byte(LI.WithCN(1)),
0, 0x17,
0xAA, 0xAA,
})
decoder := NewDecoder(buffer)
test.Log("--- stage 1")
elem, populated, n, err := peekSliceOnce(decoder, OTA.WithCN(0), 0)
if err != nil { test.Fatal(err) }
if elem != OTA.WithCN(3) {
test.Fatal("wrong element tag:", elem)
}
if !populated {
test.Fatal("wrong populated:", populated)
}
if got, correct := n, 2; got != correct {
test.Fatalf("wrong n: %d != %d", got, correct)
}
test.Log("--- stage 2")
elem, populated, n, err = peekSliceOnce(decoder, elem, n)
if err != nil { test.Fatal(err) }
if elem != LI.WithCN(1) {
test.Fatal("wrong element tag:", elem)
}
if !populated {
test.Fatal("wrong populated:", populated)
}
if got, correct := n, 7; got != correct {
test.Fatalf("wrong n: %d != %d", got, correct)
}
}
func encAny(value any) ([]byte, Tag, int, error) {
tag, err := TagAny(value)
if err != nil { return nil, 0, 0, err }