-
Notifications
You must be signed in to change notification settings - Fork 2
/
Copy pathendian_test.go
56 lines (50 loc) · 1.01 KB
/
endian_test.go
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
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
// Copyright 2025 Leon Hwang.
// SPDX-License-Identifier: Apache-2.0
package bice
import (
"testing"
"github.com/leonhwangprojects/bice/internal/test"
)
var isBigEndian = ne.Uint16([]byte{0x12, 0x34}) == 0x1234
func TestEndian(t *testing.T) {
tests := []struct {
name string
n uint64
be uint64
fn func(t *testing.T, n, exp uint64)
}{
{
name: "h2ns",
n: 0x1234,
be: 0x3412,
fn: func(t *testing.T, n, exp uint64) {
test.AssertEqual(t, h2ns(uint16(n)), uint16(exp))
},
},
{
name: "h2nl",
n: 0x12345678,
be: 0x78563412,
fn: func(t *testing.T, n, exp uint64) {
test.AssertEqual(t, h2nl(uint32(n)), uint32(exp))
},
},
{
name: "h2nll",
n: 0x1234567890abcdef,
be: 0xefcdab9078563412,
fn: func(t *testing.T, n, exp uint64) {
test.AssertEqual(t, h2nll(n), exp)
},
},
}
for _, tt := range tests {
t.Run(tt.name, func(t *testing.T) {
if isBigEndian {
tt.fn(t, tt.n, tt.n)
} else {
tt.fn(t, tt.n, tt.be)
}
})
}
}