File: data_test.go

package info (click to toggle)
golang-github-mmcloughlin-avo 0.5.0-1
  • links: PTS, VCS
  • area: main
  • in suites: bookworm, forky, sid, trixie
  • size: 15,024 kB
  • sloc: xml: 71,029; asm: 14,862; sh: 194; makefile: 21; ansic: 11
file content (29 lines) | stat: -rw-r--r-- 1,011 bytes parent folder | download | duplicates (2)
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
package data

import (
	"encoding/binary"
	"math"
	"testing"
)

//go:generate go run asm.go -out data.s -stubs stub.go

func TestDataAt(t *testing.T) {
	order := binary.LittleEndian
	expect := make([]byte, 40)
	order.PutUint64(expect[0:], 0x0011223344556677)         // DATA(0, U64(0x0011223344556677))
	copy(expect[8:], []byte("strconst"))                    // DATA(8, String("strconst"))
	order.PutUint32(expect[16:], math.Float32bits(math.Pi)) // DATA(16, F32(math.Pi))
	order.PutUint64(expect[24:], math.Float64bits(math.Pi)) // DATA(24, F64(math.Pi))
	order.PutUint32(expect[32:], 0x00112233)                // DATA(32, U32(0x00112233))
	order.PutUint16(expect[36:], 0x4455)                    // DATA(36, U16(0x4455))
	expect[38] = 0x66                                       // DATA(38, U8(0x66))
	expect[39] = 0x77                                       // DATA(39, U8(0x77))

	for i, e := range expect {
		b := DataAt(i)
		if b != e {
			t.Errorf("DataAt(%d) = %#02x; expected %#02x", i, b, e)
		}
	}
}